Package org.jboss.jms.client

Examples of org.jboss.jms.client.JBossConnection


    
   public void testWithRealServer() throws Exception
   {
      ConnectionFactory cf = (JBossConnectionFactory)ic.lookup("/ConnectionFactory");
     
      JBossConnection conn1 = null;
     
      JBossConnection conn2 = null;
     
     
      try
      {
     
         conn1 = (JBossConnection)cf.createConnection();
         Session sess1 = conn1.createSession(false, Session.AUTO_ACKNOWLEDGE);
        
         conn2 = (JBossConnection)cf.createConnection();
         Session sess2 = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
        
         ServerPeer peer = ServerManagement.getServer().getServerPeer();
        
         SimpleConnectionManager cm = (SimpleConnectionManager)peer.getConnectionManager();
        
         //Simulate failure on connection
        
         Map jmsClients = cm.getClients();
         assertEquals(1, jmsClients.size());
        
         Map endpoints = (Map)jmsClients.values().iterator().next();
        
         assertEquals(2, endpoints.size());
        
         Iterator iter = endpoints.entrySet().iterator();
              
         Map.Entry entry = (Map.Entry)iter.next();
        
         String sessId1 = (String)entry.getKey();
         
         entry = (Map.Entry)iter.next();
        
         String sessId2 = (String)entry.getKey();
        
         //Simulate failure of connection
        
         cm.handleClientFailure(sessId1);
 
         jmsClients = cm.getClients();
         assertEquals(1, jmsClients.size());       
        
         cm.handleClientFailure(sessId2);
        
         jmsClients = cm.getClients();
         assertEquals(0, jmsClients.size());  
      }
      finally
      {
         if (conn1 != null)
         {
            conn1.close();
         }
         if (conn2 != null)
         {
            conn2.close();
         }
      }
   }
