// This method is used when the service invoked synchronously. It should really // be used independantly of if the service is invoked synchronously when we are // using an out-only outbound message exchange pattern protected MuleMessage sendToOutboundRouter(MuleEvent event, MuleMessage result) throws MessagingException { if (event.isStopFurtherProcessing()) { logger.debug( "MuleEvent stop further processing has been set, no outbound routing will be performed."); } if (result != null && !event.isStopFurtherProcessing() && !(result.getPayload() instanceof NullPayload)) { if (getOutboundRouter().hasEndpoints()) { // Here we need to use a copy of the message instance because there // is an inbound response so that transformers executed as part of // the outbound phase do not affect the inbound response. MULE-3307 if (stats.isEnabled()) { stats.incSentEventSync(); } MuleMessage outboundReturnMessage = getOutboundRouter() .route(new DefaultMuleMessage(result.getPayload(), result), event.getSession()); if (outboundReturnMessage != null) { result = outboundReturnMessage; } } else { logger.debug( "Outbound router on service '" + getName() + "' doesn't have any endpoints configured."); } } return result; }
public void dispatchEvent(MuleEvent event) throws MuleException { if (stopping.get() || stopped.get()) { throw new ServiceException(CoreMessages.componentIsStopped(name), event.getMessage(), this); } // Dispatching event to an inbound endpoint // in the DefaultMuleSession#dispatchEvent ImmutableEndpoint endpoint = event.getEndpoint(); if (endpoint instanceof OutboundEndpoint) { try { ((OutboundEndpoint) endpoint).dispatch(event); } catch (Exception e) { throw new DispatchException(event.getMessage(), event.getEndpoint(), e); } return; } if (logger.isDebugEnabled()) { logger.debug( "Service: " + name + " has received asynchronous event on: " + event.getEndpoint().getEndpointURI()); } // Dispatching event to the service if (stats.isEnabled()) { stats.incReceivedEventASync(); } doDispatch(event); }
/** * 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); }
// This method is used when the service invoked asynchronously. It should really // be used independantly of if the service is invoked asynchronously when we are // using an out-in or out-optional-in outbound message exchange pattern protected void dispatchToOutboundRouter(MuleEvent event, MuleMessage result) throws MessagingException { if (event.isStopFurtherProcessing()) { logger.debug( "MuleEvent stop further processing has been set, no outbound routing will be performed."); } if (result != null && !event.isStopFurtherProcessing()) { if (getOutboundRouter().hasEndpoints()) { // Here we can use the same message instance because there is no inbound response. if (stats.isEnabled()) { stats.incSentEventASync(); } getOutboundRouter().route(result, event.getSession()); } } }
/** * 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 MuleMessage sendEvent(MuleEvent event) throws MuleException { if (stopping.get() || stopped.get()) { throw new ServiceException(CoreMessages.componentIsStopped(name), event.getMessage(), this); } try { waitIfPaused(event); } catch (InterruptedException e) { throw new ServiceException(event.getMessage(), this, e); } if (stats.isEnabled()) { stats.incReceivedEventSync(); } if (logger.isDebugEnabled()) { logger.debug( "Service: " + name + " has received synchronous event on: " + event.getEndpoint().getEndpointURI()); } event = OptimizedRequestContext.unsafeSetEvent(event); return doSend(event); }