Search in sources :

Example 1 with MuleContextNotificationListener

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

the class AbstractMuleContextTestCase method startMuleContext.

private void startMuleContext() throws MuleException, InterruptedException {
    final AtomicReference<Latch> contextStartedLatch = new AtomicReference<>();
    contextStartedLatch.set(new Latch());
    // Do not inline it, otherwise the type of the listener is lost
    final MuleContextNotificationListener<MuleContextNotification> listener = new MuleContextNotificationListener<MuleContextNotification>() {

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

        @Override
        public void onNotification(MuleContextNotification notification) {
            contextStartedLatch.get().countDown();
        }
    };
    muleContext.getNotificationManager().addListener(listener);
    muleContext.start();
    contextStartedLatch.get().await(20, SECONDS);
}
Also used : Latch(org.mule.runtime.api.util.concurrent.Latch) MuleContextNotificationListener(org.mule.runtime.core.api.context.notification.MuleContextNotificationListener) AtomicReference(java.util.concurrent.atomic.AtomicReference) MuleContextNotification(org.mule.runtime.core.api.context.notification.MuleContextNotification)

Example 2 with MuleContextNotificationListener

use of org.mule.runtime.core.api.context.notification.MuleContextNotificationListener 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

AtomicReference (java.util.concurrent.atomic.AtomicReference)2 MuleContextNotification (org.mule.runtime.core.api.context.notification.MuleContextNotification)2 MuleContextNotificationListener (org.mule.runtime.core.api.context.notification.MuleContextNotificationListener)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 Assert.assertNotNull (org.junit.Assert.assertNotNull)1 Assert.assertSame (org.junit.Assert.assertSame)1 Assert.assertTrue (org.junit.Assert.assertTrue)1 Assert.fail (org.junit.Assert.fail)1 Before (org.junit.Before)1 Rule (org.junit.Rule)1 Test (org.junit.Test)1 Mockito.mock (org.mockito.Mockito.mock)1 Registry (org.mule.runtime.api.artifact.Registry)1 MuleException (org.mule.runtime.api.exception.MuleException)1