[hornetq-commits] JBoss hornetq SVN: r9708 - in branches/hornetq-416: src/main/org/hornetq/core/protocol/core/impl and 4 other directories.

do-not-reply at jboss.org do-not-reply at jboss.org
Tue Sep 21 10:18:08 EDT 2010


Author: jmesnil
Date: 2010-09-21 10:18:07 -0400 (Tue, 21 Sep 2010)
New Revision: 9708

Added:
   branches/hornetq-416/src/main/org/hornetq/api/jms/management/JMSConnectionInfo.java
Modified:
   branches/hornetq-416/src/main/org/hornetq/api/jms/management/JMSServerControl.java
   branches/hornetq-416/src/main/org/hornetq/core/protocol/core/impl/RemotingConnectionImpl.java
   branches/hornetq-416/src/main/org/hornetq/core/protocol/stomp/StompConnection.java
   branches/hornetq-416/src/main/org/hornetq/jms/management/impl/JMSServerControlImpl.java
   branches/hornetq-416/src/main/org/hornetq/spi/core/protocol/RemotingConnection.java
   branches/hornetq-416/tests/src/org/hornetq/tests/integration/jms/server/management/JMSServerControl2Test.java
   branches/hornetq-416/tests/src/org/hornetq/tests/integration/jms/server/management/JMSServerControlUsingJMSTest.java
Log:
https://jira.jboss.org/browse/HORNETQ-416

* add JMSConnectionInfo and JMSServerControl.listConnectionsAsJSON()
* add RemotingConnection.getCreationTime() to know when a connection has been created

Added: branches/hornetq-416/src/main/org/hornetq/api/jms/management/JMSConnectionInfo.java
===================================================================
--- branches/hornetq-416/src/main/org/hornetq/api/jms/management/JMSConnectionInfo.java	                        (rev 0)
+++ branches/hornetq-416/src/main/org/hornetq/api/jms/management/JMSConnectionInfo.java	2010-09-21 14:18:07 UTC (rev 9708)
@@ -0,0 +1,96 @@
+/*
+ * Copyright 2010 Red Hat, Inc.
+ * Red Hat licenses this file to you under the Apache License, version
+ * 2.0 (the "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ * implied.  See the License for the specific language governing
+ * permissions and limitations under the License.
+ */
+
+package org.hornetq.api.jms.management;
+
+import org.hornetq.utils.json.JSONArray;
+import org.hornetq.utils.json.JSONObject;
+
+/**
+ * A JMSConnectionInfo
+ *
+ * @author jmesnil
+ *
+ *
+ */
+public class JMSConnectionInfo
+{
+
+   // Constants -----------------------------------------------------
+
+   // Attributes ----------------------------------------------------
+
+   private final String connectionID;
+   
+   private final String clientAddress;
+   
+   private final long creationTime;
+   
+   // TODO
+   // user name
+   // client ID
+
+   // Static --------------------------------------------------------
+   
+   public static JMSConnectionInfo[] from(final String jsonString) throws Exception
+   {
+      JSONArray array = new JSONArray(jsonString);
+      JMSConnectionInfo[] infos = new JMSConnectionInfo[array.length()];
+      for (int i = 0; i < array.length(); i++)
+      {
+         JSONObject obj = array.getJSONObject(i);
+         JMSConnectionInfo info = new JMSConnectionInfo(obj.getString("connectionID"),
+                                                        obj.getString("clientAddress"),
+                                                        obj.getLong("creationTime"));
+         infos[i] = info;
+      }
+      return infos;
+   }
+
+   // Constructors --------------------------------------------------
+
+   private JMSConnectionInfo(final String connectionID,
+                             final String clientAddress,
+                             final long creationTime)
+   {
+      this.connectionID = connectionID;
+      this.clientAddress = clientAddress;
+      this.creationTime = creationTime;
+   }
+   
+   // Public --------------------------------------------------------
+
+   public String getConnectionID()
+   {
+      return connectionID;
+   }
+   
+   public String getClientAddress()
+   {
+      return clientAddress;
+   }
+   
+   public long getCreationTime()
+   {
+      return creationTime;
+   }
+   
+   // Package protected ---------------------------------------------
+
+   // Protected -----------------------------------------------------
+
+   // Private -------------------------------------------------------
+
+   // Inner classes -------------------------------------------------
+
+}

