activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jstrac...@apache.org
Subject svn commit: r424697 - in /incubator/activemq/trunk/activemq-core/src: main/java/org/apache/activemq/ main/java/org/apache/activemq/util/ test/java/org/apache/activemq/
Date Sun, 23 Jul 2006 10:00:38 GMT
Author: jstrachan
Date: Sun Jul 23 03:00:37 2006
New Revision: 424697

URL: http://svn.apache.org/viewvc?rev=424697&view=rev
Log:
Added an optional clientIDPrefix property to allow auto-generated client Ids to be named to
make it easier to manage a running system using JMX. Fixes AMQ-836
You can now specify this clientIDPrefix property on the ActiveMQConnectionFactory POJO or
via a URI such as

tcp://localhost:61616?jms.clientIDPrefix=Cheese

Added:
    incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/util/package.html
  (with props)
Modified:
    incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/ActiveMQConnection.java
    incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/ActiveMQConnectionFactory.java
    incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/ActiveMQXAConnection.java
    incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/ActiveMQXAConnectionFactory.java
    incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/util/IdGenerator.java
    incubator/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/ActiveMQConnectionFactoryTest.java

Modified: incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/ActiveMQConnection.java
URL: http://svn.apache.org/viewvc/incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/ActiveMQConnection.java?rev=424697&r1=424696&r2=424697&view=diff
==============================================================================
--- incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/ActiveMQConnection.java
(original)
+++ incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/ActiveMQConnection.java
Sun Jul 23 03:00:37 2006
@@ -101,7 +101,6 @@
 
     private static final Log log = LogFactory.getLog(ActiveMQConnection.class);
     private static final IdGenerator connectionIdGenerator = new IdGenerator();
-    private static final IdGenerator clientIdGenerator = new IdGenerator();
 
     public static final String DEFAULT_USER = ActiveMQConnectionFactory.DEFAULT_USER;
     public static final String DEFAULT_PASSWORD = ActiveMQConnectionFactory.DEFAULT_PASSWORD;
@@ -130,9 +129,11 @@
     private boolean useRetroactiveConsumer;
     private int closeTimeout = 15000;
     
-    private final JMSConnectionStatsImpl stats;
-    private final JMSStatsImpl factoryStats;
     private final Transport transport;
+    private final IdGenerator clientIdGenerator;
+    private final JMSStatsImpl factoryStats;
+    private final JMSConnectionStatsImpl stats;
+    
     private final AtomicBoolean started = new AtomicBoolean(false);
     private final AtomicBoolean closing = new AtomicBoolean(false);
     private final AtomicBoolean closed = new AtomicBoolean(false);
@@ -167,9 +168,13 @@
      * @param password
      * @throws Exception 
      */
