public final synchronized void dispose() { // TODO lifecycleManager.checkPhase(Disposable.PHASE_NAME); if (isDisposed()) { return; } try { doDispose(); lifecycleManager.firePhase(getManagementContext(), Disposable.PHASE_NAME); if (getParent() != null) { parent.dispose(); } else { // remove this referenceonce there is no one else left to dispose RegistryContext.setRegistry(null); } } catch (UMOException e) { // TO-DO logger.error("Failed to cleanly dispose: " + e.getMessage(), e); } }
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; }