Coverage Report - org.mule.routing.response.AbstractResponseAggregator
 
Classes in this File Line Coverage Branch Coverage Complexity
AbstractResponseAggregator
0%
0/21
0%
0/2
1.1
 
 1  
 /*
 2  
  * $Id: AbstractResponseAggregator.java 11567 2008-04-11 13:08:05Z dirk.olmes $
 3  
  * --------------------------------------------------------------------------------------
 4  
  * Copyright (c) MuleSource, Inc.  All rights reserved.  http://www.mulesource.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.response;
 12  
 
 13  
 import org.mule.api.MuleEvent;
 14  
 import org.mule.api.MuleMessage;
 15  
 import org.mule.api.lifecycle.InitialisationException;
 16  
 import org.mule.api.routing.RoutingException;
 17  
 import org.mule.routing.EventCorrelator;
 18  
 import org.mule.routing.EventCorrelatorCallback;
 19  
 import org.mule.routing.inbound.AbstractEventAggregator;
 20  
 import org.mule.routing.inbound.EventGroup;
 21  
 
 22  
 /**
 23  
  * <code>AbstractResponseAggregator</code> provides a base class for implementing
 24  
  * response aggregator routers. This provides a thread-safe implemenetation and
 25  
  * allows developers to customise how and when events are grouped and collated.
 26  
  * Response Agrregators are used to collect responses that are usually sent to
 27  
  * replyTo endpoints set on outbound routers. When an event is sent out via an
 28  
  * outbound router, the response router will block the response flow on an
 29  
  * Service until the Response Router resolves a reply or times out.
 30  
  */
 31  0
 public abstract class AbstractResponseAggregator extends AbstractResponseRouter
 32  
 {
 33  0
     private int timeout = -1; // undefined
 34  
 
 35  0
     private boolean failOnTimeout = true;
 36  
 
 37  
     private EventCorrelator eventCorrelator;
 38  
 
 39  
     //@Override
 40  
     public void initialise() throws InitialisationException
 41  
     {
 42  0
         if (timeout == -1) // undefined
 43  
         {
 44  0
             setTimeout(muleContext.getConfiguration().getDefaultSynchronousEventTimeout());
 45  
         }
 46  0
         eventCorrelator = new EventCorrelator(getCorrelatorCallback(), messageInfoMapping, muleContext);
 47  0
         eventCorrelator.setTimeout(getTimeout());
 48  0
         eventCorrelator.setFailOnTimeout(isFailOnTimeout());
 49  0
         super.initialise();
 50  0
     }
 51  
 
 52  
     protected EventCorrelator getEventCorrelator()
 53  
     {
 54  0
         return eventCorrelator;
 55  
     }
 56  
 
 57  
 
 58  
     public void process(MuleEvent event) throws RoutingException
 59  
     {
 60  0
         eventCorrelator.addEvent(event);
 61  0
     }
 62  
 
 63  
     /**
 64  
      * This method is called by the responding callee thread and should return the
 65  
      * aggregated response message
 66  
      *
 67  
      * @param message
 68  
      * @return
 69  
      * @throws RoutingException
 70  
      */
 71  
     public MuleMessage getResponse(MuleMessage message) throws RoutingException
 72  
     {
 73  0
         return eventCorrelator.getResponse(message);
 74  
     }
 75  
 
 76  
 
 77  
     public boolean isFailOnTimeout()
 78  
     {
 79  0
         return failOnTimeout;
 80  
     }
 81  
 
 82  
     public void setFailOnTimeout(boolean failOnTimeout)
 83  
     {
 84  0
         this.failOnTimeout = failOnTimeout;
 85  0
     }
 86  
 
 87  
     public int getTimeout()
 88  
     {
 89  0
         return timeout;
 90  
     }
 91  
 
 92  
     public void setTimeout(int timeout)
 93  
     {
 94  0
         this.timeout = timeout;
 95  0
     }
 96  
 
 97  
     protected abstract EventCorrelatorCallback getCorrelatorCallback();
 98  
 
 99  
     /**
 100  
      * @see AbstractEventAggregator#aggregateEvents(EventGroup)
 101  
      */
 102  
     protected MuleMessage aggregateEvents(EventGroup events) throws RoutingException
 103  
     {
 104  0
         return null;
 105  
     }
 106  
 
 107  
 }