View Javadoc
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.lifecycle.processor;
8   
9   import org.mule.api.MessagingException;
10  import org.mule.api.MuleEvent;
11  import org.mule.api.MuleException;
12  import org.mule.api.lifecycle.LifecycleState;
13  import org.mule.api.lifecycle.Startable;
14  import org.mule.config.i18n.CoreMessages;
15  
16  public class ProcessIfStartedWaitIfSyncPausedMessageProcessor extends
17      ProcessIfStartedWaitIfPausedMessageProcessor
18  {
19  
20      public ProcessIfStartedWaitIfSyncPausedMessageProcessor(Startable startable, LifecycleState lifecycleState)
21      {
22          super(startable, lifecycleState);
23      }
24  
25      // TODO DF This needs refactoring. This is to ensure processNext()
26      // is used and not next.process()
27      @Override
28      public MuleEvent process(MuleEvent event) throws MuleException
29      {
30          if (accept(event))
31          {
32              if (isPaused() && event.getEndpoint().getExchangePattern().hasResponse())
33              {
34                  try
35                  {
36                      if (logger.isDebugEnabled())
37                      {
38                          logger.debug(startable.getClass().getName() + " " + getStartableName(startable)
39                                       + " is paused. Blocking call until resumd");
40                      }
41                      while (isPaused())
42                      {
43                          Thread.sleep(500);
44                      }
45                  }
46                  catch (InterruptedException e)
47                  {
48                      throw new MessagingException(
49                          CoreMessages.interruptedWaitingForPaused(getStartableName(startable)), event, e);
50                  }
51              }
52              return processNext(event);
53          }
54          else
55          {
56              return handleUnaccepted(event);
57          }
58      }
59  }