Modified: branches/hornetq-416/src/main/org/hornetq/api/jms/management/JMSServerControl.java
===================================================================
--- branches/hornetq-416/src/main/org/hornetq/api/jms/management/JMSServerControl.java	2010-09-21 13:38:26 UTC (rev 9707)
+++ branches/hornetq-416/src/main/org/hornetq/api/jms/management/JMSServerControl.java	2010-09-21 14:18:07 UTC (rev 9708)
@@ -228,6 +228,8 @@
    @Operation(desc = "List all the connection IDs", impact = MBeanOperationInfo.INFO)
    String[] listConnectionIDs() throws Exception;
 
+   String listConnectionsAsJSON() throws Exception;
+   
    /**
     * Lists all the sessions IDs for the specified connection ID.
     */

Modified: branches/hornetq-416/src/main/org/hornetq/core/protocol/core/impl/RemotingConnectionImpl.java
===================================================================
--- branches/hornetq-416/src/main/org/hornetq/core/protocol/core/impl/RemotingConnectionImpl.java	2010-09-21 13:38:26 UTC (rev 9707)
+++ branches/hornetq-416/src/main/org/hornetq/core/protocol/core/impl/RemotingConnectionImpl.java	2010-09-21 14:18:07 UTC (rev 9708)
@@ -89,6 +89,8 @@
    
    private volatile boolean executing;
 
+   private final long creationTime;
+
    // Constructors
    // ---------------------------------------------------------------------------------
 
@@ -129,6 +131,8 @@
       this.client = client;
 
       this.executor = executor;
+      
+      this.creationTime = System.currentTimeMillis();
    }
 
    // RemotingConnection implementation
@@ -160,6 +164,11 @@
    {
       return transportConnection.getRemoteAddress();
    }