-    protected ActiveMQConnection(final Transport transport, JMSStatsImpl factoryStats)
+    protected ActiveMQConnection(final Transport transport, IdGenerator clientIdGenerator,
JMSStatsImpl factoryStats)
             throws Exception {
        
+        this.transport = transport;
+        this.clientIdGenerator = clientIdGenerator;
+        this.factoryStats = factoryStats;
+        
         // Configure a single threaded executor who's core thread can timeout if idle
         asyncConnectionThread = new ThreadPoolExecutor(1,1,5,TimeUnit.SECONDS, new LinkedBlockingQueue(),
new ThreadFactory() {
             public Thread newThread(Runnable r) {
@@ -183,11 +188,9 @@
         this.info.setManageable(true);
         this.connectionSessionId = new SessionId(info.getConnectionId(), -1);
         
-        this.transport = transport;
         this.transport.setTransportListener(this);
 
         this.stats = new JMSConnectionStatsImpl(sessions, this instanceof XAConnection);
-        this.factoryStats = factoryStats;
         this.factoryStats.addConnection(this);
     }
 
@@ -1229,6 +1232,7 @@
         ConsumerId consumerId = new ConsumerId(new SessionId(info.getConnectionId(), -1),consumerIdGenerator.getNextSequenceId());
         advisoryConsumer = new AdvisoryConsumer(this, consumerId);        
     }
+
 
     /**
      * @return Returns the useAsyncSend.

Modified: incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/ActiveMQConnectionFactory.java
URL: http://svn.apache.org/viewvc/incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/ActiveMQConnectionFactory.java?rev=424697&r1=424696&r2=424697&view=diff
==============================================================================
--- incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/ActiveMQConnectionFactory.java
(original)
+++ incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/ActiveMQConnectionFactory.java
Sun Jul 23 03:00:37 2006
@@ -36,6 +36,7 @@
 import org.apache.activemq.management.StatsImpl;
 import org.apache.activemq.transport.Transport;
 import org.apache.activemq.transport.TransportFactory;
+import org.apache.activemq.util.IdGenerator;
 import org.apache.activemq.util.IntrospectionSupport;
 import org.apache.activemq.util.JMSExceptionSupport;
 import org.apache.activemq.util.URISupport;
@@ -60,6 +61,8 @@
     public static final String DEFAULT_USER = null;
     public static final String DEFAULT_PASSWORD = null;
 
+    private IdGenerator clientIdGenerator;
+    private String clientIDPrefix;
     protected URI brokerURL;
     protected String userName;
     protected String password;
@@ -251,7 +254,7 @@
     }
 
     protected ActiveMQConnection createActiveMQConnection(Transport transport, JMSStatsImpl
stats) throws Exception {
-        ActiveMQConnection connection = new ActiveMQConnection(transport, stats);
+        ActiveMQConnection connection = new ActiveMQConnection(transport, getClientIdGenerator(),
stats);
         return connection;
     }
 
@@ -608,5 +611,35 @@
      */
     public void setNestedMapAndListEnabled(boolean structuredMapsEnabled) {
         this.nestedMapAndListEnabled = structuredMapsEnabled;
+    }
+
+    public String getClientIDPrefix() {
+        return clientIDPrefix;
+    }
+
+    /**
+     * Sets the prefix used by autogenerated JMS Client ID values which are
+     * used if the JMS client does not explicitly specify on.
+     * 
+     * @param clientIDPrefix
+     */
+    public void setClientIDPrefix(String clientIDPrefix) {
+        this.clientIDPrefix = clientIDPrefix;
+    }
+    
+    protected synchronized IdGenerator getClientIdGenerator() {
+        if (clientIdGenerator == null) {
+            if (clientIDPrefix != null) {
+                clientIdGenerator = new IdGenerator(clientIDPrefix);
+            }
+            else {
+                clientIdGenerator = new IdGenerator();
+            }
+        }
+        return clientIdGenerator;
+    }
+
+    protected void setClientIdGenerator(IdGenerator clientIdGenerator) {
+        this.clientIdGenerator = clientIdGenerator;
     }
 }

Modified: incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/ActiveMQXAConnection.java
URL: http://svn.apache.org/viewvc/incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/ActiveMQXAConnection.java?rev=424697&r1=424696&r2=424697&view=diff
==============================================================================
--- incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/ActiveMQXAConnection.java
(original)
+++ incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/ActiveMQXAConnection.java
Sun Jul 23 03:00:37 2006
@@ -27,6 +27,7 @@
 
 import org.apache.activemq.management.JMSStatsImpl;
 import org.apache.activemq.transport.Transport;
+import org.apache.activemq.util.IdGenerator;
 
 /**
  * The XAConnection interface extends the capability of Connection by providing
@@ -49,15 +50,8 @@
  */
 public class ActiveMQXAConnection extends ActiveMQConnection implements XATopicConnection,
XAQueueConnection, XAConnection {
 
-    /**
-     * @param transport
-     * @param theUserName
-     * @param thePassword
-     * @param factoryStats
-     * @throws Exception 
-     */
-    protected ActiveMQXAConnection(Transport transport, JMSStatsImpl factoryStats) throws
Exception {
-        super(transport, factoryStats);
+    protected ActiveMQXAConnection(Transport transport, IdGenerator clientIdGenerator, JMSStatsImpl
factoryStats) throws Exception {
+        super(transport, clientIdGenerator, factoryStats);
     }
 
     public XASession createXASession() throws JMSException {

Modified: incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/ActiveMQXAConnectionFactory.java
URL: http://svn.apache.org/viewvc/incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/ActiveMQXAConnectionFactory.java?rev=424697&r1=424696&r2=424697&view=diff
==============================================================================
--- incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/ActiveMQXAConnectionFactory.java
(original)
+++ incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/ActiveMQXAConnectionFactory.java
Sun Jul 23 03:00:37 2006
@@ -80,7 +80,7 @@
     }
 
     protected ActiveMQConnection createActiveMQConnection(Transport transport, JMSStatsImpl
stats) throws Exception {
-        ActiveMQXAConnection connection = new ActiveMQXAConnection(transport, stats);
+        ActiveMQXAConnection connection = new ActiveMQXAConnection(transport, getClientIdGenerator(),
stats);
         return connection;
     }
 }

Modified: incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/util/IdGenerator.java
URL: http://svn.apache.org/viewvc/incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/util/IdGenerator.java?rev=424697&r1=424696&r2=424697&view=diff
==============================================================================
--- incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/util/IdGenerator.java
(original)
+++ incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/util/IdGenerator.java
Sun Jul 23 03:00:37 2006
@@ -49,7 +49,7 @@
 			try {
 				hostName = InetAddress.getLocalHost().getHostName();
 				ServerSocket ss = new ServerSocket(0);
-				stub=hostName + "-" + ss.getLocalPort() + "-" + System.currentTimeMillis() + "-";
+				stub="-" + ss.getLocalPort() + "-" + System.currentTimeMillis() + "-";
 				Thread.sleep(100);
 				ss.close();
 			}catch(Exception ioe){
@@ -57,7 +57,7 @@
 			}
 		}else{
             hostName="localhost";
-			stub = hostName + "-1-" +System.currentTimeMillis() +"-";
+			stub = "-1-" +System.currentTimeMillis() +"-";
 		}
 		UNIQUE_STUB = stub;
 	}
