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 | 0 | protected final transient Log logger = LogFactory.getLog(getClass()); |
36 | |
|
37 | 0 | protected boolean matchAll = false; |
38 | |
|
39 | 0 | protected List routers = new CopyOnWriteArrayList(); |
40 | |
|
41 | |
private RouterStatistics statistics; |
42 | |
|
43 | |
private UMORouterCatchAllStrategy catchAllStrategy; |
44 | |
|
45 | |
public AbstractRouterCollection(int type) |
46 | 0 | { |
47 | 0 | statistics = new RouterStatistics(type); |
48 | 0 | } |
49 | |
|
50 | |
public void setRouters(List routers) |
51 | |
{ |
52 | 0 | for (Iterator iterator = routers.iterator(); iterator.hasNext();) |
53 | |
{ |
54 | 0 | addRouter((UMORouter) iterator.next()); |
55 | |
} |
56 | 0 | } |
57 | |
|
58 | |
public void addRouter(UMORouter router) |
59 | |
{ |
60 | 0 | router.setRouterStatistics(getStatistics()); |
61 | 0 | routers.add(router); |
62 | 0 | } |
63 | |
|
64 | |
public UMORouter removeRouter(UMORouter router) |
65 | |
{ |
66 | 0 | if (routers.remove(router)) |
67 | |
{ |
68 | 0 | return router; |
69 | |
} |
70 | |
else |
71 | |
{ |
72 | 0 | return null; |
73 | |
} |
74 | |
} |
75 | |
|
76 | |
public List getRouters() |
77 | |
{ |
78 | 0 | return routers; |
79 | |
} |
80 | |
|
81 | |
public UMORouterCatchAllStrategy getCatchAllStrategy() |
82 | |
{ |
83 | 0 | return catchAllStrategy; |
84 | |
} |
85 | |
|
86 | |
public void setCatchAllStrategy(UMORouterCatchAllStrategy catchAllStrategy) |
87 | |
{ |
88 | 0 | this.catchAllStrategy = catchAllStrategy; |
89 | 0 | if (this.catchAllStrategy != null && catchAllStrategy instanceof AbstractCatchAllStrategy) |
90 | |
{ |
91 | 0 | ((AbstractCatchAllStrategy) this.catchAllStrategy).setStatistics(statistics); |
92 | |
} |
93 | 0 | } |
94 | |
|
95 | |
public boolean isMatchAll() |
96 | |
{ |
97 | 0 | return matchAll; |
98 | |
} |
99 | |
|
100 | |
public void setMatchAll(boolean matchAll) |
101 | |
{ |
102 | 0 | this.matchAll = matchAll; |
103 | 0 | } |
104 | |
|
105 | |
public RouterStatistics getStatistics() |
106 | |
{ |
107 | 0 | return statistics; |
108 | |
} |
109 | |
|
110 | |
public void setStatistics(RouterStatistics stat) |
111 | |
{ |
112 | 0 | this.statistics = stat; |
113 | 0 | } |
114 | |
} |