Coverage Report - org.mule.routing.AbstractAggregator
 
Classes in this File Line Coverage Branch Coverage Complexity
AbstractAggregator
0%
0/36
0%
0/10
1.727
 
 1  
 /*
 2  
  * $Id: AbstractAggregator.java 19948 2010-10-15 18:11:04Z dfeist $
 3  
  * --------------------------------------------------------------------------------------
 4  
  * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
 5  
  *
 6  
  * The software in this package is published under the terms of the CPAL v1.0
 7  
  * license, a copy of which has been included with this distribution in the
 8  
  * LICENSE.txt file.
 9  
  */
 10  
 
 11  
 package org.mule.routing;
 12  
 
 13  
 import org.mule.api.MuleContext;
 14  
 import org.mule.api.MuleEvent;
 15  
 import org.mule.api.MuleException;
 16  
 import org.mule.api.construct.FlowConstruct;
 17  
 import org.mule.api.construct.FlowConstructAware;
 18  
 import org.mule.api.context.MuleContextAware;
 19  
 import org.mule.api.lifecycle.Initialisable;
 20  
 import org.mule.api.lifecycle.InitialisationException;
 21  
 import org.mule.api.routing.Aggregator;
 22  
 import org.mule.api.routing.MessageInfoMapping;
 23  
 import org.mule.api.service.Service;
 24  
 import org.mule.processor.AbstractInterceptingMessageProcessor;
 25  
 import org.mule.routing.correlation.EventCorrelator;
 26  
 import org.mule.routing.correlation.EventCorrelatorCallback;
 27  
 
 28  
 import javax.resource.spi.work.WorkException;
 29  
 
 30  
 /**
 31  
  * <code>AbstractEventAggregator</code> will aggregate a set of messages into a
 32  
  * single message.
 33  
  * 
 34  
  * <b>EIP Reference:</b> <a href="http://www.eaipatterns.com/Aggregator.html">http://www.eaipatterns.com/Aggregator.html</a>
 35  
  */
 36  
 
 37  0
 public abstract class AbstractAggregator extends AbstractInterceptingMessageProcessor
 38  
     implements Initialisable, MuleContextAware, FlowConstructAware, Aggregator
 39  
 {
 40  
 
 41  
     protected EventCorrelator eventCorrelator;
 42  
     protected MuleContext muleContext;
 43  
     protected FlowConstruct flowConstruct;
 44  
     protected MessageInfoMapping messageInfoMapping;
 45  
 
 46  0
     private long timeout = 0;
 47  0
     private boolean failOnTimeout = true;
 48  
 
 49  
     public void initialise() throws InitialisationException
 50  
     {
 51  0
         if (messageInfoMapping == null)
 52  
         {
 53  0
             messageInfoMapping = flowConstruct.getMessageInfoMapping();
 54  
         }
 55  
 
 56  0
         eventCorrelator = new EventCorrelator(getCorrelatorCallback(muleContext), next, messageInfoMapping,
 57  
             muleContext);
 58  
 
 59  
         // Inherit failOnTimeout from async-reply if this aggregator is being used for async-reply
 60  0
         if (flowConstruct instanceof Service)
 61  
         {
 62  0
             Service service = (Service) flowConstruct;
 63  0
             if (service.getAsyncReplyMessageSource().getMessageProcessors().contains(this))
 64  
             {
 65  0
                 failOnTimeout = service.getAsyncReplyMessageSource().isFailOnTimeout();
 66  
             }
 67  
         }
 68  
         
 69  0
         eventCorrelator.setTimeout(timeout);
 70  0
         eventCorrelator.setFailOnTimeout(isFailOnTimeout());
 71  0
         if (timeout != 0)
 72  
         {
 73  
             try
 74  
             {
 75  0
                 eventCorrelator.enableTimeoutMonitor();
 76  
             }
 77  0
             catch (WorkException e)
 78  
             {
 79  0
                 throw new InitialisationException(e, this);
 80  0
             }
 81  
         }
 82  0
     }
 83  
 
 84  
     public void setMuleContext(MuleContext context)
 85  
     {
 86  0
         this.muleContext = context;
 87  0
     }
 88  
 
 89  
     protected abstract EventCorrelatorCallback getCorrelatorCallback(MuleContext muleContext);
 90  
 
 91  
     public MuleEvent process(MuleEvent event) throws MuleException
 92  
     {
 93  0
         MuleEvent result = eventCorrelator.process(event);
 94  0
         if (result == null)
 95  
         {
 96  0
             return null;
 97  
         }
 98  0
         return processNext(result);
 99  
     }
 100  
 
 101  
     public void expireAggregation(String groupId)
 102  
     {
 103  0
         eventCorrelator.forceGroupExpiry(groupId);
 104  0
     }
 105  
 
 106  
     public long getTimeout()
 107  
     {
 108  0
         return timeout;
 109  
     }
 110  
 
 111  
     public void setTimeout(long timeout)
 112  
     {
 113  0
         this.timeout = timeout;
 114  0
     }
 115  
 
 116  
     public boolean isFailOnTimeout()
 117  
     {
 118  0
         return failOnTimeout;
 119  
     }
 120  
 
 121  
     public void setFailOnTimeout(boolean failOnTimeout)
 122  
     {
 123  0
         this.failOnTimeout = failOnTimeout;
 124  0
     }
 125  
 
 126  
     public void setFlowConstruct(FlowConstruct flowConstruct)
 127  
     {
 128  0
         this.flowConstruct = flowConstruct;
 129  0
     }
 130  
 
 131  
     public void setMessageInfoMapping(MessageInfoMapping messageInfoMapping)
 132  
     {
 133  0
         this.messageInfoMapping = messageInfoMapping;
 134  0
     }
 135  
 }