+   
+   public long getCreationTime()
+   {
+      return creationTime;
+   }
 
    public synchronized Channel getChannel(final long channelID, final int confWindowSize)
    {

Modified: branches/hornetq-416/src/main/org/hornetq/core/protocol/stomp/StompConnection.java
===================================================================
--- branches/hornetq-416/src/main/org/hornetq/core/protocol/stomp/StompConnection.java	2010-09-21 13:38:26 UTC (rev 9707)
+++ branches/hornetq-416/src/main/org/hornetq/core/protocol/stomp/StompConnection.java	2010-09-21 14:18:07 UTC (rev 9708)
@@ -49,12 +49,16 @@
    private boolean valid;
 
    private boolean destroyed = false;
+   
+   private final long creationTime;
 
    StompConnection(final Connection transportConnection, final StompProtocolManager manager)
    {
       this.transportConnection = transportConnection;
 
       this.manager = manager;
+      
+      this.creationTime = System.currentTimeMillis();
    }
 
    public void addCloseListener(CloseListener listener)
@@ -117,6 +121,11 @@
    {
       return transportConnection.getRemoteAddress();
    }
+   
+   public long getCreationTime()
+   {
+      return creationTime;
+   }
 
    public Connection getTransportConnection()
    {

Modified: branches/hornetq-416/src/main/org/hornetq/jms/management/impl/JMSServerControlImpl.java
===================================================================
--- branches/hornetq-416/src/main/org/hornetq/jms/management/impl/JMSServerControlImpl.java	2010-09-21 13:38:26 UTC (rev 9707)
+++ branches/hornetq-416/src/main/org/hornetq/jms/management/impl/JMSServerControlImpl.java	2010-09-21 14:18:07 UTC (rev 9708)
@@ -16,6 +16,7 @@
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Map;
+import java.util.Set;
 import java.util.concurrent.atomic.AtomicLong;
 
 import javax.management.ListenerNotFoundException;
@@ -31,13 +32,16 @@
 import org.hornetq.api.core.Pair;
 import org.hornetq.api.core.TransportConfiguration;
 import org.hornetq.api.core.management.ManagementHelper;
-import org.hornetq.api.core.management.Parameter;
 import org.hornetq.api.jms.management.ConnectionFactoryControl;
 import org.hornetq.api.jms.management.JMSQueueControl;
 import org.hornetq.api.jms.management.JMSServerControl;
 import org.hornetq.api.jms.management.TopicControl;
 import org.hornetq.core.management.impl.MBeanInfoHelper;
+import org.hornetq.core.server.ServerSession;
 import org.hornetq.jms.server.JMSServerManager;
+import org.hornetq.spi.core.protocol.RemotingConnection;
+import org.hornetq.utils.json.JSONArray;
+import org.hornetq.utils.json.JSONObject;
 
 /**
  * @author <a href="mailto:jmesnil at redhat.com">Jeff Mesnil</a>
@@ -567,7 +571,34 @@
          blockOnIO();
       }
    }
+   
+   public String listConnectionsAsJSON() throws Exception
+   {
+      checkStarted();
 
+      clearIO();
+
+      try
+      {
+         JSONArray array = new JSONArray();
+         
+         Set<RemotingConnection> connections = server.getHornetQServer().getRemotingService().getConnections();
+         for (RemotingConnection connection : connections)
+         {
+            JSONObject obj = new JSONObject();
+            obj.put("connectionID", connection.getID().toString());
+            obj.put("clientAddress", connection.getRemoteAddress());
+            obj.put("creationTime", connection.getCreationTime());
+            array.put(obj);
+         }
+         return array.toString();
+      }
+      finally
+      {
+         blockOnIO();
+      }
+   }
+   
    public String[] listSessions(final String connectionID) throws Exception
    {
       checkStarted();

Modified: branches/hornetq-416/src/main/org/hornetq/spi/core/protocol/RemotingConnection.java
===================================================================
--- branches/hornetq-416/src/main/org/hornetq/spi/core/protocol/RemotingConnection.java	2010-09-21 13:38:26 UTC (rev 9707)
+++ branches/hornetq-416/src/main/org/hornetq/spi/core/protocol/RemotingConnection.java	2010-09-21 14:18:07 UTC (rev 9708)
@@ -38,6 +38,11 @@
    Object getID();
 
    /**
+    * Returns the creation time of the Remoting connection
+    */
+   long getCreationTime();
+
+   /**
     * returns a string representation of the remote address of this connection
     *
     * @return the remote address

Modified: branches/hornetq-416/tests/src/org/hornetq/tests/integration/jms/server/management/JMSServerControl2Test.java
===================================================================
--- branches/hornetq-416/tests/src/org/hornetq/tests/integration/jms/server/management/JMSServerControl2Test.java	2010-09-21 13:38:26 UTC (rev 9707)
+++ branches/hornetq-416/tests/src/org/hornetq/tests/integration/jms/server/management/JMSServerControl2Test.java	2010-09-21 14:18:07 UTC (rev 9708)
@@ -25,6 +25,7 @@
 import junit.framework.Assert;
 
 import org.hornetq.api.core.TransportConfiguration;
+import org.hornetq.api.jms.management.JMSConnectionInfo;
 import org.hornetq.api.jms.management.JMSServerControl;
 import org.hornetq.core.config.Configuration;
 import org.hornetq.core.config.impl.ConfigurationImpl;
@@ -139,7 +140,17 @@
    {
       doListConnectionIDs(NettyAcceptorFactory.class.getName(), NettyConnectorFactory.class.getName());
    }
+   
+   public void testListConnectionsAsJSONForNetty() throws Exception
+   {
+      doListConnectionsAsJSON(NettyAcceptorFactory.class.getName(), NettyConnectorFactory.class.getName());
+   }
 
+   public void testListConnectionsAsJSONForInVM() throws Exception
+   {
+      doListConnectionsAsJSON(InVMAcceptorFactory.class.getName(), InVMConnectorFactory.class.getName());
+   }
+
    // Package protected ---------------------------------------------
 
    // Protected -----------------------------------------------------
@@ -207,6 +218,80 @@
       }
    }
 
+   private void doListConnectionsAsJSON(final String acceptorFactory, final String connectorFactory) throws Exception
+   {
+      try
+      {
+         startHornetQServer(acceptorFactory);
+
+         JMSServerControl control = createManagementControl();
+
+         long startTime = System.currentTimeMillis();
+         
+         String jsonStr = control.listConnectionsAsJSON();
+         assertNotNull(jsonStr);
+         JMSConnectionInfo[] infos = JMSConnectionInfo.from(jsonStr);
+         assertEquals(0, infos.length);
+
+         ConnectionFactory cf1 = JMSUtil.createFactory(connectorFactory,
+                                                       JMSServerControl2Test.CONNECTION_TTL,
+                                                       JMSServerControl2Test.PING_PERIOD);
+         Connection connection = cf1.createConnection();
+
+         jsonStr = control.listConnectionsAsJSON();
+         assertNotNull(jsonStr);
+         infos = JMSConnectionInfo.from(jsonStr);
+         assertEquals(1, infos.length);
+         for (JMSConnectionInfo info : infos)
+         {
+            assertNotNull(info.getConnectionID());
+            assertNotNull(info.getClientAddress());
+            assertTrue(startTime < info.getCreationTime() && info.getCreationTime() < System.currentTimeMillis());
+         }
+
+         ConnectionFactory cf2 = JMSUtil.createFactory(connectorFactory,
+                                                       JMSServerControl2Test.CONNECTION_TTL,
+                                                       JMSServerControl2Test.PING_PERIOD);
+         Connection connection2 = cf2.createConnection();
+
+         jsonStr = control.listConnectionsAsJSON();
+         assertNotNull(jsonStr);
+         infos = JMSConnectionInfo.from(jsonStr);
+         assertEquals(2, infos.length);
+         for (JMSConnectionInfo info : infos)
+         {
+            assertNotNull(info.getConnectionID());
+            assertNotNull(info.getClientAddress());
+            assertTrue(startTime < info.getCreationTime() && info.getCreationTime() < System.currentTimeMillis());
+         }
+
+         connection.close();
+
+         waitForConnectionIDs(1, control);
+
+         connection2.close();
+
+         waitForConnectionIDs(0, control);
+         
+         jsonStr = control.listConnectionsAsJSON();
+         assertNotNull(jsonStr);
+         infos = JMSConnectionInfo.from(jsonStr);
+         assertEquals(0, infos.length);
+      }
+      finally
+      {
+         if (serverManager != null)
+         {
+            serverManager.stop();
+         }
+
+         if (server != null)
+         {
+            server.stop();
+         }
+      }
+   }
+   
    private void waitForConnectionIDs(final int num, final JMSServerControl control) throws Exception
    {
       final long timeout = 10000;

Modified: branches/hornetq-416/tests/src/org/hornetq/tests/integration/jms/server/management/JMSServerControlUsingJMSTest.java
===================================================================
--- branches/hornetq-416/tests/src/org/hornetq/tests/integration/jms/server/management/JMSServerControlUsingJMSTest.java	2010-09-21 13:38:26 UTC (rev 9707)
+++ branches/hornetq-416/tests/src/org/hornetq/tests/integration/jms/server/management/JMSServerControlUsingJMSTest.java	2010-09-21 14:18:07 UTC (rev 9708)
@@ -233,6 +233,11 @@
          {
             return (String[])proxy.invokeOperation("listConnectionIDs");
          }
+         
+         public String listConnectionsAsJSON() throws Exception
+         {
+            return (String)proxy.invokeOperation("listConnectionsAsJSON");
+         }
 
          public String[] listRemoteAddresses() throws Exception
          {



More information about the hornetq-commits mailing list