Coverage Report - org.mule.routing.AbstractRouterCollection
 
Classes in this File Line Coverage Branch Coverage Complexity
AbstractRouterCollection
67%
24/36
50%
5/10
1.357
 
 1  
 /*
 2  
  * $Id: AbstractRouterCollection.java 12269 2008-07-10 04:19:03Z dfeist $
 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;
 12  
 
 13  
 import org.mule.api.MuleContext;
 14  
 import org.mule.api.context.MuleContextAware;
 15  
 import org.mule.api.lifecycle.InitialisationException;
 16  
 import org.mule.api.lifecycle.LifecycleTransitionResult;
 17  
 import org.mule.api.routing.Router;
 18  
 import org.mule.api.routing.RouterCatchAllStrategy;
 19  
 import org.mule.api.routing.RouterCollection;
 20  
 import org.mule.management.stats.RouterStatistics;
 21  
 
 22  
 import java.util.Iterator;
 23  
 import java.util.List;
 24  
 
 25  
 import edu.emory.mathcs.backport.java.util.concurrent.CopyOnWriteArrayList;
 26  
 
 27  
 import org.apache.commons.logging.Log;
 28  
 import org.apache.commons.logging.LogFactory;
 29  
 
 30  
 /**
 31  
  * <code>AbstractRouterCollection</code> provides common method implementations of
 32  
  * router collections for in and outbound routers.
 33  
  */
 34  
 
 35  
 public abstract class AbstractRouterCollection implements RouterCollection, MuleContextAware
 36  
 {
 37  
     /**
 38  
      * logger used by this class
 39  
      */
 40  2124
     protected final transient Log logger = LogFactory.getLog(getClass());
 41  
 
 42  2124
     protected boolean matchAll = false;
 43  
 
 44  2124
     protected List routers = new CopyOnWriteArrayList();
 45  
 
 46  
     private RouterStatistics statistics;
 47  
 
 48  
     private RouterCatchAllStrategy catchAllStrategy;
 49  
     
 50  
     protected MuleContext muleContext;
 51  
 
 52  
     public AbstractRouterCollection(int type)
 53  2124
     {
 54  2124
         statistics = new RouterStatistics(type);
 55  2124
     }
 56  
 
 57  
     public void initialise() throws InitialisationException
 58  
     {
 59  0
         LifecycleTransitionResult.initialiseAll(routers.iterator());
 60  0
     }
 61  
 
 62  
     public void dispose()
 63  
     {
 64  0
         for (Iterator iterator = routers.iterator(); iterator.hasNext();)
 65  
         {
 66  0
             Router router = (Router) iterator.next();
 67  0
             router.dispose();
 68  0
         }
 69  0
     }
 70  
 
 71  
     public void setRouters(List routers)
 72  
     {
 73  2
         for (Iterator iterator = routers.iterator(); iterator.hasNext();)
 74  
         {
 75  4
             addRouter((Router) iterator.next());
 76  
         }
 77  2
     }
 78  
 
 79  
     public void addRouter(Router router)
 80  
     {
 81  400
         router.setRouterStatistics(getStatistics());
 82  400
         routers.add(router);
 83  400
     }
 84  
 
 85  
     public Router removeRouter(Router router)
 86  
     {
 87  2
         if (routers.remove(router))
 88  
         {
 89  2
             return router;
 90  
         }
 91  
         else
 92  
         {
 93  0
             return null;
 94  
         }
 95  
     }
 96  
 
 97  
     public List getRouters()
 98  
     {
 99  118
         return routers;
 100  
     }
 101  
 
 102  
     public RouterCatchAllStrategy getCatchAllStrategy()
 103  
     {
 104  22
         return catchAllStrategy;
 105  
     }
 106  
 
 107  
     public void setCatchAllStrategy(RouterCatchAllStrategy catchAllStrategy)
 108  
     {
 109  26
         this.catchAllStrategy = catchAllStrategy;
 110  26
         if (this.catchAllStrategy != null && catchAllStrategy instanceof AbstractCatchAllStrategy)
 111  
         {
 112  26
             ((AbstractCatchAllStrategy) this.catchAllStrategy).setStatistics(statistics);
 113  
         }
 114  26
     }
 115  
 
 116  
     public boolean isMatchAll()
 117  
     {
 118  28
         return matchAll;
 119  
     }
 120  
 
 121  
     public void setMatchAll(boolean matchAll)
 122  
     {
 123  430
         this.matchAll = matchAll;
 124  430
     }
 125  
 
 126  
     public RouterStatistics getStatistics()
 127  
     {
 128  1224
         return statistics;
 129  
     }
 130  
 
 131  
     public void setStatistics(RouterStatistics stat)
 132  
     {
 133  0
         this.statistics = stat;
 134  0
     }
 135  
 
 136  
     public void setMuleContext(MuleContext context)
 137  
     {
 138  0
         this.muleContext = context;
 139  0
     }
 140  
 }