Package org.jboss.jms.client

Examples of org.jboss.jms.client.JBossConnection


   //the server should cancel the message. Then we receive the message and ack it.
   public void testMessageStuckOnConnectionFailure() throws Exception
   {
      ConnectionFactory cf = (JBossConnectionFactory)ic.lookup("/ConnectionFactory");
     
      JBossConnection conn1 = null;
      JBossConnection conn2 = null;

      try
      {
         //create a connection
         conn1 = (JBossConnection)cf.createConnection();
         Session sess1 = conn1.createSession(false, Session.CLIENT_ACKNOWLEDGE);
         MessageProducer prod1 = sess1.createProducer(queue1);
         TextMessage msg = sess1.createTextMessage("dont-stuck-me!");
         conn1.start();
        
         //send a message
         prod1.send(msg);
        
         //receive the message but not ack
         MessageConsumer cons1 = sess1.createConsumer(queue1);
         TextMessage rm = (TextMessage)cons1.receive(2000);
        
         assertNotNull(rm);
         assertEquals("dont-stuck-me!", rm.getText());
        
         //break connection.
         JMSRemotingConnection jmsConn = ((ClientConnectionDelegate)conn1.getDelegate()).getRemotingConnection();
         Client rmClient = jmsConn.getRemotingClient();
         rmClient.disconnect();
        
         //wait for server side cleanup
         try
         {
            Thread.sleep(5000);
         }
         catch (InterruptedException e)
         {
            //ignore.
         }
        
         //now receive the message
         conn2 = (JBossConnection)cf.createConnection();
         conn2.start();
         Session sess2 = conn2.createSession(false, Session.CLIENT_ACKNOWLEDGE);
         MessageConsumer cons2 = sess2.createConsumer(queue1);
         TextMessage rm2 = (TextMessage)cons2.receive(2000);

         assertNotNull(rm2);
         assertEquals("dont-stuck-me!", rm2.getText());
         rm2.acknowledge();
        
         //Message count should be zero.
         //this is checked in tearDown().
      }
      finally
      {
         if (conn1 != null)
         {
            conn1.close();
         }
         if (conn2 != null)
         {
            conn2.close();
         }
      }

   }
View Full Code Here


   //described issue may happen. At the end check the message count, it should always be zero.
   public void testMessageCountOnConnectionFailure() throws Exception
   {
      ConnectionFactory cf = (JBossConnectionFactory)ic.lookup("/ConnectionFactory");
     
      JBossConnection conn1 = null;
      JBossConnection conn2 = null;
     
      try
      {
         conn1 = (JBossConnection)cf.createConnection();
         conn1.start();
         Session sess1 = conn1.createSession(false, Session.CLIENT_ACKNOWLEDGE);
        
         //now send messages
         MessageProducer prod1 = sess1.createProducer(queue1);
        
         final int NUM_MSG = 2000;
         for (int i = 0; i < NUM_MSG; ++i)
         {
            TextMessage tm = sess1.createTextMessage("-m"+i);
            prod1.send(tm);
         }
        
         //receive the messages
         MessageConsumer cons1 = sess1.createConsumer(queue1);
         for (int j = 0; j < NUM_MSG-1; ++j)
         {
            TextMessage rm = (TextMessage)cons1.receive(2000);
            assertNotNull(rm);
            assertEquals("-m"+j, rm.getText());
         }
        
         //last message
         TextMessage lastRm = (TextMessage)cons1.receive(2000);
         assertNotNull(lastRm);
         assertEquals("-m"+(NUM_MSG-1), lastRm.getText());
        
         final ServerClientFailureCommand cmd = new ServerClientFailureCommand();
        
         Thread exeThr = new Thread()
         {
            public void run()
            {
               try
               {
                  ServerManagement.getServer().executeCommand(cmd);
               }
               catch (Exception e)
               {
                  log.error("failed to invoke command", e);
                  fail("failure in executing command.");
               }              
            }
         };
        
         exeThr.start();

         //ack last message, making server side ack happening.
         lastRm.acknowledge();

         //receive possible canceled messages
         TextMessage prm = null;
         conn2 = (JBossConnection)cf.createConnection();
         conn2.start();
         Session sess2 = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
         MessageConsumer cons2 = sess2.createConsumer(queue1);
         prm = (TextMessage)cons2.receive(2000);
         while (prm != null)
         {
            prm = (TextMessage)cons2.receive(2000);
         }
        
         //check message count
         //tearDown will do the check.
      }
      finally
      {
         if (conn1 != null)
         {
            conn1.close();
         }
         if (conn2 != null)
         {
            conn2.close();
         }
      }     
   }
View Full Code Here

     
      try
      {
         conn = cf.createConnection();
        
         JBossConnection jbConn = (JBossConnection)conn;
        
         ClientConnectionDelegate del = (ClientConnectionDelegate)jbConn.getDelegate();
        
         ConnectionState state = (ConnectionState)del.getState();
        
         ResourceManager rm = state.getResourceManager();
        
View Full Code Here

     
      try
      {
         conn = cf.createConnection();
        
         JBossConnection jbConn = (JBossConnection)conn;
        
         ClientConnectionDelegate del = (ClientConnectionDelegate)jbConn.getDelegate();
        
         ConnectionState state = (ConnectionState)del.getState();
        
         ResourceManager rm = state.getResourceManager();
        
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

      try
      {

         conn = cf.createXAConnection();

         JBossConnection jbConn = (JBossConnection)conn;

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

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

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

      try
      {

         conn = cf.createXAConnection();

         JBossConnection jbConn = (JBossConnection)conn;

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

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

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

      try
      {

         conn = cf.createXAConnection();

         JBossConnection jbConn = (JBossConnection)conn;

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

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

         ResourceManager rm = state.getResourceManager();
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.