1 14 15 package org.apache.activemq.network; 16 17 import java.net.URI ; 18 import java.net.URISyntaxException ; 19 import java.util.List ; 20 import java.util.Set ; 21 import java.util.concurrent.CopyOnWriteArrayList ; 22 import org.apache.activemq.Service; 23 import org.apache.activemq.command.ActiveMQDestination; 24 import org.apache.activemq.transport.Transport; 25 import org.apache.activemq.transport.TransportFactory; 26 import org.apache.activemq.util.ServiceStopper; 27 import org.apache.activemq.util.ServiceSupport; 28 import org.apache.commons.logging.Log; 29 import org.apache.commons.logging.LogFactory; 30 31 34 public abstract class NetworkConnector extends NetworkBridgeConfiguration implements Service{ 35 36 protected static final Log log=LogFactory.getLog(NetworkConnector.class); 37 protected URI localURI; 38 private Set durableDestinations; 39 private List excludedDestinations=new CopyOnWriteArrayList (); 40 private List dynamicallyIncludedDestinations=new CopyOnWriteArrayList (); 41 private List staticallyIncludedDestinations=new CopyOnWriteArrayList (); 42 protected ConnectionFilter connectionFilter; 43 protected ServiceSupport serviceSupport=new ServiceSupport(){ 44 45 protected void doStart() throws Exception { 46 handleStart(); 47 } 48 49 protected void doStop(ServiceStopper stopper) throws Exception { 50 handleStop(stopper); 51 } 52 }; 53 54 public NetworkConnector(){ 55 } 56 57 public NetworkConnector(URI localURI){ 58 this.localURI=localURI; 59 } 60 61 public URI getLocalUri() throws URISyntaxException { 62 return localURI; 63 } 64 65 public void setLocalUri(URI localURI){ 66 this.localURI=localURI; 67 } 68 69 70 73 public Set getDurableDestinations(){ 74 return durableDestinations; 75 } 76 77 80 public void setDurableDestinations(Set durableDestinations){ 81 this.durableDestinations=durableDestinations; 82 } 83 84 87 public List getExcludedDestinations(){ 88 return excludedDestinations; 89 } 90 91 94 public void setExcludedDestinations(List excludedDestinations){ 95 this.excludedDestinations=excludedDestinations; 96 } 97 98 public void addExcludedDestination(ActiveMQDestination destiantion){ 99 this.excludedDestinations.add(destiantion); 100 } 101 102 105 public List getStaticallyIncludedDestinations(){ 106 return staticallyIncludedDestinations; 107 } 108 109 112 public void setStaticallyIncludedDestinations(List staticallyIncludedDestinations){ 113 this.staticallyIncludedDestinations=staticallyIncludedDestinations; 114 } 115 116 public void addStaticallyIncludedDestination(ActiveMQDestination destiantion){ 117 this.staticallyIncludedDestinations.add(destiantion); 118 } 119 120 123 public List getDynamicallyIncludedDestinations(){ 124 return dynamicallyIncludedDestinations; 125 } 126 127 130 public void setDynamicallyIncludedDestinations(List dynamicallyIncludedDestinations){ 131 this.dynamicallyIncludedDestinations=dynamicallyIncludedDestinations; 132 } 133 134 public void addDynamicallyIncludedDestination(ActiveMQDestination destiantion){ 135 this.dynamicallyIncludedDestinations.add(destiantion); 136 } 137 138 public ConnectionFilter getConnectionFilter(){ 139 return connectionFilter; 140 } 141 142 public void setConnectionFilter(ConnectionFilter connectionFilter){ 143 this.connectionFilter=connectionFilter; 144 } 145 146 147 protected NetworkBridge configureBridge(DemandForwardingBridgeSupport result){ 150 List destsList=getDynamicallyIncludedDestinations(); 151 ActiveMQDestination dests[]=(ActiveMQDestination[])destsList.toArray(new ActiveMQDestination[destsList.size()]); 152 result.setDynamicallyIncludedDestinations(dests); 153 destsList=getExcludedDestinations(); 154 dests=(ActiveMQDestination[])destsList.toArray(new ActiveMQDestination[destsList.size()]); 155 result.setExcludedDestinations(dests); 156 destsList=getStaticallyIncludedDestinations(); 157 dests=(ActiveMQDestination[])destsList.toArray(new ActiveMQDestination[destsList.size()]); 158 result.setStaticallyIncludedDestinations(dests); 159 if(durableDestinations!=null){ 160 ActiveMQDestination[] dest=new ActiveMQDestination[durableDestinations.size()]; 161 dest=(ActiveMQDestination[])durableDestinations.toArray(dest); 162 result.setDurableDestinations(dest); 163 } 164 return result; 165 } 166 167 protected Transport createLocalTransport() throws Exception { 168 return TransportFactory.connect(localURI); 169 } 170 171 public void start() throws Exception { 172 serviceSupport.start(); 173 } 174 175 public void stop() throws Exception { 176 serviceSupport.stop(); 177 } 178 179 public abstract String getName(); 180 181 protected void handleStart() throws Exception { 182 if(localURI==null){ 183 throw new IllegalStateException ("You must configure the 'localURI' property"); 184 } 185 log.info("Network Connector "+getName()+" Started"); 186 } 187 188 protected void handleStop(ServiceStopper stopper) throws Exception { 189 log.info("Network Connector "+getName()+" Stopped"); 190 } 191 } 192 | Popular Tags |