KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > geronimo > clustering > wadi > TribesDispatcherHolder


1 /**
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17 package org.apache.geronimo.clustering.wadi;
18
19 import java.net.URI JavaDoc;
20
21 import org.apache.commons.logging.Log;
22 import org.apache.commons.logging.LogFactory;
23 import org.apache.geronimo.clustering.Node;
24 import org.apache.geronimo.gbean.GBeanInfo;
25 import org.apache.geronimo.gbean.GBeanInfoBuilder;
26 import org.apache.geronimo.gbean.GBeanLifecycle;
27 import org.apache.geronimo.j2ee.j2eeobjectnames.NameFactory;
28 import org.codehaus.wadi.group.Dispatcher;
29 import org.codehaus.wadi.group.MessageExchangeException;
30 import org.codehaus.wadi.tribes.TribesDispatcher;
31 import org.codehaus.wadi.web.impl.URIEndPoint;
32
33 /**
34  *
35  * @version $Rev$ $Date$
36  */

37 public class TribesDispatcherHolder implements GBeanLifecycle, DispatcherHolder {
38     private static final Log log = LogFactory.getLog(TribesDispatcherHolder.class);
39     
40     private final URI JavaDoc endPointURI;
41     private final String JavaDoc clusterName;
42     private final long inactiveTime;
43     private final Node node;
44
45     private TribesDispatcher dispatcher;
46
47
48     public TribesDispatcherHolder(URI JavaDoc endPointURI, String JavaDoc clusterName, long inactiveTime, Node node) {
49         if (null == endPointURI) {
50             throw new IllegalArgumentException JavaDoc("endPointURI is required");
51         } else if (null == clusterName) {
52             throw new IllegalArgumentException JavaDoc("clusterName is required");
53         } else if (0 > inactiveTime) {
54             throw new IllegalArgumentException JavaDoc("inactiveTime must be > 0");
55         } else if (null == node) {
56             throw new IllegalArgumentException JavaDoc("node is required");
57         }
58         this.endPointURI = endPointURI;
59         this.clusterName = clusterName;
60         this.inactiveTime = inactiveTime;
61         this.node = node;
62     }
63
64     public void doStart() throws Exception JavaDoc {
65         dispatcher = new TribesDispatcher(clusterName, node.getName(), new URIEndPoint(endPointURI), inactiveTime, null);
66         dispatcher.start();
67     }
68
69     public void doStop() throws Exception JavaDoc {
70         dispatcher.stop();
71     }
72
73     public void doFail() {
74         try {
75             dispatcher.stop();
76         } catch (MessageExchangeException e) {
77             log.error(e);
78         }
79     }
80     
81     public Dispatcher getDispatcher() {
82         return dispatcher;
83     }
84
85     public Node getNode() {
86         return node;
87     }
88     
89     
90     public static final GBeanInfo GBEAN_INFO;
91     
92     public static final String JavaDoc GBEAN_ATTR_END_POINT_URI = "endPointURI";
93     public static final String JavaDoc GBEAN_ATTR_CLUSTER_NAME = "clusterName";
94     public static final String JavaDoc GBEAN_ATTR_CLUSTER_URI = "clusterUri";
95     public static final String JavaDoc GBEAN_ATTR_INACTIVE_TIME = "inactiveTime";
96
97     public static final String JavaDoc GBEAN_REF_NODE = "Node";
98
99     static {
100         GBeanInfoBuilder infoBuilder = GBeanInfoBuilder.createStatic(TribesDispatcherHolder.class,
101                 NameFactory.GERONIMO_SERVICE);
102         
103         infoBuilder.addAttribute(GBEAN_ATTR_END_POINT_URI, URI JavaDoc.class, true);
104         infoBuilder.addAttribute(GBEAN_ATTR_CLUSTER_NAME, String JavaDoc.class, true);
105         infoBuilder.addAttribute(GBEAN_ATTR_INACTIVE_TIME, long.class, true);
106         
107         infoBuilder.addReference(GBEAN_REF_NODE, Node.class, NameFactory.GERONIMO_SERVICE);
108
109         infoBuilder.addInterface(DispatcherHolder.class);
110         
111         infoBuilder.setConstructor(new String JavaDoc[] {
112                 GBEAN_ATTR_END_POINT_URI,
113                 GBEAN_ATTR_CLUSTER_NAME,
114                 GBEAN_ATTR_INACTIVE_TIME,
115                 GBEAN_REF_NODE });
116         
117         GBEAN_INFO = infoBuilder.getBeanInfo();
118     }
119
120     public static GBeanInfo getGBeanInfo() {
121         return GBEAN_INFO;
122     }
123 }
124
Popular Tags