1 10 11 package org.mule.routing; 12 13 import edu.emory.mathcs.backport.java.util.concurrent.CopyOnWriteArrayList; 14 15 import org.mule.management.stats.RouterStatistics; 16 import org.mule.umo.routing.UMORouter; 17 import org.mule.umo.routing.UMORouterCatchAllStrategy; 18 import org.mule.umo.routing.UMORouterCollection; 19 20 import java.util.Iterator ; 21 import java.util.List ; 22 23 30 31 public abstract class AbstractRouterCollection implements UMORouterCollection 32 { 33 protected boolean matchAll = false; 34 35 protected List routers = new CopyOnWriteArrayList(); 36 37 private RouterStatistics statistics; 38 39 private UMORouterCatchAllStrategy catchAllStrategy; 40 41 public AbstractRouterCollection(int type) 42 { 43 statistics = new RouterStatistics(type); 44 } 45 46 public void setRouters(List routers) 47 { 48 for (Iterator iterator = routers.iterator(); iterator.hasNext();) 49 { 50 addRouter((UMORouter)iterator.next()); 51 } 52 } 53 54 public void addRouter(UMORouter router) 55 { 56 router.setRouterStatistics(getStatistics()); 57 routers.add(router); 58 } 59 60 public UMORouter removeRouter(UMORouter router) 61 { 62 if (routers.remove(router)) 63 { 64 return router; 65 } 66 else 67 { 68 return null; 69 } 70 } 71 72 public List getRouters() 73 { 74 return routers; 75 } 76 77 public UMORouterCatchAllStrategy getCatchAllStrategy() 78 { 79 return catchAllStrategy; 80 } 81 82 public void setCatchAllStrategy(UMORouterCatchAllStrategy catchAllStrategy) 83 { 84 this.catchAllStrategy = catchAllStrategy; 85 if (this.catchAllStrategy != null && catchAllStrategy instanceof AbstractCatchAllStrategy) 86 { 87 ((AbstractCatchAllStrategy)this.catchAllStrategy).setStatistics(statistics); 88 } 89 } 90 91 public boolean isMatchAll() 92 { 93 return matchAll; 94 } 95 96 public void setMatchAll(boolean matchAll) 97 { 98 this.matchAll = matchAll; 99 } 100 101 public RouterStatistics getStatistics() 102 { 103 return statistics; 104 } 105 106 public void setStatistics(RouterStatistics stat) 107 { 108 this.statistics = stat; 109 } 110 } 111 | Popular Tags |