protected void doStart() throws MuleException { try { workManager.start(); workManager.scheduleWork(this, WorkManager.INDEFINITE, null, this); } catch (Exception e) { throw new LifecycleException(CoreMessages.failedToStart("Service: " + name), e, this); } }
protected void doDispose() { queue = null; // threadPool.awaitTerminationAfterShutdown(); if (workManager != null) { workManager.dispose(); } }
protected void doStop() throws MuleException { if (muleContext.getQueueManager().getQueueSession().getQueue(name).size() > 0) { try { stopping.whenFalse(null); } catch (InterruptedException e) { // we can ignore this // TODO MULE-863: Why? } } workManager.dispose(); }
protected void doStop() throws MuleException { if (queue != null && queue.size() > 0) { try { stopping.whenFalse(null); } catch (InterruptedException e) { // we can ignore this // TODO MULE-863: Why? } } workManager.dispose(); }
public synchronized void dispose() { if (isDisposed()) { return; } ServerNotificationManager notificationManager = getNotificationManager(); lifecycleManager.checkPhase(Disposable.PHASE_NAME); fireNotification(new MuleContextNotification(this, MuleContextNotification.CONTEXT_DISPOSING)); try { if (isStarted()) { stop(); } } catch (MuleException e) { logger.error("Failed to stop manager: " + e.getMessage(), e); } try { lifecycleManager.firePhase(this, Disposable.PHASE_NAME); // Dispose internal registries registryBroker.dispose(); } catch (Exception e) { logger.debug("Failed to cleanly dispose Mule: " + e.getMessage(), e); } notificationManager.fireNotification( new MuleContextNotification(this, MuleContextNotification.CONTEXT_DISPOSED)); notificationManager.dispose(); workManager.dispose(); if ((getStartDate() > 0) && logger.isInfoEnabled()) { SplashScreen splashScreen = SplashScreen.getInstance(ServerShutdownSplashScreen.class); splashScreen.setHeader(this); logger.info(splashScreen.toString()); } // SplashScreen holds static variables which need to be cleared in case we restart the server. SplashScreen.dispose(); }
public synchronized void initialise() throws InitialisationException { if (isInitialised()) { return; } lifecycleManager.checkPhase(Initialisable.PHASE_NAME); if (getNotificationManager() == null) { throw new MuleRuntimeException( CoreMessages.objectIsNull(MuleProperties.OBJECT_NOTIFICATION_MANAGER)); } if (workManager == null) { throw new MuleRuntimeException(CoreMessages.objectIsNull("workManager")); } try { registryBroker = createRegistryBroker(); muleRegistryHelper = createRegistryHelper(registryBroker); // Initialize internal registries registryBroker.initialise(); // We need to start the work manager straight away since we need it to fire notifications workManager.start(); getNotificationManager().start(workManager, workListener); fireNotification( new MuleContextNotification(this, MuleContextNotification.CONTEXT_INITIALISING)); lifecycleManager.firePhase(this, Initialisable.PHASE_NAME); fireNotification( new MuleContextNotification(this, MuleContextNotification.CONTEXT_INITIALISED)); } catch (Exception e) { throw new InitialisationException(e, this); } }
/** * While the service isn't stopped this runs a continuous loop checking for new events in the * queue. */ public void run() { DefaultMuleEvent event = null; QueueSession queueSession = muleContext.getQueueManager().getQueueSession(); while (!stopped.get()) { try { // Wait if the service is paused paused.whenFalse(null); // If we're doing a draining stop, read all events from the queue // before stopping if (stopping.get()) { if (queueSession == null || getQueueSize() <= 0) { stopping.set(false); break; } } event = (DefaultMuleEvent) dequeue(); if (event != null) { if (stats.isEnabled()) { stats.decQueuedEvent(); } if (logger.isDebugEnabled()) { logger.debug( "Service: " + name + " dequeued event on: " + event.getEndpoint().getEndpointURI()); } workManager.scheduleWork( new ComponentStageWorker(event), WorkManager.INDEFINITE, null, this); } } catch (Exception e) { if (isStopped() || isStopping()) { break; } if (e instanceof InterruptedException) { stopping.set(false); break; } else if (e instanceof NoSuchElementException) { handleException( new ServiceException( CoreMessages.proxyPoolTimedOut(), (event == null ? null : event.getMessage()), this, e)); } else if (e instanceof MuleException) { handleException(e); } else if (e instanceof WorkException) { handleException( new ServiceException( CoreMessages.eventProcessingFailedFor(name), (event == null ? null : event.getMessage()), this, e)); } else { handleException( new ServiceException( CoreMessages.failedToGetPooledObject(), (event == null ? null : event.getMessage()), this, e)); } } finally { stopping.set(false); } } }
/** * While the service isn't stopped this runs a continuous loop checking for new events in the * queue. */ public void run() { DefaultMuleEvent event = null; QueueSession queueSession = muleContext.getQueueManager().getQueueSession(); while (!stopped.get()) { try { // Wait if the service is paused if (paused.get()) { paused.whenFalse(null); // If service is resumed as part of stopping if (stopping.get()) { if (!queueProfile.isPersistent() && (queueSession != null && getQueueSize() > 0)) { // Any messages in a non-persistent queue went paused service is stopped are lost logger.warn( CoreMessages.stopPausedSedaServiceNonPeristentQueueMessageLoss( getQueueSize(), this)); } stopping.set(false); break; } } // If we're doing a draining stop, read all events from the queue // before stopping if (stopping.get()) { if (queueProfile.isPersistent() || (queueSession == null || getQueueSize() <= 0)) { stopping.set(false); break; } } if (stats.isEnabled()) { synchronized (queueStatsGuard) { event = (DefaultMuleEvent) dequeue(); if (event != null) { stats.decQueuedEvent(); } } } else { // just dequeue without any hit for synchronization event = (DefaultMuleEvent) dequeue(); } if (event != null) { if (logger.isDebugEnabled()) { logger.debug( MessageFormat.format( "Service: {0} dequeued event on: {1}", name, event.getEndpoint().getEndpointURI())); } workManager.scheduleWork( new ComponentStageWorker(event), WorkManager.INDEFINITE, null, this); } } catch (Exception e) { if (e instanceof InterruptedException) { stopping.set(false); break; } if (e instanceof MuleException) { handleException(e); } else { handleException( new ServiceException( CoreMessages.eventProcessingFailedFor(name), (event == null ? null : event.getMessage()), this, e)); } } } }