Coverage Report - org.mule.lifecycle.processor.ProcessIfStartedWaitIfPausedMessageProcessor
 
Classes in this File Line Coverage Branch Coverage Complexity
ProcessIfStartedWaitIfPausedMessageProcessor
0%
0/15
0%
0/12
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.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  
 import org.mule.service.Pausable;
 16  
 
 17  
 public class ProcessIfStartedWaitIfPausedMessageProcessor extends ProcessIfStartedMessageProcessor
 18  
 {
 19  
 
 20  
     public ProcessIfStartedWaitIfPausedMessageProcessor(Startable startable, LifecycleState lifecycleState)
 21  
     {
 22  0
         super(startable, lifecycleState);
 23  0
     }
 24  
 
 25  
     @Override
 26  
     public MuleEvent process(MuleEvent event) throws MuleException
 27  
     {
 28  0
         if (accept(event))
 29  
         {
 30  0
             if (isPaused())
 31  
             {
 32  
                 try
 33  
                 {
 34  0
                     if (logger.isDebugEnabled())
 35  
                     {
 36  0
                         logger.debug(startable.getClass().getName() + " " + getStartableName(startable)
 37  
                                      + " is paused. Blocking call until resumd");
 38  
                     }
 39  0
                     while (isPaused())
 40  
                     {
 41  0
                         Thread.sleep(500);
 42  
                     }
 43  
                 }
 44  0
                 catch (InterruptedException e)
 45  
                 {
 46  0
                     throw new MessagingException(
 47  
                         CoreMessages.interruptedWaitingForPaused(getStartableName(startable)), event, e);
 48  0
                 }
 49  
             }
 50  0
             return processNext(event);
 51  
         }
 52  
         else
 53  
         {
 54  0
             return handleUnaccepted(event);
 55  
         }
 56  
     }
 57  
 
 58  
     @Override
 59  
     protected boolean accept(MuleEvent event)
 60  
     {
 61  0
         return lifecycleState.isStarted() || isPaused();
 62  
     }
 63  
 
 64  
     protected boolean isPaused()
 65  
     {
 66  0
         return lifecycleState.isPhaseComplete(Pausable.PHASE_NAME);
 67  
     }
 68  
 
 69  
 }