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()));
}
}
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);
}
}
}
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);
}
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());
}
}
}
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);
}
}
Aggregations