Search in sources :

Example 6 with MuleContextNotification

use of org.mule.runtime.core.api.context.notification.MuleContextNotification in project mule by mulesoft.

the class DefaultMuleApplication method setMuleContext.

private void setMuleContext(final MuleContext muleContext, Registry registry) {
    statusListener = new MuleContextNotificationListener<MuleContextNotification>() {

        @Override
        public boolean isBlocking() {
            return false;
        }

        @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());
            }
        }
    };
    notificationRegistrer = registry.lookupByType(NotificationListenerRegistry.class).get();
    notificationRegistrer.registerListener(statusListener);
}
Also used : Action(org.mule.runtime.api.notification.Notification.Action) IntegerAction(org.mule.runtime.api.notification.IntegerAction) IntegerAction(org.mule.runtime.api.notification.IntegerAction) MuleContextNotification(org.mule.runtime.core.api.context.notification.MuleContextNotification)

Example 7 with MuleContextNotification

use of org.mule.runtime.core.api.context.notification.MuleContextNotification in project mule by mulesoft.

the class DefaultMuleApplicationStatusTestCase method initialised.

@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);
}
Also used : MuleContextNotification(org.mule.runtime.core.api.context.notification.MuleContextNotification) Test(org.junit.Test)

Example 8 with MuleContextNotification

use of org.mule.runtime.core.api.context.notification.MuleContextNotification in project mule by mulesoft.

the class MuleContextLifecycleTestCase method notificationHasMuleContextRef.

@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());
}
Also used : Arrays(java.util.Arrays) QueueManager(org.mule.runtime.core.api.util.queue.QueueManager) InitialisationException(org.mule.runtime.api.lifecycle.InitialisationException) MuleContextNotification(org.mule.runtime.core.api.context.notification.MuleContextNotification) MuleContextListener(org.mule.runtime.core.api.context.notification.MuleContextListener) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) MuleContextNotificationListener(org.mule.runtime.core.api.context.notification.MuleContextNotificationListener) AtomicReference(java.util.concurrent.atomic.AtomicReference) MuleAssert.assertTrue(org.mule.tck.MuleAssert.assertTrue) ArrayList(java.util.ArrayList) Assert.assertSame(org.junit.Assert.assertSame) CONTEXT_STARTED(org.mule.runtime.core.api.context.notification.MuleContextNotification.CONTEXT_STARTED) MuleContextWithRegistries(org.mule.runtime.core.internal.context.MuleContextWithRegistries) AbstractMuleTestCase(org.mule.tck.junit4.AbstractMuleTestCase) MuleContext(org.mule.runtime.core.api.MuleContext) DefaultsConfigurationBuilder(org.mule.runtime.core.internal.config.builders.DefaultsConfigurationBuilder) DefaultMuleContextBuilder(org.mule.runtime.core.internal.context.DefaultMuleContextBuilder) MuleException(org.mule.runtime.api.exception.MuleException) After(org.junit.After) CONTEXT_STOPPED(org.mule.runtime.core.api.context.notification.MuleContextNotification.CONTEXT_STOPPED) Assert.fail(org.junit.Assert.fail) Registry(org.mule.runtime.api.artifact.Registry) MuleContextLifecycleManager(org.mule.runtime.core.internal.lifecycle.MuleContextLifecycleManager) JdkVersionUtils(org.mule.runtime.core.internal.util.JdkVersionUtils) Before(org.junit.Before) Disposable(org.mule.runtime.api.lifecycle.Disposable) LifecycleException(org.mule.runtime.api.lifecycle.LifecycleException) Startable(org.mule.runtime.api.lifecycle.Startable) Assert.assertNotNull(org.junit.Assert.assertNotNull) CONTEXT_STOPPING(org.mule.runtime.core.api.context.notification.MuleContextNotification.CONTEXT_STOPPING) UUID(org.mule.runtime.core.api.util.UUID) Assert.assertTrue(org.junit.Assert.assertTrue) TestServicesConfigurationBuilder(org.mule.tck.config.TestServicesConfigurationBuilder) Test(org.junit.Test) Initialisable(org.mule.runtime.api.lifecycle.Initialisable) CONTEXT_STARTING(org.mule.runtime.core.api.context.notification.MuleContextNotification.CONTEXT_STARTING) NotificationListenerRegistry(org.mule.runtime.api.notification.NotificationListenerRegistry) List(java.util.List) Rule(org.junit.Rule) Assert.assertFalse(org.junit.Assert.assertFalse) Stoppable(org.mule.runtime.api.lifecycle.Stoppable) APP(org.mule.runtime.core.api.config.bootstrap.ArtifactType.APP) DefaultNotificationListenerRegistry(org.mule.runtime.core.internal.context.notification.DefaultNotificationListenerRegistry) Assert.assertEquals(org.junit.Assert.assertEquals) Mockito.mock(org.mockito.Mockito.mock) SecurityManager(org.mule.runtime.core.api.security.SecurityManager) MuleContext(org.mule.runtime.core.api.MuleContext) AtomicReference(java.util.concurrent.atomic.AtomicReference) DefaultsConfigurationBuilder(org.mule.runtime.core.internal.config.builders.DefaultsConfigurationBuilder) MuleContextNotification(org.mule.runtime.core.api.context.notification.MuleContextNotification) Test(org.junit.Test)

Aggregations

MuleContextNotification (org.mule.runtime.core.api.context.notification.MuleContextNotification)8 MuleException (org.mule.runtime.api.exception.MuleException)3 MuleRuntimeException (org.mule.runtime.api.exception.MuleRuntimeException)3 InitialisationException (org.mule.runtime.api.lifecycle.InitialisationException)3 LifecycleException (org.mule.runtime.api.lifecycle.LifecycleException)3 AtomicReference (java.util.concurrent.atomic.AtomicReference)2 Test (org.junit.Test)2 ConnectException (org.mule.runtime.core.api.connector.ConnectException)2 ArtifactShutdownSplashScreen (org.mule.runtime.core.internal.util.splash.ArtifactShutdownSplashScreen)2 ArtifactStartupSplashScreen (org.mule.runtime.core.internal.util.splash.ArtifactStartupSplashScreen)2 ServerShutdownSplashScreen (org.mule.runtime.core.internal.util.splash.ServerShutdownSplashScreen)2 ServerStartupSplashScreen (org.mule.runtime.core.internal.util.splash.ServerStartupSplashScreen)2 SplashScreen (org.mule.runtime.core.internal.util.splash.SplashScreen)2 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 List (java.util.List)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 After (org.junit.After)1 Assert.assertEquals (org.junit.Assert.assertEquals)1 Assert.assertFalse (org.junit.Assert.assertFalse)1