Coverage Report - org.mule.routing.AbstractAggregator
 
Classes in this File Line Coverage Branch Coverage Complexity
AbstractAggregator
0%
0/36
0%
0/10
1.462
 
 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.routing;
 8  
 
 9  
 import org.mule.api.MuleContext;
 10  
 import org.mule.api.MuleEvent;
 11  
 import org.mule.api.MuleException;
 12  
 import org.mule.api.construct.FlowConstruct;
 13  
 import org.mule.api.construct.FlowConstructAware;
 14  
 import org.mule.api.context.MuleContextAware;
 15  
 import org.mule.api.lifecycle.Initialisable;
 16  
 import org.mule.api.lifecycle.InitialisationException;
 17  
 import org.mule.api.lifecycle.Startable;
 18  
 import org.mule.api.lifecycle.Stoppable;
 19  
 import org.mule.api.routing.Aggregator;
 20  
 import org.mule.api.routing.MessageInfoMapping;
 21  
 import org.mule.api.service.Service;
 22  
 import org.mule.processor.AbstractInterceptingMessageProcessor;
 23  
 import org.mule.routing.correlation.EventCorrelator;
 24  
 import org.mule.routing.correlation.EventCorrelatorCallback;
 25  
 
 26  
 /**
 27  
  * <code>AbstractEventAggregator</code> will aggregate a set of messages into a
 28  
  * single message.
 29  
  *
 30  
  * <b>EIP Reference:</b> <a href="http://www.eaipatterns.com/Aggregator.html">http://www.eaipatterns.com/Aggregator.html</a>
 31  
  */
 32  
 
 33  0
 public abstract class AbstractAggregator extends AbstractInterceptingMessageProcessor
 34  
         implements Initialisable, MuleContextAware, FlowConstructAware, Aggregator, Startable, Stoppable
 35  
 {
 36  
 
 37  
     protected EventCorrelator eventCorrelator;
 38  
     protected MuleContext muleContext;
 39  
     protected FlowConstruct flowConstruct;
 40  
     protected MessageInfoMapping messageInfoMapping;
 41  
 
 42  0
     private long timeout = 0;
 43  0
     private boolean failOnTimeout = true;
 44  
 
 45  
     public void initialise() throws InitialisationException
 46  
     {
 47  0
         if (messageInfoMapping == null)
 48  
         {
 49  0
             messageInfoMapping = flowConstruct.getMessageInfoMapping();
 50  
         }
 51  
 
 52  0
         eventCorrelator = new EventCorrelator(getCorrelatorCallback(muleContext), next, messageInfoMapping,
 53  
                                               muleContext, flowConstruct.getName());
 54  
 
 55  
         // Inherit failOnTimeout from async-reply if this aggregator is being used for async-reply
 56  0
         if (flowConstruct instanceof Service)
 57  
         {
 58  0
             Service service = (Service) flowConstruct;
 59  0
             if (service.getAsyncReplyMessageSource().getMessageProcessors().contains(this))
 60  
             {
 61  0
                 failOnTimeout = service.getAsyncReplyMessageSource().isFailOnTimeout();
 62  
             }
 63  
         }
 64  
 
 65  0
         eventCorrelator.setTimeout(timeout);
 66  0
         eventCorrelator.setFailOnTimeout(isFailOnTimeout());
 67  0
     }
 68  
 
 69  
     public void start() throws MuleException 
 70  
     {
 71  0
         if (timeout != 0)
 72  
         {
 73  0
             eventCorrelator.start();
 74  
         }
 75  0
     }
 76  
 
 77  
     public void stop() throws MuleException
 78  
     {
 79  0
         eventCorrelator.stop();
 80  0
     }
 81  
 
 82  
     public void setMuleContext(MuleContext context)
 83  
     {
 84  0
         this.muleContext = context;
 85  0
     }
 86  
 
 87  
     protected abstract EventCorrelatorCallback getCorrelatorCallback(MuleContext muleContext);
 88  
 
 89  
     public MuleEvent process(MuleEvent event) throws MuleException
 90  
     {
 91  0
         MuleEvent result = eventCorrelator.process(event);
 92  0
         if (result == null)
 93  
         {
 94  0
             return null;
 95  
         }
 96  0
         return processNext(result);
 97  
     }
 98  
 
 99  
     public void expireAggregation(String groupId)
 100  
     {
 101  0
         eventCorrelator.forceGroupExpiry(groupId);
 102  0
     }
 103  
 
 104  
     public long getTimeout()
 105  
     {
 106  0
         return timeout;
 107  
     }
 108  
 
 109  
     public void setTimeout(long timeout)
 110  
     {
 111  0
         this.timeout = timeout;
 112  0
     }
 113  
 
 114  
     public boolean isFailOnTimeout()
 115  
     {
 116  0
         return failOnTimeout;
 117  
     }
 118  
 
 119  
     public void setFailOnTimeout(boolean failOnTimeout)
 120  
     {
 121  0
         this.failOnTimeout = failOnTimeout;
 122  0
     }
 123  
 
 124  
     public void setFlowConstruct(FlowConstruct flowConstruct)
 125  
     {
 126  0
         this.flowConstruct = flowConstruct;
 127  0
     }
 128  
 
 129  
     public void setMessageInfoMapping(MessageInfoMapping messageInfoMapping)
 130  
     {
 131  0
         this.messageInfoMapping = messageInfoMapping;
 132  0
     }
 133  
 }