@@ -84,7 +84,7 @@
 	}
     
     public IdGenerator(){
-        this("ID:");
+        this("ID:" + hostName);
     }
 	
 	/**

Added: incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/util/package.html
URL: http://svn.apache.org/viewvc/incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/util/package.html?rev=424697&view=auto
==============================================================================
--- incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/util/package.html
(added)
+++ incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/util/package.html
Sun Jul 23 03:00:37 2006
@@ -0,0 +1,9 @@
+<html>
+<head>
+</head>
+<body>
+
+Some utility classes
+
+</body>
+</html>

Propchange: incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/util/package.html
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/util/package.html
------------------------------------------------------------------------------
    svn:executable = *

Modified: incubator/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/ActiveMQConnectionFactoryTest.java
URL: http://svn.apache.org/viewvc/incubator/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/ActiveMQConnectionFactoryTest.java?rev=424697&r1=424696&r2=424697&view=diff
==============================================================================
--- incubator/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/ActiveMQConnectionFactoryTest.java
(original)
+++ incubator/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/ActiveMQConnectionFactoryTest.java
Sun Jul 23 03:00:37 2006
@@ -29,6 +29,24 @@
 
 public class ActiveMQConnectionFactoryTest extends CombinationTestSupport {
     
+    public void testUseURIToSetUseClientIDPrefixOnConnectionFactory() throws URISyntaxException,
JMSException {
+        ActiveMQConnectionFactory cf = new ActiveMQConnectionFactory("vm://localhost?jms.clientIDPrefix=Cheese");
+        assertEquals("Cheese", cf.getClientIDPrefix());
+
+        ActiveMQConnection connection = (ActiveMQConnection) cf.createConnection();
+        try {
+            connection.start();
+
+            String clientID = connection.getClientID();
+            log.info("Got client ID: " + clientID);
+
+            assertTrue("should start with Cheese! but was: " + clientID, clientID.startsWith("Cheese"));
+        }
+        finally {
+            connection.close();
+        }
+    }
+    
     public void testUseURIToSetOptionsOnConnectionFactory() throws URISyntaxException, JMSException
{
         ActiveMQConnectionFactory cf = new ActiveMQConnectionFactory("vm://localhost?jms.useAsyncSend=true");
         assertTrue(cf.isUseAsyncSend());



Mime
View raw message