1 18 package org.apache.activemq.network; 19 20 import org.apache.activemq.transport.Transport; 21 import org.apache.activemq.transport.TransportFactory; 22 import org.apache.activemq.util.ServiceStopper; 23 24 import java.net.URI ; 25 26 38 public class MulticastNetworkConnector extends NetworkConnector { 39 40 private Transport localTransport; 41 private Transport remoteTransport; 42 private URI remoteURI; 43 private DemandForwardingBridgeSupport bridge; 44 45 public MulticastNetworkConnector() { 46 } 47 48 public MulticastNetworkConnector(URI remoteURI) { 49 this.remoteURI = remoteURI; 50 } 51 52 55 public DemandForwardingBridgeSupport getBridge() { 56 return bridge; 57 } 58 59 public void setBridge(DemandForwardingBridgeSupport bridge) { 60 this.bridge = bridge; 61 } 62 63 public Transport getLocalTransport() { 64 return localTransport; 65 } 66 67 public void setLocalTransport(Transport localTransport) { 68 this.localTransport = localTransport; 69 } 70 71 public Transport getRemoteTransport() { 72 return remoteTransport; 73 } 74 75 78 public void setRemoteTransport(Transport remoteTransport) { 79 this.remoteTransport = remoteTransport; 80 } 81 82 public URI getRemoteURI() { 83 return remoteURI; 84 } 85 86 90 public void setRemoteURI(URI remoteURI) { 91 this.remoteURI = remoteURI; 92 } 93 94 97 protected void handleStart() throws Exception { 98 if (remoteTransport == null) { 99 if (remoteURI == null) { 100 throw new IllegalArgumentException ("You must specify the remoteURI property"); 101 } 102 remoteTransport = TransportFactory.connect(remoteURI); 103 } 104 105 if (localTransport == null) { 106 localTransport = createLocalTransport(); 107 } 108 109 bridge = createBridge(localTransport, remoteTransport); 110 configureBridge(bridge); 111 bridge.start(); 112 113 remoteTransport.start(); 115 localTransport.start(); 116 117 super.handleStart(); 118 } 119 120 protected void handleStop(ServiceStopper stopper) throws Exception { 121 super.handleStop(stopper); 122 if (bridge != null) { 123 try { 124 bridge.stop(); 125 } 126 catch (Exception e) { 127 stopper.onException(this, e); 128 } 129 } 130 if (remoteTransport != null) { 131 try { 132 remoteTransport.stop(); 133 } 134 catch (Exception e) { 135 stopper.onException(this, e); 136 } 137 } 138 if (localTransport != null) { 139 try { 140 localTransport.stop(); 141 } 142 catch (Exception e) { 143 stopper.onException(this, e); 144 } 145 } 146 } 147 148 public String getName() { 149 return remoteTransport.toString(); 150 } 151 152 protected DemandForwardingBridgeSupport createBridge(Transport local, Transport remote) { 153 return new CompositeDemandForwardingBridge(this,local, remote); 154 } 155 156 } 157 | Popular Tags |