@Test public void initialised() { // the context was initialised before we gave it to the application, so we need // to fire the notification again since the listener wasn't there notificationDispatcher.dispatch(new MuleContextNotification(muleContext, CONTEXT_INITIALISED)); assertStatus(ApplicationStatus.INITIALISED); }
@Override public void onNotification(MuleContextNotification notification) { switch (notification.getAction().getActionId()) { case CONTEXT_STARTING: startingNotificationFired.set(true); break; case CONTEXT_STARTED: startedNotificationFired.set(true); break; case CONTEXT_STOPPING: stoppingNotificationFired.set(true); break; case CONTEXT_STOPPED: stoppedNotificationFired.set(true); break; } } }
public MuleContextNotification(MuleContext context, String action) { this(context, getActionId(action)); }
@Test public void notificationHasMuleContextRef() throws Exception { ctx.initialise(); new DefaultsConfigurationBuilder().configure(ctx); final AtomicReference<MuleContext> contextFromNotification = new AtomicReference<>(); final AtomicReference<String> resourceId = new AtomicReference<>(); MuleContextNotificationListener<MuleContextNotification> listener = notification -> { contextFromNotification.set(notification.getMuleContext()); resourceId.set(notification.getResourceIdentifier()); }; notificationListenerRegistry.registerListener(listener); ctx.start(); assertNotNull(contextFromNotification.get()); assertSame(ctx, contextFromNotification.get()); assertEquals(ctx.getConfiguration().getId(), resourceId.get()); }
@Override public String toString() { return getEventName() + "{" + "action=" + getActionName(action) + ", resourceId=" + resourceIdentifier + ", timestamp=" + timestamp + "}"; }
@Test public void notificationHasMuleContextRef() throws Exception { ctx.initialise(); new DefaultsConfigurationBuilder().configure(ctx); final AtomicReference<MuleContext> contextFromNotification = new AtomicReference<>(); final AtomicReference<String> resourceId = new AtomicReference<>(); MuleContextNotificationListener<MuleContextNotification> listener = notification -> { contextFromNotification.set(notification.getMuleContext()); resourceId.set(notification.getResourceIdentifier()); }; notificationListenerRegistry.registerListener(listener); ctx.start(); assertNotNull(contextFromNotification.get()); assertSame(ctx, contextFromNotification.get()); assertEquals(ctx.getConfiguration().getId(), resourceId.get()); }
/** * Stops the <code>MuleContext</code> which stops all sessions and connectors * * @throws MuleException if either any of the sessions or connectors fail to stop */ @Override public void stop() throws MuleException { synchronized (lifecycleStateLock) { startLatch.release(); stopIfNeeded(extensionManager); getLifecycleManager().checkPhase(Stoppable.PHASE_NAME); fireNotification(new MuleContextNotification(this, CONTEXT_STOPPING)); getLifecycleManager().fireLifecycle(Stoppable.PHASE_NAME); fireNotification(new MuleContextNotification(this, CONTEXT_STOPPED)); listeners.forEach(l -> l.onStop(this, getApiRegistry())); } }
@Override public void onNotification(MuleContextNotification notification) { Action action = notification.getAction(); if (new IntegerAction(CONTEXT_INITIALISED).equals(action) || new IntegerAction(CONTEXT_STARTED).equals(action) || new IntegerAction(CONTEXT_STOPPED).equals(action) || new IntegerAction(CONTEXT_DISPOSED).equals(action)) { updateStatusFor(muleContext.getLifecycleManager().getCurrentPhase()); } } };
fireNotification(new MuleContextNotification(this, CONTEXT_DISPOSING)); notificationManager.fireNotification(new MuleContextNotification(this, CONTEXT_DISPOSED));
@Override public void onNotification(MuleContextNotification notification) { switch (notification.getAction().getActionId()) { case CONTEXT_STARTING: startingNotificationFired.set(true); break; case CONTEXT_STARTED: startedNotificationFired.set(true); break; case CONTEXT_STOPPING: stoppingNotificationFired.set(true); break; case CONTEXT_STOPPED: stoppedNotificationFired.set(true); break; } } }
@Test public void initialised() { // the context was initialised before we gave it to the application, so we need // to fire the notification again since the listener wasn't there notificationDispatcher.dispatch(new MuleContextNotification(muleContext, CONTEXT_INITIALISED)); assertStatus(ApplicationStatus.INITIALISED); }
@Override public void onNotification(MuleContextNotification notification) { Action action = notification.getAction(); if (new IntegerAction(CONTEXT_INITIALISED).equals(action) || new IntegerAction(CONTEXT_STARTED).equals(action) || new IntegerAction(CONTEXT_STOPPED).equals(action) || new IntegerAction(CONTEXT_DISPOSED).equals(action)) { updateStatusFor(muleContext.getLifecycleManager().getCurrentPhase()); } } };
@Override public void start() throws MuleException { synchronized (lifecycleStateLock) { getLifecycleManager().checkPhase(Startable.PHASE_NAME); if (getQueueManager() == null) { throw new MuleRuntimeException(objectIsNull("queueManager")); } componentInitialStateManager = muleRegistryHelper.get(OBJECT_COMPONENT_INITIAL_STATE_MANAGER); startDate = System.currentTimeMillis(); startIfNeeded(extensionManager); fireNotification(new MuleContextNotification(this, CONTEXT_STARTING)); getLifecycleManager().fireLifecycle(Startable.PHASE_NAME); overridePollingController(); overrideClusterConfiguration(); startMessageSources(); fireNotification(new MuleContextNotification(this, CONTEXT_STARTED)); listeners.forEach(l -> l.onStart(this, getApiRegistry())); startLatch.release(); if (logger.isInfoEnabled()) { SplashScreen startupScreen = buildStartupSplash(); logger.info(startupScreen.toString()); } } }
fireNotification(new MuleContextNotification(this, CONTEXT_INITIALISING)); getLifecycleManager().fireLifecycle(Initialisable.PHASE_NAME); fireNotification(new MuleContextNotification(this, CONTEXT_INITIALISED)); listeners.forEach(l -> l.onInitialization(this, getApiRegistry()));