Coverage Report - org.mule.api.processor.policy.PolicyInvocation
 
Classes in this File Line Coverage Branch Coverage Complexity
PolicyInvocation
0%
0/20
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.api.processor.policy;
 8  
 
 9  
 import org.mule.api.MuleEvent;
 10  
 import org.mule.api.MuleException;
 11  
 import org.mule.api.processor.MessageProcessor;
 12  
 
 13  
 import java.util.LinkedList;
 14  
 import java.util.List;
 15  
 
 16  
 /**
 17  
  *
 18  
  */
 19  
 public class PolicyInvocation
 20  
 {
 21  
     private MuleEvent event;
 22  0
     private List<AroundPolicy> policies = new LinkedList<AroundPolicy>();
 23  0
     private volatile int currentPolicyIndex = 0;
 24  
     private MessageProcessor messageProcessor;
 25  
 
 26  
     public PolicyInvocation(MuleEvent event, List<AroundPolicy> policies, MessageProcessor processor)
 27  0
     {
 28  0
         this.event = event;
 29  0
         this.policies = policies;
 30  0
         this.messageProcessor = processor;
 31  0
     }
 32  
 
 33  
     /**
 34  
      * Proceed using the current event.
 35  
      *
 36  
      * @see #setEvent(org.mule.api.MuleEvent)
 37  
      */
 38  
     public MuleEvent proceed() throws MuleException
 39  
     {
 40  0
         currentPolicyIndex++;
 41  0
         if (currentPolicyIndex == policies.size())
 42  
         {
 43  
             // end of chain
 44  0
             return messageProcessor.process(event);
 45  
         }
 46  0
         final AroundPolicy currentPolicy = getCurrentPolicy();
 47  0
         final MuleEvent result = currentPolicy.invoke(this);
 48  0
         setEvent(result);
 49  0
         return event;
 50  
     }
 51  
 
 52  
     public MuleEvent getEvent()
 53  
     {
 54  0
         return event;
 55  
     }
 56  
 
 57  
     /**
 58  
      * Replace the event object completely. Note that most of the time it's enough to simply
 59  
      * modify the event without any rewriting.
 60  
      *
 61  
      * @see #getEvent()
 62  
      */
 63  
     public void setEvent(MuleEvent event)
 64  
     {
 65  0
         this.event = event;
 66  0
     }
 67  
 
 68  
     /**
 69  
      * @return policy at the current index in the list
 70  
      */
 71  
     public AroundPolicy getCurrentPolicy()
 72  
     {
 73  0
         return policies.get(currentPolicyIndex);
 74  
     }
 75  
 
 76  
     public MessageProcessor getMessageProcessor()
 77  
     {
 78  0
         return messageProcessor;
 79  
     }
 80  
 
 81  
     public List<AroundPolicy> getPolicies()
 82  
     {
 83  0
         return policies;
 84  
     }
 85  
 }