1 /**
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one or more
4 * contributor license agreements. See the NOTICE file distributed with
5 * this work for additional information regarding copyright ownership.
6 * The ASF licenses this file to You under the Apache License, Version 2.0
7 * (the "License"); you may not use this file except in compliance with
8 * the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 */
18 package org.apache.geronimo.clustering.wadi;
19
20 import org.apache.commons.logging.Log;
21 import org.apache.commons.logging.LogFactory;
22 import org.apache.geronimo.clustering.Node;
23 import org.apache.geronimo.gbean.GBeanInfo;
24 import org.apache.geronimo.gbean.GBeanInfoBuilder;
25 import org.apache.geronimo.gbean.GBeanLifecycle;
26 import org.apache.geronimo.j2ee.j2eeobjectnames.NameFactory;
27 import org.codehaus.wadi.group.Dispatcher;
28 import org.codehaus.wadi.group.MessageExchangeException;
29 import org.codehaus.wadi.tribes.TribesDispatcher;
30
31 /**
32 *
33 * @version $Rev$ $Date$
34 */
35 public class TribesDispatcherHolder implements GBeanLifecycle, DispatcherHolder {
36 private static final Log log = LogFactory.getLog(TribesDispatcherHolder.class);
37
38 private final String clusterName;
39 private final long inactiveTime;
40 private final Node node;
41
42 private TribesDispatcher dispatcher;
43
44 public TribesDispatcherHolder(String clusterName, long inactiveTime, Node node) {
45 this.clusterName = clusterName;
46 this.inactiveTime = inactiveTime;
47 this.node = node;
48 }
49
50 public void doStart() throws Exception {
51 dispatcher = new TribesDispatcher(clusterName, node.getName(), inactiveTime, null);
52 dispatcher.start();
53 }
54
55 public void doStop() throws Exception {
56 dispatcher.stop();
57 }
58
59 public void doFail() {
60 try {
61 dispatcher.stop();
62 } catch (MessageExchangeException e) {
63 log.error(e);
64 }
65 }
66
67 public Dispatcher getDispatcher() {
68 return dispatcher;
69 }
70
71 public Node getNode() {
72 return node;
73 }
74
75
76 public static final GBeanInfo GBEAN_INFO;
77
78 public static final String GBEAN_ATTR_CLUSTER_NAME = "clusterName";
79 public static final String GBEAN_ATTR_CLUSTER_URI = "clusterUri";
80 public static final String GBEAN_ATTR_INACTIVE_TIME = "inactiveTime";
81
82 public static final String GBEAN_REF_NODE = "Node";
83
84 static {
85 GBeanInfoBuilder infoBuilder = GBeanInfoBuilder.createStatic(TribesDispatcherHolder.class,
86 NameFactory.GERONIMO_SERVICE);
87
88 infoBuilder.addAttribute(GBEAN_ATTR_CLUSTER_NAME, String.class, true);
89 infoBuilder.addAttribute(GBEAN_ATTR_INACTIVE_TIME, long.class, true);
90
91 infoBuilder.addReference(GBEAN_REF_NODE, Node.class, NameFactory.GERONIMO_SERVICE);
92
93 infoBuilder.addInterface(DispatcherHolder.class);
94
95 infoBuilder.setConstructor(new String[] { GBEAN_ATTR_CLUSTER_NAME,
96 GBEAN_ATTR_INACTIVE_TIME,
97 GBEAN_REF_NODE });
98
99 GBEAN_INFO = infoBuilder.getBeanInfo();
100 }
101
102 public static GBeanInfo getGBeanInfo() {
103 return GBEAN_INFO;
104 }
105 }