Package org.hornetq.api.jms.management

Examples of org.hornetq.api.jms.management.JMSServerControl


   {
      try
      {
         startHornetQServer(acceptorFactory);

         JMSServerControl control = createManagementControl();

         Assert.assertEquals(0, control.listConnectionIDs().length);

         ConnectionFactory cf1 = JMSUtil.createFactory(connectorFactory,
                                                       JMSServerControl2Test.CONNECTION_TTL,
                                                       JMSServerControl2Test.PING_PERIOD);
         Connection connection = cf1.createConnection();

         String[] connectionIDs = control.listConnectionIDs();
         Assert.assertEquals(1, connectionIDs.length);

         ConnectionFactory cf2 = JMSUtil.createFactory(connectorFactory,
                                                       JMSServerControl2Test.CONNECTION_TTL,
                                                       JMSServerControl2Test.PING_PERIOD);
         Connection connection2 = cf2.createConnection();
         Assert.assertEquals(2, control.listConnectionIDs().length);

         connection.close();

         waitForConnectionIDs(1, control);
View Full Code Here


   {
      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());
            assertNull(info.getClientID());
            assertNull(info.getUsername());
         }

         connection.close();

         waitForConnectionIDs(1, control);

         connection2.close();

         waitForConnectionIDs(0, control);
        
         Connection connection3 = cf2.createConnection("guest", "guest");
         connection3.setClientID("MyClient");
        
         jsonStr = control.listConnectionsAsJSON();
         assertNotNull(jsonStr);
        
         infos = JMSConnectionInfo.from(jsonStr);
         JMSConnectionInfo info = infos[0];
         assertEquals("MyClient", info.getClientID());
         assertEquals("guest", info.getUsername());
        
         connection3.close();
        
         jsonStr = control.listConnectionsAsJSON();
         assertNotNull(jsonStr);
         infos = JMSConnectionInfo.from(jsonStr);
         assertEquals(0, infos.length);
      }
      finally
