001 /** 002 * 003 * Licensed to the Apache Software Foundation (ASF) under one or more 004 * contributor license agreements. See the NOTICE file distributed with 005 * this work for additional information regarding copyright ownership. 006 * The ASF licenses this file to You under the Apache License, Version 2.0 007 * (the "License"); you may not use this file except in compliance with 008 * the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, software 013 * distributed under the License is distributed on an "AS IS" BASIS, 014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 015 * See the License for the specific language governing permissions and 016 * limitations under the License. 017 */ 018 package org.apache.geronimo.clustering.wadi; 019 020 import org.apache.commons.logging.Log; 021 import org.apache.commons.logging.LogFactory; 022 import org.apache.geronimo.clustering.Node; 023 import org.apache.geronimo.gbean.GBeanInfo; 024 import org.apache.geronimo.gbean.GBeanInfoBuilder; 025 import org.apache.geronimo.gbean.GBeanLifecycle; 026 import org.apache.geronimo.j2ee.j2eeobjectnames.NameFactory; 027 import org.codehaus.wadi.group.Dispatcher; 028 import org.codehaus.wadi.group.MessageExchangeException; 029 import org.codehaus.wadi.tribes.TribesDispatcher; 030 031 /** 032 * 033 * @version $Rev$ $Date$ 034 */ 035 public class TribesDispatcherHolder implements GBeanLifecycle, DispatcherHolder { 036 private static final Log log = LogFactory.getLog(TribesDispatcherHolder.class); 037 038 private final String clusterName; 039 private final long inactiveTime; 040 private final Node node; 041 042 private TribesDispatcher dispatcher; 043 044 public TribesDispatcherHolder(String clusterName, long inactiveTime, Node node) { 045 this.clusterName = clusterName; 046 this.inactiveTime = inactiveTime; 047 this.node = node; 048 } 049 050 public void doStart() throws Exception { 051 dispatcher = new TribesDispatcher(clusterName, node.getName(), inactiveTime, null); 052 dispatcher.start(); 053 } 054 055 public void doStop() throws Exception { 056 dispatcher.stop(); 057 } 058 059 public void doFail() { 060 try { 061 dispatcher.stop(); 062 } catch (MessageExchangeException e) { 063 log.error(e); 064 } 065 } 066 067 public Dispatcher getDispatcher() { 068 return dispatcher; 069 } 070 071 public Node getNode() { 072 return node; 073 } 074 075 076 public static final GBeanInfo GBEAN_INFO; 077 078 public static final String GBEAN_ATTR_CLUSTER_NAME = "clusterName"; 079 public static final String GBEAN_ATTR_CLUSTER_URI = "clusterUri"; 080 public static final String GBEAN_ATTR_INACTIVE_TIME = "inactiveTime"; 081 082 public static final String GBEAN_REF_NODE = "Node"; 083 084 static { 085 GBeanInfoBuilder infoBuilder = GBeanInfoBuilder.createStatic(TribesDispatcherHolder.class, 086 NameFactory.GERONIMO_SERVICE); 087 088 infoBuilder.addAttribute(GBEAN_ATTR_CLUSTER_NAME, String.class, true); 089 infoBuilder.addAttribute(GBEAN_ATTR_INACTIVE_TIME, long.class, true); 090 091 infoBuilder.addReference(GBEAN_REF_NODE, Node.class, NameFactory.GERONIMO_SERVICE); 092 093 infoBuilder.addInterface(DispatcherHolder.class); 094 095 infoBuilder.setConstructor(new String[] { GBEAN_ATTR_CLUSTER_NAME, 096 GBEAN_ATTR_INACTIVE_TIME, 097 GBEAN_REF_NODE }); 098 099 GBEAN_INFO = infoBuilder.getBeanInfo(); 100 } 101 102 public static GBeanInfo getGBeanInfo() { 103 return GBEAN_INFO; 104 } 105 }