KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mule > routing > AbstractRouterCollection


1 /*
2  * $Id: AbstractRouterCollection.java 3798 2006-11-04 04:07:14Z aperepel $
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 MuleSource MPL
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 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 JavaDoc;
21 import java.util.List JavaDoc;
22
23 /**
24  * <code>AbstractRouterCollection</code> provides common method implementations of
25  * router collections for in and outbound routers.
26  *
27  * @author <a HREF="mailto:ross.mason@symphonysoft.com">Ross Mason </a>
28  * @version $Revision: 3798 $
29  */

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 JavaDoc 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