Support naming all the connectors so that JMX object names are easier to view.

git-svn-id: https://svn.apache.org/repos/asf/incubator/activemq/trunk@383972 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Hiram R. Chirino 2006-03-07 19:25:05 +00:00
parent c977f7ddfc
commit b2ad8fa833
8 changed files with 84 additions and 31 deletions

View File

@ -775,7 +775,8 @@ public class BrokerService implements Service {
ObjectName objectName = new ObjectName( ObjectName objectName = new ObjectName(
managementContext.getJmxDomainName()+":"+ managementContext.getJmxDomainName()+":"+
"BrokerName="+JMXSupport.encodeObjectNamePart(getBrokerName())+","+ "BrokerName="+JMXSupport.encodeObjectNamePart(getBrokerName())+","+
"Type=NetworkConnector" "Type=NetworkConnector,"+
"NetworkConnectorName="+JMXSupport.encodeObjectNamePart(connector.getName())
); );
mbeanServer.registerMBean(view, objectName); mbeanServer.registerMBean(view, objectName);
registeredMBeanNames.add(objectName); registeredMBeanNames.add(objectName);
@ -792,7 +793,8 @@ public class BrokerService implements Service {
ObjectName objectName = new ObjectName( ObjectName objectName = new ObjectName(
managementContext.getJmxDomainName()+":"+ managementContext.getJmxDomainName()+":"+
"BrokerName="+JMXSupport.encodeObjectNamePart(getBrokerName())+","+ "BrokerName="+JMXSupport.encodeObjectNamePart(getBrokerName())+","+
"Type=ProxyConnector" "Type=ProxyConnector,"+
"ProxyConnectorName="+JMXSupport.encodeObjectNamePart(connector.getName())
); );
mbeanServer.registerMBean(view, objectName); mbeanServer.registerMBean(view, objectName);
registeredMBeanNames.add(objectName); registeredMBeanNames.add(objectName);
@ -826,7 +828,8 @@ public class BrokerService implements Service {
ObjectName objectName = new ObjectName( ObjectName objectName = new ObjectName(
managementContext.getJmxDomainName()+":"+ managementContext.getJmxDomainName()+":"+
"BrokerName="+JMXSupport.encodeObjectNamePart(getBrokerName())+","+ "BrokerName="+JMXSupport.encodeObjectNamePart(getBrokerName())+","+
"Type=JmsConnector" "Type=JmsConnector,"+
"JmsConnectorName="+JMXSupport.encodeObjectNamePart(connector.getName())
); );
mbeanServer.registerMBean(view, objectName); mbeanServer.registerMBean(view, objectName);
registeredMBeanNames.add(objectName); registeredMBeanNames.add(objectName);

View File

@ -63,6 +63,7 @@ public class TransportConnector implements Connector {
private ConnectorStatistics statistics = new ConnectorStatistics(); private ConnectorStatistics statistics = new ConnectorStatistics();
private URI discoveryUri; private URI discoveryUri;
private URI connectUri; private URI connectUri;
private String name;
/** /**
@ -86,12 +87,13 @@ public class TransportConnector implements Connector {
* Factory method to create a JMX managed version of this transport connector * Factory method to create a JMX managed version of this transport connector
*/ */
public ManagedTransportConnector asManagedConnector(MBeanServer mbeanServer, ObjectName connectorName) throws IOException, URISyntaxException { public ManagedTransportConnector asManagedConnector(MBeanServer mbeanServer, ObjectName connectorName) throws IOException, URISyntaxException {
ManagedTransportConnector rc = new ManagedTransportConnector(mbeanServer,connectorName, getBroker(), getServer()); ManagedTransportConnector rc = new ManagedTransportConnector(mbeanServer, connectorName, getBroker(), getServer());
rc.setTaskRunnerFactory(getTaskRunnerFactory()); rc.setTaskRunnerFactory(getTaskRunnerFactory());
rc.setUri(uri); rc.setUri(uri);
rc.setConnectUri(connectUri); rc.setConnectUri(connectUri);
rc.setDiscoveryAgent(discoveryAgent); rc.setDiscoveryAgent(discoveryAgent);
rc.setDiscoveryUri(discoveryUri); rc.setDiscoveryUri(discoveryUri);
rc.setName(name);
return rc; return rc;
} }
@ -110,10 +112,6 @@ public class TransportConnector implements Connector {
return server; return server;
} }
public String getName() throws IOException, URISyntaxException {
return getServer().getConnectURI().toString();
}
public Broker getBroker() { public Broker getBroker() {
return broker; return broker;
} }
@ -195,15 +193,13 @@ public class TransportConnector implements Connector {
public void start() throws Exception { public void start() throws Exception {
getServer().start(); getServer().start();
log.info("Accepting connection on: "+getServer().getConnectURI());
DiscoveryAgent da = getDiscoveryAgent(); DiscoveryAgent da = getDiscoveryAgent();
if( da!=null ) { if( da!=null ) {
da.registerService(getConnectUri().toString()); da.registerService(getConnectUri().toString());
da.start(); da.start();
} }
this.statusDector.start(); this.statusDector.start();
log.info("Connector "+getName()+" Started");
} }
public void stop() throws Exception { public void stop() throws Exception {
@ -220,6 +216,7 @@ public class TransportConnector implements Connector {
ss.stop(c); ss.stop(c);
} }
ss.throwFirstException(); ss.throwFirstException();
log.info("Connector "+getName()+" Stopped");
} }
// Implementation methods // Implementation methods
@ -288,4 +285,14 @@ public class TransportConnector implements Connector {
connections.remove(connection); connections.remove(connection);
} }
public String getName() {
if( name == null ) {
name = server.getConnectURI().toString();
}
return name;
}
public void setName(String name) {
this.name = name;
}
} }

