1 17 package org.apache.geronimo.clustering.wadi; 18 19 import java.net.URI ; 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 37 public class TribesDispatcherHolder implements GBeanLifecycle, DispatcherHolder { 38 private static final Log log = LogFactory.getLog(TribesDispatcherHolder.class); 39 40 private final URI endPointURI; 41 private final String clusterName; 42 private final long inactiveTime; 43 private final Node node; 44 45 private TribesDispatcher dispatcher; 46 47 48 public TribesDispatcherHolder(URI endPointURI, String clusterName, long inactiveTime, Node node) { 49 if (null == endPointURI) { 50 throw new IllegalArgumentException ("endPointURI is required"); 51 } else if (null == clusterName) { 52 throw new IllegalArgumentException ("clusterName is required"); 53 } else if (0 > inactiveTime) { 54 throw new IllegalArgumentException ("inactiveTime must be > 0"); 55 } else if (null == node) { 56 throw new IllegalArgumentException ("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 { 65 dispatcher = new TribesDispatcher(clusterName, node.getName(), new URIEndPoint(endPointURI), inactiveTime, null); 66 dispatcher.start(); 67 } 68 69 public void doStop() throws Exception { 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 GBEAN_ATTR_END_POINT_URI = "endPointURI"; 93 public static final String GBEAN_ATTR_CLUSTER_NAME = "clusterName"; 94 public static final String GBEAN_ATTR_CLUSTER_URI = "clusterUri"; 95 public static final String GBEAN_ATTR_INACTIVE_TIME = "inactiveTime"; 96 97 public static final String 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 .class, true); 104 infoBuilder.addAttribute(GBEAN_ATTR_CLUSTER_NAME, String .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 [] { 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 |