Search in sources :

Example 1 with MuleContextNotification

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

the class DefaultMuleContext method stop.

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

Example 2 with MuleContextNotification

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

the class DefaultMuleContext method initialise.

@Override
public void initialise() throws InitialisationException {
    synchronized (lifecycleStateLock) {
        lifecycleManager.checkPhase(Initialisable.PHASE_NAME);
        if (getNotificationManager() == null) {
            throw new MuleRuntimeException(objectIsNull(OBJECT_NOTIFICATION_MANAGER));
        }
        try {
            JdkVersionUtils.validateJdk();
        } catch (RuntimeException e) {
            throw new InitialisationException(invalidJdk(JAVA_VERSION, getSupportedJdks()), this);
        }
        try {
            id = getConfiguration().getDomainId() + "." + getClusterId() + "." + getConfiguration().getId();
            // Initialize the helper, this only initialises the helper class and does not call the registry lifecycle manager
            // The registry lifecycle is called below using 'getLifecycleManager().fireLifecycle(Initialisable.PHASE_NAME);'
            getRegistry().initialise();
            fireNotification(new MuleContextNotification(this, CONTEXT_INITIALISING));
            getLifecycleManager().fireLifecycle(Initialisable.PHASE_NAME);
            fireNotification(new MuleContextNotification(this, CONTEXT_INITIALISED));
            listeners.forEach(l -> l.onInitialization(this, getApiRegistry()));
            initialiseIfNeeded(getExceptionListener(), true, this);
            getNotificationManager().initialise();
            // refresh object serializer reference in case a default one was redefined in the config.
            objectSerializer = registryBroker.get(DEFAULT_OBJECT_SERIALIZER_NAME);
        } catch (InitialisationException e) {
            dispose();
            throw e;
        } catch (Exception e) {
            dispose();
            throw new InitialisationException(e, this);
        }
    }
}
Also used : MuleRuntimeException(org.mule.runtime.api.exception.MuleRuntimeException) MuleRuntimeException(org.mule.runtime.api.exception.MuleRuntimeException) InitialisationException(org.mule.runtime.api.lifecycle.InitialisationException) MuleContextNotification(org.mule.runtime.core.api.context.notification.MuleContextNotification) InitialisationException(org.mule.runtime.api.lifecycle.InitialisationException) MuleRuntimeException(org.mule.runtime.api.exception.MuleRuntimeException) MuleException(org.mule.runtime.api.exception.MuleException) ConnectException(org.mule.runtime.core.api.connector.ConnectException) LifecycleException(org.mule.runtime.api.lifecycle.LifecycleException) RegistrationException(org.mule.runtime.core.privileged.registry.RegistrationException)

Example 3 with MuleContextNotification

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

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

the class DefaultMuleContext method start.

@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());
        }
    }
}
Also used : MuleRuntimeException(org.mule.runtime.api.exception.MuleRuntimeException) SplashScreen(org.mule.runtime.core.internal.util.splash.SplashScreen) ServerStartupSplashScreen(org.mule.runtime.core.internal.util.splash.ServerStartupSplashScreen) ArtifactShutdownSplashScreen(org.mule.runtime.core.internal.util.splash.ArtifactShutdownSplashScreen) ServerShutdownSplashScreen(org.mule.runtime.core.internal.util.splash.ServerShutdownSplashScreen) ArtifactStartupSplashScreen(org.mule.runtime.core.internal.util.splash.ArtifactStartupSplashScreen) MuleContextNotification(org.mule.runtime.core.api.context.notification.MuleContextNotification)

Example 5 with MuleContextNotification

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

the class DefaultMuleContext method dispose.

@Override
public void dispose() {
    synchronized (lifecycleStateLock) {
        if (isStarted() || (lifecycleManager.getLastPhaseExecuted() != null && (lifecycleManager.getLastPhaseExecuted().equals(Startable.PHASE_NAME) && lifecycleManager.isLastPhaseExecutionFailed()))) {
            try {
                stop();
            } catch (MuleException e) {
                logger.error("Failed to stop Mule context", e);
            }
        }
        getLifecycleManager().checkPhase(Disposable.PHASE_NAME);
        fireNotification(new MuleContextNotification(this, CONTEXT_DISPOSING));
        disposeIfNeeded(getExceptionListener(), logger);
        try {
            getLifecycleManager().fireLifecycle(Disposable.PHASE_NAME);
            // abstraction?
            if (muleRegistryHelper != null) {
                safely(() -> muleRegistryHelper.dispose());
            }
        } catch (Exception e) {
            logger.debug("Failed to cleanly dispose Mule: " + e.getMessage(), e);
        }
        notificationManager.fireNotification(new MuleContextNotification(this, CONTEXT_DISPOSED));
        disposeManagers();
        if ((getStartDate() > 0) && logger.isInfoEnabled()) {
            SplashScreen shutdownScreen = buildShutdownSplash();
            logger.info(shutdownScreen.toString());
        }
        // registryBroker.dispose();
        setExecutionClassLoader(null);
    }
}
Also used : SplashScreen(org.mule.runtime.core.internal.util.splash.SplashScreen) ServerStartupSplashScreen(org.mule.runtime.core.internal.util.splash.ServerStartupSplashScreen) ArtifactShutdownSplashScreen(org.mule.runtime.core.internal.util.splash.ArtifactShutdownSplashScreen) ServerShutdownSplashScreen(org.mule.runtime.core.internal.util.splash.ServerShutdownSplashScreen) ArtifactStartupSplashScreen(org.mule.runtime.core.internal.util.splash.ArtifactStartupSplashScreen) MuleContextNotification(org.mule.runtime.core.api.context.notification.MuleContextNotification) MuleException(org.mule.runtime.api.exception.MuleException) InitialisationException(org.mule.runtime.api.lifecycle.InitialisationException) MuleRuntimeException(org.mule.runtime.api.exception.MuleRuntimeException) MuleException(org.mule.runtime.api.exception.MuleException) ConnectException(org.mule.runtime.core.api.connector.ConnectException) LifecycleException(org.mule.runtime.api.lifecycle.LifecycleException) RegistrationException(org.mule.runtime.core.privileged.registry.RegistrationException)

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