View File

@ -57,7 +57,7 @@ public class MasterConnector implements Service{
private TransportConnector connector; private TransportConnector connector;
private AtomicBoolean masterActive=new AtomicBoolean(false); private AtomicBoolean masterActive=new AtomicBoolean(false);
private AtomicBoolean started=new AtomicBoolean(false); private AtomicBoolean started=new AtomicBoolean(false);
IdGenerator idGenerator=new IdGenerator(); private final IdGenerator idGenerator=new IdGenerator();
ConnectionInfo connectionInfo; ConnectionInfo connectionInfo;
SessionInfo sessionInfo; SessionInfo sessionInfo;

View File

@ -17,14 +17,13 @@
package org.apache.activemq.network; package org.apache.activemq.network;
import java.util.Set; import java.util.Set;
import org.apache.activemq.command.ActiveMQDestination;
import org.apache.activemq.command.ConsumerId; import org.apache.activemq.command.ConsumerId;
import org.apache.activemq.command.ConsumerInfo; import org.apache.activemq.command.ConsumerInfo;
import edu.emory.mathcs.backport.java.util.concurrent.CopyOnWriteArraySet; import edu.emory.mathcs.backport.java.util.concurrent.CopyOnWriteArraySet;
import edu.emory.mathcs.backport.java.util.concurrent.atomic.AtomicInteger; import edu.emory.mathcs.backport.java.util.concurrent.atomic.AtomicInteger;
/** /**
* Represents a network bridge interface * Represents a network bridge interface
* *

View File

@ -34,7 +34,6 @@ import org.apache.activemq.command.SessionInfo;
import org.apache.activemq.command.ShutdownInfo; import org.apache.activemq.command.ShutdownInfo;
import org.apache.activemq.transport.DefaultTransportListener; import org.apache.activemq.transport.DefaultTransportListener;
import org.apache.activemq.transport.Transport; import org.apache.activemq.transport.Transport;
import org.apache.activemq.transport.TransportListener;
import org.apache.activemq.util.IdGenerator; import org.apache.activemq.util.IdGenerator;
import org.apache.activemq.util.ServiceStopper; import org.apache.activemq.util.ServiceStopper;
import org.apache.activemq.util.ServiceSupport; import org.apache.activemq.util.ServiceSupport;

View File

@ -81,6 +81,7 @@ public class NetworkConnector implements Service, DiscoveryListener {
throw new IllegalStateException("You must configure the 'localURI' property"); throw new IllegalStateException("You must configure the 'localURI' property");
} }
this.discoveryAgent.start(); this.discoveryAgent.start();
log.info("Network Connector "+getName()+" Started");
} }
public void stop() throws Exception { public void stop() throws Exception {
@ -89,6 +90,7 @@ public class NetworkConnector implements Service, DiscoveryListener {
Bridge bridge = (Bridge)i.next(); Bridge bridge = (Bridge)i.next();
bridge.stop(); bridge.stop();
} }
log.info("Network Connector "+getName()+" Stopped");
} }
public void onServiceAdd(DiscoveryEvent event) { public void onServiceAdd(DiscoveryEvent event) {
@ -228,6 +230,9 @@ public class NetworkConnector implements Service, DiscoveryListener {
* @return Returns the name. * @return Returns the name.
*/ */
public String getName(){ public String getName(){
if( name == null ) {
name = discoveryAgent.toString();
}
return name; return name;
} }
@ -373,7 +378,7 @@ public class NetworkConnector implements Service, DiscoveryListener {
if (conduitSubscriptions){ if (conduitSubscriptions){
if (dynamicOnly){ if (dynamicOnly){
result = new ConduitBridge(localTransport, remoteTransport) { result = new ConduitBridge(localTransport, remoteTransport) {
protected void serviceRemoteException(IOException error) { protected void serviceRemoteException(Exception error) {
super.serviceRemoteException(error); super.serviceRemoteException(error);
try { try {
// Notify the discovery agent that the remote broker failed. // Notify the discovery agent that the remote broker failed.
@ -384,7 +389,7 @@ public class NetworkConnector implements Service, DiscoveryListener {
}; };
}else { }else {
result = new DurableConduitBridge(localTransport, remoteTransport) { result = new DurableConduitBridge(localTransport, remoteTransport) {
protected void serviceRemoteException(IOException error) { protected void serviceRemoteException(Exception error) {
super.serviceRemoteException(error); super.serviceRemoteException(error);
try { try {
// Notify the discovery agent that the remote broker failed. // Notify the discovery agent that the remote broker failed.
@ -396,7 +401,7 @@ public class NetworkConnector implements Service, DiscoveryListener {
} }
}else { }else {
result = new DemandForwardingBridge(localTransport, remoteTransport) { result = new DemandForwardingBridge(localTransport, remoteTransport) {
protected void serviceRemoteException(IOException error) { protected void serviceRemoteException(Exception error) {
super.serviceRemoteException(error); super.serviceRemoteException(error);
try { try {
// Notify the discovery agent that the remote broker failed. // Notify the discovery agent that the remote broker failed.

View File

@ -19,10 +19,9 @@ package org.apache.activemq.network.jms;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import javax.jms.Connection; import javax.jms.Connection;
import javax.jms.Destination; import javax.jms.Destination;
import javax.jms.Queue;
import javax.jms.QueueConnection;
import org.apache.activemq.ActiveMQConnectionFactory; import org.apache.activemq.ActiveMQConnectionFactory;
import org.apache.activemq.Service; import org.apache.activemq.Service;
@ -31,6 +30,7 @@ import org.apache.activemq.util.LRUCache;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.springframework.jndi.JndiTemplate; import org.springframework.jndi.JndiTemplate;
import edu.emory.mathcs.backport.java.util.concurrent.CopyOnWriteArrayList; import edu.emory.mathcs.backport.java.util.concurrent.CopyOnWriteArrayList;
import edu.emory.mathcs.backport.java.util.concurrent.atomic.AtomicBoolean; import edu.emory.mathcs.backport.java.util.concurrent.atomic.AtomicBoolean;
@ -41,6 +41,7 @@ import edu.emory.mathcs.backport.java.util.concurrent.atomic.AtomicBoolean;
* @version $Revision: 1.1.1.1 $ * @version $Revision: 1.1.1.1 $
*/ */
public abstract class JmsConnector implements Service{ public abstract class JmsConnector implements Service{
private static final Log log=LogFactory.getLog(JmsConnector.class); private static final Log log=LogFactory.getLog(JmsConnector.class);
protected JndiTemplate jndiLocalTemplate; protected JndiTemplate jndiLocalTemplate;
protected JndiTemplate jndiOutboundTemplate; protected JndiTemplate jndiOutboundTemplate;
@ -52,11 +53,18 @@ public abstract class JmsConnector implements Service{
protected AtomicBoolean started = new AtomicBoolean(false); protected AtomicBoolean started = new AtomicBoolean(false);
protected ActiveMQConnectionFactory embeddedConnectionFactory; protected ActiveMQConnectionFactory embeddedConnectionFactory;
protected int replyToDestinationCacheSize=10000; protected int replyToDestinationCacheSize=10000;
protected String outboundUsername; protected String outboundUsername;
protected String outboundPassword; protected String outboundPassword;
protected String localUsername; protected String localUsername;
protected String localPassword; protected String localPassword;
private String name;
protected LRUCache replyToBridges=new LRUCache(){ protected LRUCache replyToBridges=new LRUCache(){
/**
*
*/
private static final long serialVersionUID = -7446792754185879286L;
protected boolean removeEldestEntry(Map.Entry enty){ protected boolean removeEldestEntry(Map.Entry enty){
if(size()>maxCacheSize){ if(size()>maxCacheSize){
Iterator iter=entrySet().iterator(); Iterator iter=entrySet().iterator();
@ -97,14 +105,15 @@ public abstract class JmsConnector implements Service{
public void start() throws Exception{ public void start() throws Exception{
init(); init();
if (started.compareAndSet(false, true)){ if (started.compareAndSet(false, true)){
for(int i=0;i<inboundBridges.size();i++){ for(int i=0;i<inboundBridges.size();i++){
DestinationBridge bridge=(DestinationBridge) inboundBridges.get(i); DestinationBridge bridge=(DestinationBridge) inboundBridges.get(i);
bridge.start(); bridge.start();
} }
for(int i=0;i<outboundBridges.size();i++){ for(int i=0;i<outboundBridges.size();i++){
DestinationBridge bridge=(DestinationBridge) outboundBridges.get(i); DestinationBridge bridge=(DestinationBridge) outboundBridges.get(i);
bridge.start(); bridge.start();
} }
log.info("JMS Connector "+getName()+" Started");
} }
} }
@ -118,6 +127,7 @@ public abstract class JmsConnector implements Service{
DestinationBridge bridge=(DestinationBridge) outboundBridges.get(i); DestinationBridge bridge=(DestinationBridge) outboundBridges.get(i);
bridge.stop(); bridge.stop();
} }
log.info("JMS Connector "+getName()+" Stopped");
} }
} }
@ -276,4 +286,20 @@ public abstract class JmsConnector implements Service{
protected void removeOutboundBridge(DestinationBridge bridge){ protected void removeOutboundBridge(DestinationBridge bridge){
outboundBridges.add(bridge); outboundBridges.add(bridge);
} }
public String getName() {
if( name == null ) {
name = "Connector:"+getNextId();
}
return name;
}
static int nextId;
static private synchronized int getNextId() {
return nextId;
}
public void setName(String name) {
this.name = name;
}
} }

View File

@ -46,6 +46,7 @@ public class ProxyConnector implements Service {
private URI bind; private URI bind;
private URI remote; private URI remote;
private URI localUri; private URI localUri;
private String name;
CopyOnWriteArrayList connections = new CopyOnWriteArrayList(); CopyOnWriteArrayList connections = new CopyOnWriteArrayList();
@ -69,6 +70,7 @@ public class ProxyConnector implements Service {
} }
}); });
getServer().start(); getServer().start();
log.info("Proxy Connector "+getName()+" Started");
} }
@ -82,6 +84,7 @@ public class ProxyConnector implements Service {
ss.stop((Service) iter.next()); ss.stop((Service) iter.next());
} }
ss.throwFirstException(); ss.throwFirstException();
log.info("Proxy Connector "+getName()+" Stopped");
} }
// Properties // Properties
@ -147,4 +150,15 @@ public class ProxyConnector implements Service {
return transport; return transport;
} }
public String getName() {
if( name == null ) {
name = server.getConnectURI().toString();
}
return name;
}
public void setName(String name) {
this.name = name;
}
} }