Coverage Report - org.mule.service.AbstractService
 
Classes in this File Line Coverage Branch Coverage Complexity
AbstractService
0%
0/194
0%
0/46
0
AbstractService$1
0%
0/12
0%
0/4
0
AbstractService$2
0%
0/3
N/A
0
AbstractService$3
0%
0/3
N/A
0
AbstractService$4
0%
0/3
N/A
0
AbstractService$5
0%
0/3
N/A
0
AbstractService$6
0%
0/3
N/A
0
AbstractService$7
0%
0/2
N/A
0
 
 1  
 /*
 2  
  * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
 3  
  * The software in this package is published under the terms of the CPAL v1.0
 4  
  * license, a copy of which has been included with this distribution in the
 5  
  * LICENSE.txt file.
 6  
  */
 7  
 package org.mule.service;
 8  
 
 9  
 import org.mule.DefaultMuleEvent;
 10  
 import org.mule.RequestContext;
 11  
 import org.mule.api.MuleContext;
 12  
 import org.mule.api.MuleEvent;
 13  
 import org.mule.api.MuleException;
 14  
 import org.mule.api.MuleRuntimeException;
 15  
 import org.mule.api.MuleSession;
 16  
 import org.mule.api.component.Component;
 17  
 import org.mule.api.construct.FlowConstruct;
 18  
 import org.mule.api.construct.FlowConstructAware;
 19  
 import org.mule.api.context.MuleContextAware;
 20  
 import org.mule.api.exception.MessagingExceptionHandler;
 21  
 import org.mule.api.lifecycle.Disposable;
 22  
 import org.mule.api.lifecycle.Initialisable;
 23  
 import org.mule.api.lifecycle.InitialisationException;
 24  
 import org.mule.api.lifecycle.LifecycleCallback;
 25  
 import org.mule.api.lifecycle.LifecycleManager;
 26  
 import org.mule.api.lifecycle.LifecycleState;
 27  
 import org.mule.api.lifecycle.Startable;
 28  
 import org.mule.api.lifecycle.Stoppable;
 29  
 import org.mule.api.model.Model;
 30  
 import org.mule.api.processor.MessageProcessor;
 31  
 import org.mule.api.processor.MessageProcessorChain;
 32  
 import org.mule.api.processor.MessageProcessorChainBuilder;
 33  
 import org.mule.api.routing.MessageInfoMapping;
 34  
 import org.mule.api.routing.OutboundRouterCollection;
 35  
 import org.mule.api.routing.RouterStatisticsRecorder;
 36  
 import org.mule.api.service.Service;
 37  
 import org.mule.api.source.MessageSource;
 38  
 import org.mule.component.simple.PassThroughComponent;
 39  
 import org.mule.config.i18n.CoreMessages;
 40  
 import org.mule.lifecycle.EmptyLifecycleCallback;
 41  
 import org.mule.lifecycle.processor.ProcessIfStartedWaitIfPausedMessageProcessor;
 42  
 import org.mule.management.stats.RouterStatistics;
 43  
 import org.mule.management.stats.ServiceStatistics;
 44  
 import org.mule.processor.AbstractInterceptingMessageProcessor;
 45  
 import org.mule.processor.chain.DefaultMessageProcessorChainBuilder;
 46  
 import org.mule.routing.MuleMessageInfoMapping;
 47  
 import org.mule.routing.outbound.DefaultOutboundRouterCollection;
 48  
 import org.mule.service.processor.ServiceAsyncRequestReplyRequestor;
 49  
 import org.mule.session.DefaultMuleSession;
 50  
 import org.mule.util.ClassUtils;
 51  
 
 52  
 import org.apache.commons.logging.Log;
 53  
 import org.apache.commons.logging.LogFactory;
 54  
 
 55  
 /**
 56  
  * A base implementation for all Services in Mule
 57  
  */
 58  0
 public abstract class AbstractService implements Service, MessageProcessor
 59  
 {
 60  
 
 61  
     /**
 62  
      * logger used by this class
 63  
      */
 64  0
     protected transient Log logger = LogFactory.getLog(getClass());
 65  
 
 66  
     protected ServiceStatistics stats;
 67  
     /**
 68  
      * The model in which this service is registered
 69  
      */
 70  
     protected Model model;
 71  
 
 72  
     protected MuleContext muleContext;
 73  
 
 74  
     protected ServiceLifecycleManager lifecycleManager;
 75  
 
 76  
     /**
 77  
      * The initial states that the service can be started in
 78  
      */
 79  
     public static final String INITIAL_STATE_STOPPED = "stopped";
 80  
     public static final String INITIAL_STATE_STARTED = "started";
 81  
     public static final String INITIAL_STATE_PAUSED = "paused";
 82  
 
 83  
     /**
 84  
      * The exception strategy used by the service.
 85  
      */
 86  
     protected MessagingExceptionHandler exceptionListener;
 87  
 
 88  
     /**
 89  
      * The service's name
 90  
      */
 91  
     protected String name;
 92  
 
 93  0
     protected MessageProcessor outboundRouter = new DefaultOutboundRouterCollection();
 94  
 
 95  0
     protected MessageSource messageSource = new ServiceCompositeMessageSource();
 96  0
     protected ServiceAsyncReplyCompositeMessageSource asyncReplyMessageSource = new ServiceAsyncReplyCompositeMessageSource();
 97  
 
 98  
     protected MessageProcessorChain messageProcessorChain;
 99  0
     protected MessageInfoMapping messageInfoMapping = new MuleMessageInfoMapping();
 100  
 
 101  
     /**
 102  
      * Determines the initial state of this service when the model starts. Can be
 103  
      * 'stopped' or 'started' (default)
 104  
      */
 105  0
     protected String initialState = INITIAL_STATE_STARTED;
 106  
 
 107  
     // Default component to use if one is not configured.
 108  
     // TODO MULE-3113 This should not really be needed as to implement bridging we
 109  
     // should
 110  
     // should just increment a 'bridged' counter and sent the event straight to
 111  
     // outbound router collection. Currently it's the Component that routes events
 112  
     // onto the outbound router collection so this default implementation is needed.
 113  
     // It would be beneficial to differenciate between component invocations and
 114  
     // events that are bridged but currently everything is an invocation.
 115  0
     protected Component component = new PassThroughComponent();
 116  
 
 117  
     public AbstractService(MuleContext muleContext)
 118  0
     {
 119  0
         this.muleContext = muleContext;
 120  0
         ((MuleContextAware) component).setMuleContext(muleContext);
 121  
         try
 122  
         {
 123  0
             lifecycleManager = new ServiceLifecycleManager(this, muleContext);
 124  
         }
 125  0
         catch (MuleException e)
 126  
         {
 127  0
             throw new MuleRuntimeException(CoreMessages.failedToCreate("Service Lifecycle Manager"), e);
 128  0
         }
 129  
 
 130  0
     }
 131  
 
 132  
     //----------------------------------------------------------------------------------------//
 133  
     //-                    LIFECYCLE METHODS
 134  
     //----------------------------------------------------------------------------------------//
 135  
 
 136  
     /**
 137  
      * Initialise the service. The service will first create a component from the
 138  
      * ServiceDescriptor and then initialise a pool based on the attributes in the
 139  
      * ServiceDescriptor .
 140  
      *
 141  
      * @throws org.mule.api.lifecycle.InitialisationException
 142  
      *          if the service fails to
 143  
      *          initialise
 144  
      * @see org.mule.api.registry.ServiceDescriptor
 145  
      */
 146  
     public final synchronized void initialise() throws InitialisationException
 147  
     {
 148  
         try
 149  
         {
 150  0
             lifecycleManager.fireInitialisePhase(new LifecycleCallback<FlowConstruct>()
 151  0
             {
 152  
                 public void onTransition(String phaseName, FlowConstruct object) throws MuleException
 153  
                 {
 154  0
                     if (outboundRouter instanceof MuleContextAware)
 155  
                     {
 156  0
                         ((MuleContextAware) outboundRouter).setMuleContext(muleContext);
 157  
                     }
 158  
 
 159  0
                     if (exceptionListener == null)
 160  
                     {
 161  
                         // By default use the model Exception Listener
 162  
                         // TODO MULE-2102 This should be configured in the default template.
 163  0
                         exceptionListener = getModel().getExceptionListener();
 164  
                     }
 165  
 
 166  0
                     injectFlowConstructMuleContext(messageSource);
 167  0
                     injectFlowConstructMuleContext(asyncReplyMessageSource);
 168  0
                     injectFlowConstructMuleContext(messageProcessorChain);
 169  0
                     injectFlowConstructMuleContext(component);
 170  0
                     injectFlowConstructMuleContext(exceptionListener);
 171  
                     
 172  0
                     doInitialise();
 173  0
                 }
 174  
             });
 175  
         }
 176  0
         catch (InitialisationException e)
 177  
         {
 178  0
             throw e;
 179  
         }
 180  0
         catch (MuleException e)
 181  
         {
 182  0
             throw new InitialisationException(e, this);
 183  0
         }
 184  
 
 185  0
     }
 186  
 
 187  
     public void start() throws MuleException
 188  
     {
 189  0
         if (!isStopped() && initialState.equals(AbstractService.INITIAL_STATE_STOPPED))
 190  
         {
 191  
             //Transition to a stopped state without changing state of the flow construct
 192  0
             lifecycleManager.fireStartPhase(new EmptyLifecycleCallback<FlowConstruct>());
 193  0
             lifecycleManager.fireStopPhase(new EmptyLifecycleCallback<FlowConstruct>());
 194  
 
 195  0
             logger.info("Service " + name + " has not been started (initial state = 'stopped')");
 196  0
             return;
 197  
         }
 198  
         
 199  0
         lifecycleManager.fireStartPhase(new LifecycleCallback<FlowConstruct>()
 200  0
         {
 201  
             public void onTransition(String phaseName, FlowConstruct object) throws MuleException
 202  
             {
 203  0
                 doStart();
 204  0
             }
 205  
         });
 206  
 
 207  
         //Cannot call one lifecycle phase from within another, so we pause if necessary here
 208  0
         if ( initialState.equals(AbstractService.INITIAL_STATE_PAUSED))
 209  
         {
 210  0
             pause();
 211  0
             logger.info("Service " + name + " has been started and paused (initial state = 'paused')");
 212  
         }
 213  
 
 214  0
     }
 215  
 
 216  
     /**
 217  
      * Pauses event processing for a single Mule Service. Unlike stop(), a paused
 218  
      * service will still consume messages from the underlying transport, but those
 219  
      * messages will be queued until the service is resumed.
 220  
      */
 221  
     public final void pause() throws MuleException
 222  
     {
 223  0
         lifecycleManager.firePausePhase(new LifecycleCallback<FlowConstruct>()
 224  0
         {
 225  
             public void onTransition(String phaseName, FlowConstruct object) throws MuleException
 226  
             {
 227  0
                 doPause();
 228  0
             }
 229  
         });
 230  0
     }
 231  
 
 232  
     /**
 233  
      * Resumes a single Mule Service that has been paused. If the service is not
 234  
      * paused nothing is executed.
 235  
      */
 236  
     public final void resume() throws MuleException
 237  
     {
 238  0
         lifecycleManager.fireResumePhase(new LifecycleCallback<FlowConstruct>()
 239  0
         {
 240  
             public void onTransition(String phaseName, FlowConstruct object) throws MuleException
 241  
             {
 242  0
                 doResume();
 243  0
             }
 244  
         });
 245  0
     }
 246  
 
 247  
 
 248  
     public void stop() throws MuleException
 249  
     {
 250  0
         lifecycleManager.fireStopPhase(new LifecycleCallback<FlowConstruct>()
 251  0
         {
 252  
             public void onTransition(String phaseName, FlowConstruct object) throws MuleException
 253  
             {
 254  0
                 doStop();
 255  0
             }
 256  
         });
 257  0
     }
 258  
 
 259  
     public final void dispose()
 260  
     {
 261  
 
 262  
         try
 263  
         {
 264  0
             if (isStarted() || isPaused())
 265  
             {
 266  0
                 stop();
 267  
             }
 268  
 
 269  0
             lifecycleManager.fireDisposePhase(new LifecycleCallback<FlowConstruct>()
 270  0
             {
 271  
                 public void onTransition(String phaseName, FlowConstruct object) throws MuleException
 272  
                 {
 273  0
                     doDispose();
 274  0
                 }
 275  
             });
 276  
         }
 277  0
         catch (MuleException e)
 278  
         {
 279  0
             logger.error("Failed to stop service: " + name, e);
 280  0
         }
 281  0
     }
 282  
 
 283  
     public LifecycleState getLifecycleState()
 284  
     {
 285  0
         return lifecycleManager.getState();
 286  
     }
 287  
 
 288  
     public boolean isStarted()
 289  
     {
 290  0
         return lifecycleManager.getState().isStarted();
 291  
     }
 292  
 
 293  
     /**
 294  
      * Determines if the service is in a paused state
 295  
      * 
 296  
      * @return True if the service is in a paused state, false otherwise
 297  
      */
 298  
     public boolean isPaused()
 299  
     {
 300  0
         return lifecycleManager.getCurrentPhase().equals(Pausable.PHASE_NAME);
 301  
     }
 302  
 
 303  
     public boolean isStopped()
 304  
     {
 305  0
         return lifecycleManager.getState().isStopped();
 306  
     }
 307  
 
 308  
     public boolean isStopping()
 309  
     {
 310  0
         return lifecycleManager.getState().isStopping();
 311  
     }
 312  
 
 313  
     /**
 314  
      * Custom components can execute code necessary to put the service in a paused state here. If a developer
 315  
      * overloads this method the doResume() method MUST also be overloaded to avoid inconsistent state in the
 316  
      * service
 317  
      * 
 318  
      * @throws MuleException
 319  
      */
 320  
     protected void doPause() throws MuleException
 321  
     {
 322  
         // template method
 323  0
     }
 324  
 
 325  
     /**
 326  
      * Custom components can execute code necessary to resume a service once it has
 327  
      * been paused If a developer overloads this method the doPause() method MUST
 328  
      * also be overloaded to avoid inconsistent state in the service
 329  
      *
 330  
      * @throws MuleException
 331  
      */
 332  
     protected void doResume() throws MuleException
 333  
     {
 334  
         // template method
 335  0
     }
 336  
 
 337  
     protected void doForceStop() throws MuleException
 338  
     {
 339  
         // template method
 340  0
     }
 341  
 
 342  
     protected void doStop() throws MuleException
 343  
     {
 344  0
         stopIfStoppable(messageSource);
 345  0
         asyncReplyMessageSource.stop();
 346  
 
 347  0
         stopIfStoppable(messageProcessorChain);
 348  
         // Component is not in chain
 349  0
         stopIfStoppable(component);
 350  0
         stopIfStoppable(exceptionListener);
 351  0
     }
 352  
 
 353  
     protected void doStart() throws MuleException
 354  
     {
 355  
         // Component is not in chain
 356  0
         startIfStartable(exceptionListener);
 357  0
         startIfStartable(component);
 358  0
         startIfStartable(messageProcessorChain);
 359  
 
 360  0
         startIfStartable(messageSource);
 361  0
         if (asyncReplyMessageSource.getEndpoints().size() > 0)
 362  
         {
 363  0
             asyncReplyMessageSource.start();
 364  
         }
 365  0
     }
 366  
 
 367  
     protected void doDispose()
 368  
     {
 369  
         // Component is not in chain
 370  0
         disposeIfDisposable(component);
 371  0
         disposeIfDisposable(messageProcessorChain);
 372  0
         disposeIfDisposable(messageSource);
 373  0
         disposeIfDisposable(exceptionListener);
 374  0
         muleContext.getStatistics().remove(stats);
 375  0
     }
 376  
 
 377  
     protected void doInitialise() throws InitialisationException
 378  
     {
 379  
         // initialise statistics
 380  0
         stats = createStatistics();
 381  0
         stats.setEnabled(muleContext.getStatistics().isEnabled());
 382  0
         muleContext.getStatistics().add(stats);
 383  0
         RouterStatistics routerStatistics = null;
 384  
 
 385  
         // If the router collection already has router statistics, keep using them.
 386  0
         if (outboundRouter instanceof OutboundRouterCollection)
 387  
         {
 388  0
             routerStatistics = ((OutboundRouterCollection)outboundRouter).getRouterStatistics();
 389  
         }
 390  0
         if (routerStatistics == null)
 391  
         {
 392  0
             routerStatistics = new RouterStatistics(RouterStatistics.TYPE_OUTBOUND);
 393  
         }
 394  0
         stats.setOutboundRouterStat(routerStatistics);
 395  0
         if (outboundRouter != null && outboundRouter instanceof RouterStatisticsRecorder)
 396  
         {
 397  0
             ((RouterStatisticsRecorder)outboundRouter).setRouterStatistics(routerStatistics);
 398  
         }
 399  0
         RouterStatistics inboundRouterStatistics = new RouterStatistics(RouterStatistics.TYPE_INBOUND);
 400  0
         stats.setInboundRouterStat(inboundRouterStatistics);
 401  0
         if (messageSource instanceof RouterStatisticsRecorder)
 402  
         {
 403  0
             ((RouterStatisticsRecorder) messageSource).setRouterStatistics(inboundRouterStatistics);
 404  
         }
 405  0
         stats.setComponentStat(component.getStatistics());
 406  
 
 407  
         try
 408  
         {
 409  0
             buildServiceMessageProcessorChain();
 410  
         }
 411  0
         catch (MuleException e)
 412  
         {
 413  0
             throw new InitialisationException(e, this);
 414  0
         }
 415  
         
 416  
         // Wrap chain to decouple lifecycle
 417  0
         messageSource.setListener(new AbstractInterceptingMessageProcessor()
 418  0
         {
 419  
             public MuleEvent process(MuleEvent event) throws MuleException
 420  
             {
 421  0
                 return messageProcessorChain.process(event);
 422  
             }
 423  
         });
 424  
 
 425  0
         initialiseIfInitialisable(exceptionListener);
 426  0
         initialiseIfInitialisable(component);
 427  0
         initialiseIfInitialisable(messageProcessorChain);
 428  0
         initialiseIfInitialisable(messageSource);
 429  
         
 430  0
         if (asyncReplyMessageSource.getEndpoints().size() > 0)
 431  
         {
 432  0
             asyncReplyMessageSource.initialise();
 433  
         }
 434  0
     }
 435  
 
 436  
     public void forceStop() throws MuleException
 437  
     {
 438  
         // Kepping this here since I don't understand why this method exists. AFAICS
 439  
         // this just says the service is stopped
 440  
         // without actually stopping it
 441  
         // if (!stopped.get())
 442  
         // {
 443  
         // logger.debug("Stopping Service");
 444  
         // stopping.set(true);
 445  
         // fireServiceNotification(ServiceNotification.SERVICE_STOPPING);
 446  
         // doForceStop();
 447  
         // stopped.set(true);
 448  
         // stopping.set(false);
 449  
         // fireServiceNotification(ServiceNotification.SERVICE_STOPPED);
 450  
         // }
 451  0
         doForceStop();
 452  0
         stop();
 453  0
     }
 454  
 
 455  
 
 456  
     //----------------------------------------------------------------------------------------//
 457  
     //-                    END LIFECYCLE METHODS
 458  
     //----------------------------------------------------------------------------------------//
 459  
 
 460  
     protected void buildServiceMessageProcessorChain() throws MuleException
 461  
     {
 462  0
         DefaultMessageProcessorChainBuilder builder = new DefaultMessageProcessorChainBuilder(this);
 463  0
         builder.setName("Service '" + name + "' Processor Chain");
 464  0
         builder.chain(getServiceStartedAssertingMessageProcessor());
 465  0
         addMessageProcessors(builder);
 466  0
         messageProcessorChain = builder.build();
 467  0
     }
 468  
 
 469  
     protected MessageProcessor getServiceStartedAssertingMessageProcessor()
 470  
     {
 471  0
         return new ProcessIfStartedWaitIfPausedMessageProcessor(this, lifecycleManager.getState());
 472  
     }
 473  
 
 474  
     protected abstract void addMessageProcessors(MessageProcessorChainBuilder builder);
 475  
 
 476  
     protected ServiceStatistics createStatistics()
 477  
     {
 478  0
         return new ServiceStatistics(name);
 479  
     }
 480  
 
 481  
     public ServiceStatistics getStatistics()
 482  
     {
 483  0
         return stats;
 484  
     }
 485  
 
 486  
     @Deprecated
 487  
     public void dispatchEvent(MuleEvent event) throws MuleException
 488  
     {
 489  0
         messageProcessorChain.process(event);
 490  0
     }
 491  
 
 492  
     @Deprecated
 493  
     public MuleEvent sendEvent(MuleEvent event) throws MuleException
 494  
     {
 495  0
         return messageProcessorChain.process(event);
 496  
     }
 497  
 
 498  
     /**
 499  
      * @return the Mule descriptor name which is associated with the service
 500  
      */
 501  
     public String getName()
 502  
     {
 503  0
         return name;
 504  
     }
 505  
 
 506  
     @Override
 507  
     public String toString()
 508  
     {
 509  0
         return String.format("%s{%s}", ClassUtils.getSimpleName(this.getClass()), getName());
 510  
     }
 511  
 
 512  
 
 513  
     // /////////////////////////////////////////////////////////////////////////////////////////
 514  
     // Getters and Setters
 515  
     // /////////////////////////////////////////////////////////////////////////////////////////
 516  
 
 517  
     public Model getModel()
 518  
     {
 519  0
         return model;
 520  
     }
 521  
 
 522  
     public void setModel(Model model)
 523  
     {
 524  0
         this.model = model;
 525  0
     }
 526  
 
 527  
     public MessagingExceptionHandler getExceptionListener()
 528  
     {
 529  0
         return exceptionListener;
 530  
     }
 531  
 
 532  
     public void setExceptionListener(MessagingExceptionHandler exceptionListener)
 533  
     {
 534  0
         this.exceptionListener = exceptionListener;
 535  0
     }
 536  
 
 537  
     public MessageSource getMessageSource()
 538  
     {
 539  0
         return messageSource;
 540  
     }
 541  
 
 542  
     public void setMessageSource(MessageSource inboundMessageSource)
 543  
     {
 544  0
         this.messageSource = inboundMessageSource;
 545  0
     }
 546  
 
 547  
     public MessageProcessor getOutboundMessageProcessor()
 548  
     {
 549  0
         return outboundRouter;
 550  
     }
 551  
 
 552  
     // TODO Use spring factory bean
 553  
     @Deprecated
 554  
     public void setMessageProcessor(MessageProcessor processor)
 555  
     {
 556  0
         setOutboundMessageProcessor(processor);
 557  0
     }
 558  
     
 559  
     public void setOutboundMessageProcessor(MessageProcessor processor)
 560  
     {
 561  0
         this.outboundRouter = processor;
 562  0
     }
 563  
 
 564  
     public ServiceAsyncReplyCompositeMessageSource getAsyncReplyMessageSource()
 565  
     {
 566  0
         return asyncReplyMessageSource;
 567  
     }
 568  
 
 569  
     public void setAsyncReplyMessageSource(ServiceAsyncReplyCompositeMessageSource asyncReplyMessageSource)
 570  
     {
 571  0
         this.asyncReplyMessageSource = asyncReplyMessageSource;
 572  0
     }
 573  
 
 574  
     public String getInitialState()
 575  
     {
 576  0
         return initialState;
 577  
     }
 578  
 
 579  
     public void setInitialState(String initialState)
 580  
     {
 581  0
         this.initialState = initialState;
 582  0
     }
 583  
 
 584  
     public void setName(String name)
 585  
     {
 586  0
         this.name = name;
 587  0
     }
 588  
 
 589  
     public Component getComponent()
 590  
     {
 591  0
         return component;
 592  
     }
 593  
 
 594  
     public void setComponent(Component component)
 595  
     {
 596  0
         this.component = component;
 597  0
         this.component.setFlowConstruct(this);
 598  0
         if (component instanceof MuleContextAware)
 599  
         {
 600  0
             ((MuleContextAware) component).setMuleContext(muleContext);
 601  
 
 602  
         }
 603  0
     }
 604  
 
 605  
     public MuleContext getMuleContext()
 606  
     {
 607  0
         return muleContext;
 608  
     }
 609  
 
 610  
     public LifecycleManager getLifecycleManager()
 611  
     {
 612  0
         return lifecycleManager;
 613  
     }
 614  
     
 615  
     public MessageInfoMapping getMessageInfoMapping()
 616  
     {
 617  0
         return messageInfoMapping;
 618  
     }
 619  
 
 620  
     public void setMessageInfoMapping(MessageInfoMapping messageInfoMapping)
 621  
     {
 622  0
         this.messageInfoMapping = messageInfoMapping;
 623  0
     }
 624  
 
 625  
     protected long getAsyncReplyTimeout()
 626  
     {
 627  0
         if (asyncReplyMessageSource.getTimeout() != null)
 628  
         {
 629  0
             return asyncReplyMessageSource.getTimeout().longValue();
 630  
         }
 631  
         else
 632  
         {
 633  0
             return muleContext.getConfiguration().getDefaultResponseTimeout();
 634  
         }
 635  
     }
 636  
 
 637  
     protected ServiceAsyncRequestReplyRequestor createAsyncReplyProcessor()
 638  
     {
 639  0
         ServiceAsyncRequestReplyRequestor asyncReplyMessageProcessor = new ServiceAsyncRequestReplyRequestor();
 640  0
         asyncReplyMessageProcessor.setTimeout(getAsyncReplyTimeout());
 641  0
         asyncReplyMessageProcessor.setFailOnTimeout(asyncReplyMessageSource.isFailOnTimeout());
 642  0
         asyncReplyMessageProcessor.setReplySource(asyncReplyMessageSource);
 643  0
         return asyncReplyMessageProcessor;
 644  
     }
 645  
     
 646  
     public MuleEvent process(MuleEvent event) throws MuleException
 647  
     {
 648  0
         MuleSession calledSession = new DefaultMuleSession(event.getSession(), this);
 649  0
         MuleEvent newEvent = new DefaultMuleEvent(event.getMessage(), event.getEndpoint(), event,
 650  
             calledSession);
 651  0
         RequestContext.setEvent(newEvent);
 652  
         try
 653  
         {
 654  0
             MuleEvent result = messageProcessorChain.process(newEvent);
 655  0
             if (result != null)
 656  
             {
 657  0
                 result.getMessage().release();
 658  
             }
 659  0
             return result;
 660  
         }
 661  0
         catch (Exception e)
 662  
         {
 663  0
             return getExceptionListener().handleException(e, newEvent);
 664  
         }
 665  
         finally
 666  
         {
 667  0
             RequestContext.setEvent(event);
 668  0
             event.getMessage().release();
 669  
         }
 670  
     }
 671  
 
 672  
     public MessageProcessorChain getMessageProcessorChain()
 673  
     {
 674  0
         return messageProcessorChain;
 675  
     }
 676  
     
 677  
     protected void injectFlowConstructMuleContext(Object candidate)
 678  
     {
 679  0
         if (candidate instanceof FlowConstructAware)
 680  
         {
 681  0
             ((FlowConstructAware) candidate).setFlowConstruct(this);
 682  
         }
 683  0
         if (candidate instanceof MuleContextAware)
 684  
         {
 685  0
             ((MuleContextAware) candidate).setMuleContext(muleContext);
 686  
         }
 687  0
     }
 688  
 
 689  
     protected void initialiseIfInitialisable(Object candidate) throws InitialisationException
 690  
     {
 691  0
         if (candidate instanceof Initialisable)
 692  
         {
 693  0
             ((Initialisable) candidate).initialise();
 694  
         }
 695  0
     }
 696  
 
 697  
     protected void startIfStartable(Object candidate) throws MuleException
 698  
     {
 699  0
         if (candidate instanceof Startable)
 700  
         {
 701  0
             ((Startable) candidate).start();
 702  
         }
 703  0
     }
 704  
 
 705  
     protected void stopIfStoppable(Object candidate) throws MuleException
 706  
     {
 707  0
         if (candidate instanceof Stoppable)
 708  
         {
 709  0
             ((Stoppable) candidate).stop();
 710  
         }
 711  0
     }
 712  
 
 713  
     protected void disposeIfDisposable(Object candidate)
 714  
     {
 715  0
         if (candidate instanceof Disposable)
 716  
         {
 717  0
             ((Disposable) candidate).dispose();
 718  
         }
 719  0
     }
 720  
 
 721  
     protected void pauseIfPausable(Object candidate) throws MuleException
 722  
     {
 723  0
         if (candidate instanceof Pausable)
 724  
         {
 725  0
             ((Pausable) candidate).pause();
 726  
         }
 727  0
     }
 728  
 
 729  
     protected void resumeIfResumable(Object candidate) throws MuleException
 730  
     {
 731  0
         if (candidate instanceof Resumable)
 732  
         {
 733  0
             ((Resumable) candidate).resume();
 734  
         }
 735  0
     }
 736  
 }