Coverage Report - org.mule.lifecycle.processor.ProcessIfStartedMessageProcessor
 
Classes in this File Line Coverage Branch Coverage Complexity
ProcessIfStartedMessageProcessor
0%
0/9
0%
0/2
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.MuleEvent;
 10  
 import org.mule.api.NamedObject;
 11  
 import org.mule.api.lifecycle.LifecycleException;
 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.processor.AbstractFilteringMessageProcessor;
 16  
 
 17  
 public class ProcessIfStartedMessageProcessor extends AbstractFilteringMessageProcessor
 18  
 {
 19  
 
 20  
     protected Startable startable;
 21  
     protected LifecycleState lifecycleState;
 22  
 
 23  
     public ProcessIfStartedMessageProcessor(Startable startable, LifecycleState lifecycleState)
 24  0
     {
 25  0
         this.startable = startable;
 26  0
         this.lifecycleState = lifecycleState;
 27  0
     }
 28  
 
 29  
     @Override
 30  
     protected boolean accept(MuleEvent event)
 31  
     {
 32  0
         return lifecycleState.isStarted();
 33  
     }
 34  
 
 35  
     @Override
 36  
     protected MuleEvent handleUnaccepted(MuleEvent event) throws LifecycleException
 37  
     {
 38  0
         throw new LifecycleException(CoreMessages.isStopped(getStartableName(startable)), event.getMessage());
 39  
     }
 40  
 
 41  
     protected String getStartableName(Startable startableObject)
 42  
     {
 43  0
         if (startableObject instanceof NamedObject)
 44  
         {
 45  0
             return ((NamedObject) startableObject).getName();
 46  
         }
 47  
         else
 48  
         {
 49  0
             return startableObject.toString();
 50  
         }
 51  
     }
 52  
 
 53  
 }