View Full Code Here


      try
      {
         xaConn = cf.createXAConnection();

         JBossConnection jbConn = (JBossConnection)xaConn;

         ClientConnectionDelegate del = (ClientConnectionDelegate)jbConn.getDelegate();

         ConnectionState state = (ConnectionState)del.getState();

         ResourceManager rm = state.getResourceManager();
View Full Code Here

      try
      {
         xaConn = cf.createXAConnection();

         JBossConnection jbConn = (JBossConnection)xaConn;

         ClientConnectionDelegate del = (ClientConnectionDelegate)jbConn.getDelegate();

         ConnectionState state = (ConnectionState)del.getState();

         ResourceManager rm = state.getResourceManager();
View Full Code Here

      if (!ServerManagement.isRemote())
      {
         return;
      }

      JBossConnection connection = null;

      try
      {
         connection = (JBossConnection)cf.createConnection();
         connection.start();

         ClientConnectionDelegate delegate = (ClientConnectionDelegate)connection.getDelegate();
         JMSRemotingConnection remotingConnection = delegate.getRemotingConnection();
         Client client = remotingConnection.getRemotingClient();

         Field field = JMSRemotingConnection.class.getDeclaredField("serverLocator");
         field.setAccessible(true);
         InvokerLocator locator = (InvokerLocator)field.get(remotingConnection);
         String transport = locator.getProtocol();

         if (!"http".equals(transport))
         {
            // not interesting
            return;
         }

         field = Client.class.getDeclaredField("callbackPollers");
         field.setAccessible(true);
         Map callbackPollers = (Map)field.get(client);
         assertEquals(1, callbackPollers.size());

         CallbackPoller callbackPoller = (CallbackPoller)callbackPollers.values().iterator().next();

         field = CallbackPoller.class.getDeclaredField("pollPeriod");
         field.setAccessible(true);
         Long pollPeriod = (Long)field.get(callbackPoller);
         assertEquals(ServiceContainer.HTTP_CONNECTOR_CALLBACK_POLL_PERIOD, pollPeriod.longValue());
      }
      finally
      {
         if (connection != null)
         {
            connection.close();
         }
      }
   }
View Full Code Here

      if (!ServerManagement.isRemote())
      {
         return;
      }

      JBossConnection connection = null;

      try
      {
         String address = InetAddress.getLocalHost().getHostAddress();
         System.setProperty("jboss.messaging.callback.bind.address", address);
        
         int freePort = PortUtil.findFreePort(InetAddress.getLocalHost().getHostName());
         System.setProperty("jboss.messaging.callback.bind.port", Integer.toString(freePort));

         String pollPeriod = "654";
         System.setProperty("jboss.messaging.callback.pollPeriod", pollPeriod);

         System.setProperty("jboss.messaging.callback.reportPollingStatistics", "true");
        
         connection = (JBossConnection)cf.createConnection();
         connection.start();

         ClientConnectionDelegate delegate = (ClientConnectionDelegate)connection.getDelegate();
         JMSRemotingConnection remotingConnection = delegate.getRemotingConnection();
         Client client = remotingConnection.getRemotingClient();

         Field field = JMSRemotingConnection.class.getDeclaredField("serverLocator");
         field.setAccessible(true);
         InvokerLocator locator = (InvokerLocator)field.get(remotingConnection);
         String transport = locator.getProtocol();

         if ("socket".equals(transport)
               || "sslsocket".equals(transport)
               || "bisocket".equals(transport)
               || "sslbisocket".equals(transport))
         {
            field = Client.class.getDeclaredField("callbackConnectors");
            field.setAccessible(true);
            Map callbackConnectors = (Map)field.get(client);

            InvokerCallbackHandler callbackHandler = remotingConnection.getCallbackManager();
            HashSet map = (HashSet) callbackConnectors.get(callbackHandler);
            Connector connector = (Connector)map.iterator().next();
            locator = new InvokerLocator(connector.getInvokerLocator());
            assertEquals(address, locator.getHost());
            assertEquals(freePort, locator.getPort());
         }
         else if ("http".equals(transport))
         {
            field = Client.class.getDeclaredField("callbackPollers");
            field.setAccessible(true);
            Map callbackPollers = (Map)field.get(client);
            assertEquals(1, callbackPollers.size());

            CallbackPoller callbackPoller =
               (CallbackPoller)callbackPollers.values().iterator().next();

            field = CallbackPoller.class.getDeclaredField("pollPeriod");
            field.setAccessible(true);

            assertEquals(pollPeriod, ((Long)field.get(callbackPoller)).toString());
           
            field = CallbackPoller.class.getDeclaredField("reportStatistics");
            field.setAccessible(true);
            assertEquals(true, ((Boolean) field.get(callbackPoller)).booleanValue());
         }
         else
         {
            fail("Unrecognized transport: " + transport);
         }
      }
      finally
      {
         if (connection != null)
         {
            connection.close();
         }
        
         System.clearProperty("jboss.messaging.callback.bind.address");
        
         System.clearProperty("jboss.messaging.callback.bind.port");
View Full Code Here

         conn.start();

         for (int i = 0; i < 3; i++)
         {
            JBossConnection connTest = (JBossConnection)
               getConnection(new Connection[]{conn1, conn2, conn3}, i);

            String locator = ((ClientConnectionDelegate) connTest.getDelegate()).
               getRemotingConnection().getRemotingClient().getInvoker().getLocator().getLocatorURI();

            log.info("Server " + i + " has locator=" + locator);

         }
View Full Code Here

    
   public void testWithRealServer() throws Exception
   {
      ConnectionFactory cf = (JBossConnectionFactory)ic.lookup("/ConnectionFactory");
     
      JBossConnection conn1 = null;
     
      JBossConnection conn2 = null;
     
     
      try
      {
     
        conn1 = (JBossConnection)cf.createConnection();
        Session sess1 = conn1.createSession(false, Session.AUTO_ACKNOWLEDGE);
       
        conn2 = (JBossConnection)cf.createConnection();
        Session sess2 = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
       
        ServerPeer peer = ServerManagement.getServer().getServerPeer();
       
        SimpleConnectionManager cm = (SimpleConnectionManager)peer.getConnectionManager();
       
        //Simulate failure on connection
       
        Map jmsClients = cm.getClients();
        assertEquals(1, jmsClients.size());
       
        Map endpoints = (Map)jmsClients.values().iterator().next();
       
        assertEquals(2, endpoints.size());
       
        Iterator iter = endpoints.entrySet().iterator();
             
        Map.Entry entry = (Map.Entry)iter.next();
       
        String sessId1 = (String)entry.getKey();
        
        entry = (Map.Entry)iter.next();
       
        //Simulate failure of connection
       
        cm.handleClientFailure(sessId1, true);
       
        //both connections should be shut
       
        jmsClients = cm.getClients();
        assertEquals(0, jmsClients.size());       
      }
      finally
      {
        if (conn1 != null)
        {
          conn1.close();
        }
        if (conn2 != null)
        {
          conn2.close();
        }
      }
   }
View Full Code Here

      try
      {
         conn = createConnectionOnServer(cf, 1);

         JBossConnection jbc = (JBossConnection)conn;
        
         SimpleFailoverListener failoverListener = new SimpleFailoverListener();
         ((JBossConnection)conn).registerFailoverListener(failoverListener);

         ClientConnectionDelegate del = (ClientConnectionDelegate)jbc.getDelegate();

         ConnectionState state = (ConnectionState)del.getState();

         int initialServerID = state.getServerID();
View Full Code Here

         conn = createConnectionOnServer(cf, 1);
        
         SimpleFailoverListener failoverListener = new SimpleFailoverListener();
         ((JBossConnection)conn).registerFailoverListener(failoverListener);

         JBossConnection jbc = (JBossConnection)conn;

         ClientConnectionDelegate del = (ClientConnectionDelegate)jbc.getDelegate();

         ConnectionState state = (ConnectionState)del.getState();

         int initialServerID = state.getServerID();
View Full Code Here

   public void testTopicSubscriber() throws Exception
   {
      Destination destination = (Destination) topic[1];

      JBossConnection conn = (JBossConnection)createConnectionOnServer(cf, 1);
     
      SimpleFailoverListener failoverListener = new SimpleFailoverListener();
      ((JBossConnection)conn).registerFailoverListener(failoverListener);


      conn.setClientID("testClient");
      conn.start();

      try
      {
         JBossSession session = (JBossSession) conn.createSession(true, Session.SESSION_TRANSACTED);
         ClientSessionDelegate clientSessionDelegate = (ClientSessionDelegate) session.getDelegate();
         SessionState sessionState = (SessionState) clientSessionDelegate.getState();

         MessageConsumer consumerHA = session.createDurableSubscriber((Topic) destination, "T1");

         MessageProducer producer = session.createProducer(destination);
         Message message = session.createTextMessage("Hello Before");
         producer.send(message);
         session.commit();

         receiveMessage("consumerHA", consumerHA, true, false);

         session.commit();
         //if (true) return;

         Object txID = sessionState.getCurrentTxId();

         producer.send(session.createTextMessage("Hello again before failover"));

         ClientConnectionDelegate delegate = (ClientConnectionDelegate) conn.getDelegate();

         JMSRemotingConnection originalRemoting = delegate.getRemotingConnection();

         ServerManagement.kill(1);

         // wait for the client-side failover to complete

         while(true)
         {
            FailoverEvent event = failoverListener.getEvent(30000);
            if (event != null && FailoverEvent.FAILOVER_COMPLETED == event.getType())
            {
               break;
            }
            if (event == null)
            {
               fail("Did not get expected FAILOVER_COMPLETED event");
            }
         }
         // if failover happened, this object was replaced
         assertNotSame(originalRemoting, delegate.getRemotingConnection());

         message = session.createTextMessage("Hello After");
         producer.send(message);

         assertEquals(txID, sessionState.getCurrentTxId());
         session.commit();

         receiveMessage("consumerHA", consumerHA, true, false);
         receiveMessage("consumerHA", consumerHA, true, false);
         receiveMessage("consumerHA", consumerHA, true, true);

         session.commit();

         consumerHA.close();
         session.unsubscribe("T1");
      }
      finally
      {
         if (conn!=null)
         {
            try { conn.close(); } catch (Throwable ignored) {}
         }
      }
   }
View Full Code Here

TOP

Related Classes of org.jboss.jms.client.JBossConnection

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.