/** * Initialise the service. The service will first create a Mule UMO from the UMODescriptor and * then initialise a pool based on the attributes in the UMODescriptor. * * @throws org.mule.api.lifecycle.InitialisationException if the service fails to initialise */ public final synchronized void initialise() throws InitialisationException { if (initialised.get()) { throw new InitialisationException( CoreMessages.objectAlreadyInitialised("Service '" + name + "'"), this); } // Ensure Component has service instance and is initialised. If the component // was configured with spring and is therefore in the registry it will get // started automatically, if it was set on the service directly then it won't // be started automatically. So to be sure we start it here. component.setService(this); component.initialise(); if (inboundRouter == null) { // Create Default routes that route to the default inbound and // outbound endpoints inboundRouter = new DefaultInboundRouterCollection(); // TODO MULE-2102 This should be configured in the default template. inboundRouter.addRouter(new InboundPassThroughRouter()); } if (outboundRouter == null) { outboundRouter = new DefaultOutboundRouterCollection(); // TODO MULE-2102 This should be configured in the default template. outboundRouter.addRouter(new OutboundPassThroughRouter()); } if (responseRouter == null) { responseRouter = new DefaultResponseRouterCollection(); } if (exceptionListener == null) { // By default us the model Exception Listener exceptionListener = getModel().getExceptionListener(); // // TODO MULE-2102 This should be configured in the default template. // exceptionListener = new DefaultServiceExceptionStrategy(this); // ((MuleContextAware) exceptionListener).setMuleContext(muleContext); // ((Initialisable) exceptionListener).initialise(); } doInitialise(); // initialise statistics stats = createStatistics(); stats.setEnabled(muleContext.getStatistics().isEnabled()); muleContext.getStatistics().add(stats); stats.setOutboundRouterStat(outboundRouter.getStatistics()); stats.setInboundRouterStat(inboundRouter.getStatistics()); stats.setComponentStat(component.getStatistics()); initialised.set(true); fireServiceNotification(ServiceNotification.SERVICE_INITIALISED); }
public void stop() throws MuleException { if (!stopped.get()) { logger.debug("Stopping Service"); stopping.set(true); fireServiceNotification(ServiceNotification.SERVICE_STOPPING); // Unregister Listeners for the service unregisterListeners(); // Resume if paused. (This is required so that stop() doesn't hand and so // message aren't lost in SedaQueue when service is stopped. if (isPaused()) { resume(); } doStop(); // Stop component. We do this here in case there are any queues that need to be consumed // first. component.stop(); stopped.set(true); fireServiceNotification(ServiceNotification.SERVICE_STOPPED); logger.info("Mule Service " + name + " has been stopped successfully"); } }
/** * Initialise the service. The service will first create a component from the ServiceDescriptor * and then initialise a pool based on the attributes in the ServiceDescriptor . * * @see org.mule.api.registry.ServiceDescriptor * @throws org.mule.api.lifecycle.InitialisationException if the service fails to initialise */ public final synchronized void initialise() throws InitialisationException { if (inboundRouter == null) { // Create Default routes that route to the default inbound and // outbound endpoints inboundRouter = new DefaultInboundRouterCollection(); // TODO MULE-2102 This should be configured in the default template. inboundRouter.addRouter(new InboundPassThroughRouter()); } if (outboundRouter == null) { outboundRouter = new DefaultOutboundRouterCollection(); // TODO MULE-2102 This should be configured in the default template. outboundRouter.addRouter(new OutboundPassThroughRouter()); } if (responseRouter == null) { responseRouter = new DefaultResponseRouterCollection(); } if (exceptionListener == null) { // By default us the model Exception Listener exceptionListener = getModel().getExceptionListener(); // // TODO MULE-2102 This should be configured in the default template. // exceptionListener = new DefaultServiceExceptionStrategy(this); // ((MuleContextAware) exceptionListener).setMuleContext(muleContext); // ((Initialisable) exceptionListener).initialise(); } try { lifecycleManager.fireLifecycle(Initialisable.PHASE_NAME); } catch (LifecycleException e) { throw new InitialisationException(e, this); } // Ensure Component has service instance and is initialised. If the component // was configured with spring and is therefore in the registry it will get // started automatically, if it was set on the service directly then it won't // be started automatically. So to be sure we start it here. component.setService(this); component.initialise(); // initialise statistics stats = createStatistics(); stats.setEnabled(muleContext.getStatistics().isEnabled()); muleContext.getStatistics().add(stats); stats.setOutboundRouterStat(outboundRouter.getStatistics()); stats.setInboundRouterStat(inboundRouter.getStatistics()); stats.setComponentStat(component.getStatistics()); }
public final void dispose() { try { lifecycleManager.fireLifecycle(Disposable.PHASE_NAME); } catch (MuleException e) { logger.error("Failed to stop service: " + name, e); } component.dispose(); muleContext.getStatistics().remove(stats); }
public void stop() throws MuleException { // TODO this wasn't being called stopListeners(); // Unregister Listeners for the service unregisterListeners(); // Stop component. We do this here in case there are any queues that need to be consumed first. component.stop(); lifecycleManager.fireLifecycle(Stoppable.PHASE_NAME); }
public final void dispose() { try { if (!stopped.get()) { stop(); } } catch (MuleException e) { // TODO MULE-863: If this is an error, do something! logger.error("Failed to stop service: " + name, e); } doDispose(); component.dispose(); initialised.set(false); fireServiceNotification(ServiceNotification.SERVICE_DISPOSED); muleContext.getStatistics().remove(stats); }
public void stop() throws MuleException { if (!stopped.get()) { logger.debug("Stopping Service"); stopping.set(true); fireServiceNotification(ServiceNotification.SERVICE_STOPPING); // Unregister Listeners for the service unregisterListeners(); component.stop(); doStop(); stopped.set(true); fireServiceNotification(ServiceNotification.SERVICE_STOPPED); logger.info("Mule Service " + name + " has been stopped successfully"); } }
public void start() throws MuleException { lifecycleManager.checkPhase(Startable.PHASE_NAME); if (!beyondInitialState.get() && initialState.equals(AbstractService.INITIAL_STATE_STOPPED)) { logger.info("Service " + name + " has not been started (initial state = 'stopped')"); beyondInitialState.set(true); return; } // Ensure Component is started. If component was configured with spring and // is therefore in the registry it will get started automatically, if it was // set on the service directly then it won't be started automatically. So to // be sure we start it here. component.start(); // Create the receivers for the service but do not start them yet. registerListeners(); // We connect the receivers _before_ starting the service because there may // be // some initialization required for the service which needs to have them // connected. // For example, the org.mule.transport.soap.glue.GlueMessageReceiver adds // InitialisationCallbacks within its doConnect() method (see MULE-804). connectListeners(); if (!beyondInitialState.get() && initialState.equals(AbstractService.INITIAL_STATE_PAUSED)) { lifecycleManager.fireLifecycle(Startable.PHASE_NAME); lifecycleManager.fireLifecycle(Pausable.PHASE_NAME); logger.info("Service " + name + " has been started and paused (initial state = 'paused')"); } else { lifecycleManager.fireLifecycle(Startable.PHASE_NAME); logger.info("Service " + name + " has been started successfully"); } beyondInitialState.set(true); // We start the receivers _after_ starting the service because if a message // gets routed to the service before it is started, // org.mule.model.AbstractComponent.dispatchEvent() will throw a // ServiceException with message COMPONENT_X_IS_STOPPED (see MULE-526). startListeners(); }
/** * Starts a Mule Service. * * @param startPaused - Start service in a "paused" state (messages are received but not * processed). */ protected void start(boolean startPaused) throws MuleException { // Ensure Component is started. If component was configured with spring and // is therefore in the registry it will get started automatically, if it was // set on the service directly then it won't be started automatically. So to // be sure we start it here. component.start(); // Create the receivers for the service but do not start them yet. registerListeners(); // We connect the receivers _before_ starting the service because there may // be // some initialization required for the service which needs to have them // connected. // For example, the org.mule.transport.soap.glue.GlueMessageReceiver adds // InitialisationCallbacks within its doConnect() method (see MULE-804). connectListeners(); // Start (and pause) the service. if (stopped.get()) { stopped.set(false); paused.set(false); doStart(); } fireServiceNotification(ServiceNotification.SERVICE_STARTED); if (startPaused) { pause(); } // We start the receivers _after_ starting the service because if a message // gets routed to the service before it is started, // org.mule.model.AbstractComponent.dispatchEvent() will throw a // ServiceException with message COMPONENT_X_IS_STOPPED (see MULE-526). startListeners(); }
protected MuleMessage invokeComponent(MuleEvent event) throws MuleException { return component.invoke(event); }