QueueSession getQueueSession() throws InitialisationException { QueueManager qm = MuleManager.getInstance().getQueueManager(); UMOTransaction tx = TransactionCoordination.getInstance().getTransaction(); if (tx != null) { if (tx.hasResource(qm)) { if (logger.isDebugEnabled()) { logger.debug("Retrieving queue session from current transaction"); } return (QueueSession) tx.getResource(qm); } } if (logger.isDebugEnabled()) { logger.debug("Retrieving new queue session from queue manager"); } QueueSession session = qm.getQueueSession(); if (tx != null) { logger.debug("Binding queue session to current transaction"); try { tx.bindResource(qm, session); } catch (TransactionException e) { throw new RuntimeException("Could not bind queue session to current transaction", e); } } return session; }
public VMTransaction(MuleContext muleContext, boolean initialize) throws TransactionException { super(muleContext); if (initialize) { QueueManager qm = muleContext.getQueueManager(); QueueSession qs = qm.getQueueSession(); bindResource(qm, qs); } }
public static TransientRegistry createNew() throws UMOException { // Use the default server lifecycleManager // UMOLifecycleManager lifecycleManager = new DefaultLifecycleManager(); UMOLifecycleManager lifecycleManager = new GenericLifecycleManager(); lifecycleManager.registerLifecycle( new ContainerManagedLifecyclePhase( Initialisable.PHASE_NAME, Initialisable.class, Disposable.PHASE_NAME)); lifecycleManager.registerLifecycle(new ManagementContextStartPhase()); lifecycleManager.registerLifecycle(new ManagementContextStopPhase()); lifecycleManager.registerLifecycle( new ContainerManagedLifecyclePhase( Disposable.PHASE_NAME, Disposable.class, Initialisable.PHASE_NAME)); // Create the registry TransientRegistry registry = new TransientRegistry(); RegistryContext.setRegistry(registry); MuleConfiguration config = new MuleConfiguration(); registry.setConfiguration(config); QueueManager queueManager = new TransactionalQueueManager(); queueManager.setPersistenceStrategy( new CachingPersistenceStrategy(new MemoryPersistenceStrategy())); ThreadingProfile tp = config.getDefaultThreadingProfile(); UMOWorkManager workManager = new MuleWorkManager(tp, "MuleServer"); ServerNotificationManager notificationManager = new ServerNotificationManager(); notificationManager.registerEventType( ManagerNotificationListener.class, ManagerNotification.class); notificationManager.registerEventType(ModelNotificationListener.class, ModelNotification.class); notificationManager.registerEventType( ComponentNotificationListener.class, ComponentNotification.class); notificationManager.registerEventType( SecurityNotificationListener.class, SecurityNotification.class); notificationManager.registerEventType( ManagementNotificationListener.class, ManagementNotification.class); notificationManager.registerEventType(AdminNotificationListener.class, AdminNotification.class); notificationManager.registerEventType( CustomNotificationListener.class, CustomNotification.class); notificationManager.registerEventType( ConnectionNotificationListener.class, ConnectionNotification.class); notificationManager.registerEventType( RegistryNotificationListener.class, RegistryNotification.class); notificationManager.registerEventType( ExceptionNotificationListener.class, ExceptionNotification.class); notificationManager.registerEventType( TransactionNotificationListener.class, TransactionNotification.class); UMOSecurityManager securityManager = new MuleSecurityManager(); UMOManagementContext context = new ManagementContext(lifecycleManager); context.setId(UUID.getUUID()); registry.registerObject( UMOManagementContext.class, MuleProperties.OBJECT_MANAGMENT_CONTEXT, context); registry.registerObject( ObjectProcessor.class, MuleProperties.OBJECT_MANAGMENT_CONTEXT_PROCESSOR, new ManagementContextDependencyProcessor(context)); // Register objects so we get lifecycle management registry.registerObject(MuleProperties.OBJECT_SECURITY_MANAGER, securityManager); registry.registerObject(MuleProperties.OBJECT_WORK_MANAGER, workManager); registry.registerObject(MuleProperties.OBJECT_NOTIFICATION_MANAGER, notificationManager); registry.registerObject(MuleProperties.OBJECT_QUEUE_MANAGER, queueManager); // Set the object explicitly on the ManagementContext context.setWorkManager(workManager); context.setSecurityManager(securityManager); context.setNotificationManager(notificationManager); context.setQueueManager(queueManager); // Register the system Model ModelServiceDescriptor sd = (ModelServiceDescriptor) registry.lookupServiceDescriptor( ServiceDescriptorFactory.MODEL_SERVICE_TYPE, config.getSystemModelType(), null); UMOModel model = sd.createModel(); model.setName(MuleProperties.OBJECT_SYSTEM_MODEL); registry.registerModel(model); registry.initialise(); return registry; }