View Full Code Here

   {
      try
      {
         startHornetQServer(acceptorFactory);

         JMSServerControl control = createManagementControl();

         Assert.assertEquals(0, control.listConnectionIDs().length);

         ConnectionFactory cf = JMSUtil.createFactory(connectorFactory,
                                                      JMSServerControl2Test.CONNECTION_TTL,
                                                      JMSServerControl2Test.PING_PERIOD);
         Connection connection = cf.createConnection();

         String[] connectionIDs = control.listConnectionIDs();
         Assert.assertEquals(1, connectionIDs.length);
         String connectionID = connectionIDs[0];

         String[] sessions = control.listSessions(connectionID);
         Assert.assertEquals(1, sessions.length);
         connection.close();
         sessions = control.listSessions(connectionID);
         Assert.assertEquals("got " + Arrays.asList(sessions), 0, sessions.length);

         connection.close();

         waitForConnectionIDs(0, control);

         Assert.assertEquals(0, control.listConnectionIDs().length);
      }
      finally
      {
         if (serverManager != null)
         {
View Full Code Here

   {
      try
      {
         startHornetQServer(acceptorFactory);

         JMSServerControl control = createManagementControl();

         Assert.assertEquals(0, control.listRemoteAddresses().length);

         ConnectionFactory cf = JMSUtil.createFactory(connectorFactory,
                                                      JMSServerControl2Test.CONNECTION_TTL,
                                                      JMSServerControl2Test.PING_PERIOD);
         Connection connection = cf.createConnection();

         String[] remoteAddresses = control.listRemoteAddresses();
         Assert.assertEquals(1, remoteAddresses.length);

         for (String remoteAddress : remoteAddresses)
         {
            System.out.println(remoteAddress);
         }

         connection.close();

         waitForConnectionIDs(0, control);

         remoteAddresses = control.listRemoteAddresses();
         Assert.assertEquals("got " + Arrays.asList(remoteAddresses), 0, remoteAddresses.length);
      }
      finally
      {
         if (serverManager != null)
View Full Code Here

   {
      try
      {
         startHornetQServer(acceptorFactory);

         JMSServerControl control = createManagementControl();

         Assert.assertEquals(0, server.getConnectionCount());
         Assert.assertEquals(0, control.listRemoteAddresses().length);

         ConnectionFactory cf = JMSUtil.createFactory(connectorFactory,
                                                      JMSServerControl2Test.CONNECTION_TTL,
                                                      JMSServerControl2Test.PING_PERIOD);
         Connection connection = cf.createConnection();

         Assert.assertEquals(1, server.getConnectionCount());

         String[] remoteAddresses = control.listRemoteAddresses();
         Assert.assertEquals(1, remoteAddresses.length);
         String remoteAddress = remoteAddresses[0];

         final CountDownLatch exceptionLatch = new CountDownLatch(1);
         connection.setExceptionListener(new ExceptionListener()
         {
            public void onException(final JMSException e)
            {
               exceptionLatch.countDown();
            }
         });

         Assert.assertTrue(control.closeConnectionsForAddress(remoteAddress));

         boolean gotException = exceptionLatch.await(2 * JMSServerControl2Test.CONNECTION_TTL, TimeUnit.MILLISECONDS);
         Assert.assertTrue("did not received the expected JMSException", gotException);

         remoteAddresses = control.listRemoteAddresses();
         Assert.assertEquals("got " + Arrays.asList(remoteAddresses), 0, remoteAddresses.length);
         Assert.assertEquals(0, server.getConnectionCount());

         connection.close();
      }
View Full Code Here

      try
      {
         startHornetQServer(acceptorFactory);

         JMSServerControl control = createManagementControl();

         Assert.assertEquals(0, server.getConnectionCount());
         Assert.assertEquals(0, control.listRemoteAddresses().length);

         ConnectionFactory cf = JMSUtil.createFactory(connectorFactory,
                                                      JMSServerControl2Test.CONNECTION_TTL,
                                                      JMSServerControl2Test.PING_PERIOD);
         Connection connection = cf.createConnection();

         Assert.assertEquals(1, server.getConnectionCount());
         String[] remoteAddresses = control.listRemoteAddresses();
         Assert.assertEquals(1, remoteAddresses.length);

         final CountDownLatch exceptionLatch = new CountDownLatch(1);
         connection.setExceptionListener(new ExceptionListener()
         {
            public void onException(final JMSException e)
            {
               exceptionLatch.countDown();
            }
         });

         Assert.assertFalse(control.closeConnectionsForAddress(unknownAddress));

         boolean gotException = exceptionLatch.await(2 * JMSServerControl2Test.CONNECTION_TTL, TimeUnit.MILLISECONDS);
         Assert.assertFalse(gotException);

         Assert.assertEquals(1, control.listRemoteAddresses().length);
         Assert.assertEquals(1, server.getConnectionCount());

         connection.close();

      }
View Full Code Here

      {
         startHornetQServer(NettyAcceptorFactory.class.getName());
         serverManager.createQueue(false, queueName, null, true, queueName);
         Queue queue = HornetQJMSClient.createQueue(queueName);

         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(NettyConnectorFactory.class.getName(),
                                                       JMSServerControl2Test.CONNECTION_TTL,
                                                       JMSServerControl2Test.PING_PERIOD);
         Connection connection = cf1.createConnection();
         Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
         TemporaryTopic temporaryTopic = session.createTemporaryTopic();

         // create a regular message consumer
         MessageConsumer consumer = session.createConsumer(queue);

         jsonStr = control.listConnectionsAsJSON();
         assertNotNull(jsonStr);
         infos = JMSConnectionInfo.from(jsonStr);
         assertEquals(1, infos.length);
         String connectionID = infos[0].getConnectionID();
        
         String consJsonStr = control.listConsumersAsJSON(connectionID);
         assertNotNull(consJsonStr);
         JMSConsumerInfo[] consumerInfos = JMSConsumerInfo.from(consJsonStr);
         assertEquals(1, consumerInfos.length);
         JMSConsumerInfo consumerInfo = consumerInfos[0];
         assertNotNull(consumerInfo.getConsumerID());
         assertEquals(connectionID, consumerInfo.getConnectionID());
         assertEquals(queue.getQueueName(), consumerInfo.getDestinationName());
         assertEquals("queue", consumerInfo.getDestinationType());
         assertNull(consumerInfo.getFilter());
         assertEquals(false, consumerInfo.isBrowseOnly());
         assertEquals(false, consumerInfo.isDurable());
         assertTrue(startTime <= consumerInfo.getCreationTime() && consumerInfo.getCreationTime() <= System.currentTimeMillis());

         consumer.close();
        
         consJsonStr = control.listConsumersAsJSON(connectionID);
         assertNotNull(consJsonStr);
         consumerInfos = JMSConsumerInfo.from(consJsonStr);
         assertEquals(0, consumerInfos.length);

         // create a queue browser
         QueueBrowser browser = session.createBrowser(queue);
         // the server resources are created when the browser starts enumerating
         browser.getEnumeration();
        
         consJsonStr = control.listConsumersAsJSON(connectionID);
         assertNotNull(consJsonStr);
         System.out.println(consJsonStr);
         consumerInfos = JMSConsumerInfo.from(consJsonStr);
         assertEquals(1, consumerInfos.length);
         consumerInfo = consumerInfos[0];
         assertNotNull(consumerInfo.getConsumerID());
         assertEquals(connectionID, consumerInfo.getConnectionID());
         assertEquals(queue.getQueueName(), consumerInfo.getDestinationName());
         assertEquals("queue", consumerInfo.getDestinationType());
         assertNull(consumerInfo.getFilter());
         assertEquals(true, consumerInfo.isBrowseOnly());
         assertEquals(false, consumerInfo.isDurable());
         assertTrue(startTime <= consumerInfo.getCreationTime() && consumerInfo.getCreationTime() <= System.currentTimeMillis());

         browser.close();
        
         // create a regular consumer w/ filter on a temp topic
         String filter = "color = 'red'";
         consumer = session.createConsumer(temporaryTopic, filter);
        
         consJsonStr = control.listConsumersAsJSON(connectionID);
         assertNotNull(consJsonStr);
         System.out.println(consJsonStr);
         consumerInfos = JMSConsumerInfo.from(consJsonStr);
         assertEquals(1, consumerInfos.length);
         consumerInfo = consumerInfos[0];
View Full Code Here

      {
         startHornetQServer(NettyAcceptorFactory.class.getName());
         serverManager.createTopic(false, topicName, topicName);
         Topic topic = HornetQJMSClient.createTopic(topicName);
        
         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(NettyConnectorFactory.class.getName(),
                                                       JMSServerControl2Test.CONNECTION_TTL,
                                                       JMSServerControl2Test.PING_PERIOD);
         Connection connection = cf1.createConnection();
         connection.setClientID(clientID);
         Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);

         // create a durable subscriber
         MessageConsumer consumer = session.createDurableSubscriber(topic, subName);
        
         jsonStr = control.listConnectionsAsJSON();
         assertNotNull(jsonStr);
         infos = JMSConnectionInfo.from(jsonStr);
         assertEquals(1, infos.length);
         String connectionID = infos[0].getConnectionID();
        
         String consJsonStr = control.listConsumersAsJSON(connectionID);
         assertNotNull(consJsonStr);
         JMSConsumerInfo[] consumerInfos = JMSConsumerInfo.from(consJsonStr);
         assertEquals(1, consumerInfos.length);
         JMSConsumerInfo consumerInfo = consumerInfos[0];
         assertNotNull(consumerInfo.getConsumerID());
View Full Code Here

      {
         startHornetQServer(NettyAcceptorFactory.class.getName());
         serverManager.createQueue(false, queueName, null, true, queueName);
         Queue queue = HornetQJMSClient.createQueue(queueName);

         JMSServerControl control = createManagementControl();

         long startTime = System.currentTimeMillis();

         ConnectionFactory cf1 = JMSUtil.createFactory(NettyConnectorFactory.class.getName(),
                                                       JMSServerControl2Test.CONNECTION_TTL,
                                                       JMSServerControl2Test.PING_PERIOD);
         connection = cf1.createConnection();
         Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
        
         MessageProducer producer = session.createProducer(queue);
        
         TextMessage msgSent = null;
         for (int i = 0; i < 10; i++)
         {
            msgSent = session.createTextMessage("mymessage-" + i);
            producer.send(msgSent);
            System.out.println("sending msgID " + msgSent.getJMSMessageID());
         }
        
        

         connection.start();
        
         // create a regular message consumer
         MessageConsumer consumer = session.createConsumer(queue);

         TextMessage receivedMsg = null;
         for (int i = 0; i < 10; i++)
         {
            receivedMsg = (TextMessage)consumer.receive(3000);
            assertNotNull(receivedMsg);
            System.out.println("receiveMsg: " + receivedMsg);
         }
        
         assertEquals(msgSent.getJMSMessageID(), receivedMsg.getJMSMessageID());
        
         HornetQMessage jmsMessage = (HornetQMessage)receivedMsg;
         String lastMsgID = jmsMessage.getCoreMessage().getUserID().toString();
        
         String jsonStr = control.listConnectionsAsJSON();
         JMSConnectionInfo[] infos = JMSConnectionInfo.from(jsonStr);
        
         JMSConnectionInfo connInfo = infos[0];
        
         String sessionsStr = control.listSessionsAsJSON(connInfo.getConnectionID());
         JMSSessionInfo[] sessInfos = JMSSessionInfo.from(sessionsStr);
        
         assertTrue(sessInfos.length > 0);
         boolean lastMsgFound = false;
         for (JMSSessionInfo sInfo : sessInfos)
         {
            System.out.println("Session name: " + sInfo.getSessionID());
            assertNotNull(sInfo.getSessionID());
            long createTime = sInfo.getCreationTime();
            assertTrue(startTime <= createTime && createTime <= System.currentTimeMillis());
            String lastID = control.getLastSentMessageID(sInfo.getSessionID(), "jms.queue." + queueName);
            if (lastID != null)
            {
               assertEquals(lastMsgID, lastID);
               lastMsgFound = true;
            }
View Full Code Here

      return 0;
   }

   public void testGetVersion() throws Exception
   {
      JMSServerControl control = createManagementControl();
      String version = control.getVersion();
      Assert.assertEquals(serverManager.getVersion(), version);
   }
View Full Code Here

TOP

Related Classes of org.hornetq.api.jms.management.JMSServerControl

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.