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