Package org.jboss.jms.client

Examples of org.jboss.jms.client.JBossSession


   public void testDupsOKBatchDefault() throws Exception
   {
      //test default
      Connection conn = cf.createConnection();
     
      JBossSession sess = (JBossSession)conn.createSession(false, Session.DUPS_OK_ACKNOWLEDGE);
     
      ClientSessionDelegate del = (ClientSessionDelegate)sess.getDelegate();
     
      assertEquals(1000, del.getDupsOKBatchSize());
     
      conn.close();
   }
View Full Code Here


    * This test was created as per http://jira.jboss.org/jira/browse/JBMESSAGING-685.
    */
   public void testEmptyCommit() throws Exception
   {
      Connection conn = cf.createConnection();
      JBossSession session = (JBossSession)conn.createSession(true, Session.SESSION_TRANSACTED);
      session.commit();
      conn.close();
   }
View Full Code Here

         (JBossConnection) getConnection(new Connection[]{conn1, conn2}, 1);

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

      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");
      JBossMessageConsumer jbossConsumerHA = (JBossMessageConsumer) consumerHA;

      org.jboss.jms.client.delegate.ClientConsumerDelegate clientDelegate =
         (org.jboss.jms.client.delegate.ClientConsumerDelegate) jbossConsumerHA.getDelegate();
      ConsumerState consumerState = (ConsumerState) clientDelegate.getState();

      log.info("subscriptionName=" + consumerState.getSubscriptionName());

      log.info(">>Creating Producer");
      MessageProducer producer = session.createProducer(destination);
      log.info(">>creating Message");
      Message message = session.createTextMessage("Hello Before");
      log.info(">>sending Message");
      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);

      Thread.sleep(60000);
      // if failover happened, this object was replaced
      assertNotSame(originalRemoting, delegate.getRemotingConnection());

      //System.out.println("Kill server1"); Thread.sleep(10000);

      message = session.createTextMessage("Hello After");
      log.info(">>Sending new message");
      producer.send(message);

      assertEquals(txID, sessionState.getCurrentTxId());
      System.out.println("TransactionID on client = " + txID);
      log.info(">>Final commit");

      session.commit();

      log.info("Calling alternate receiver");
      receiveMessage("consumerHA", consumerHA, true, false);
      receiveMessage("consumerHA", consumerHA, true, false);
      receiveMessage("consumerHA", consumerHA, true, true);

      session.commit();
      conn1.close();
      conn2.close();
   }
View Full Code Here

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

         ResourceManager rm = state.getResourceManager();

         // Create a session
         JBossSession sess1 = (JBossSession)conn.createXASession();
         DummyListener listener = new DummyListener();
         sess1.setMessageListener(listener);
         conn.start();
         MessagingXAResource res1 = (MessagingXAResource)sess1.getXAResource();
         tm.begin();

         Transaction trans = tm.getTransaction();
         trans.enlistResource(res1);
         trans.delistResource(res1, XAResource.TMSUCCESS);
         MessageProducer p = sess1.createProducer(queue1);
         MessageConsumer cons = sess1.createConsumer(queue1);
         conn.start();
         // send 10 messages
         for (int i = 0; i < 10; i++)
         {
            TextMessage message = sess1.createTextMessage("delistedwork" + i);
            p.send(message);
         }
         // now receive 5
         for (int i = 0; i < 5; i++)
         {
            TextMessage textMessage = (TextMessage)cons.receive();
            assertEquals("delistedwork" + i, textMessage.getText());
         }
         // once we enlist ensure that the 5 acks are merged ok, the first timne we do this there is nothing to merge in
         // the global tx
         // so all acks are just copied
         trans.enlistResource(res1);
         SessionState sstate = (SessionState)((DelegateSupport)sess1.getDelegate()).getState();
         ClientTransaction clientTransaction = rm.getTx(sstate.getCurrentTxId());
         assertEquals("to many session states", clientTransaction.getSessionStates().size(), 1);
         ClientTransaction.SessionTxState sessionTxState = (ClientTransaction.SessionTxState)clientTransaction.getSessionStates()
                                                                                                              .get(0);
         assertEquals("wrong number of acks", 5, sessionTxState.getAcks().size());
View Full Code Here

         // Starts a new transaction
         tm.begin();

         Transaction trans = tm.getTransaction();

         JBossSession session = (JBossSession)xasession;
         SessionState state = (SessionState)((DelegateSupport)session.getDelegate()).getState();

         // Validates TX convertion
         assertTrue(state.getCurrentTxId() instanceof LocalTx);

         // Enlist the transaction... as supposed to be happening on JBossAS with the
View Full Code Here

     
      try
      {       
        conn = cf.createConnection();
       
        JBossSession sess = (JBossSession)conn.createSession(false, Session.DUPS_OK_ACKNOWLEDGE);
       
        ClientSessionDelegate del = (ClientSessionDelegate)sess.getDelegate();
       
        assertEquals(1000, del.getDupsOKBatchSize());
      }
      finally
      {
View Full Code Here

    * This test was created as per http://jira.jboss.org/jira/browse/JBMESSAGING-685.
    */
   public void testEmptyCommit() throws Exception
   {
      Connection conn = cf.createConnection();
      JBossSession session = (JBossSession)conn.createSession(true, Session.SESSION_TRANSACTED);
      session.commit();
      conn.close();
   }
View Full Code Here

      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)
         {
View Full Code Here

            }
         }
        
         if (forwardMode == FORWARD_MODE_XA && sourceSession instanceof JBossSession)
         {
           JBossSession jsession = (JBossSession)sourceSession;
          
           SessionState sstate = (SessionState)((DelegateSupport)jsession.getDelegate()).getState();
           
           sstate.setTreatAsNonTransactedWhenNotEnlisted(false);
         }
           
         if (subName == null)
View Full Code Here

      //If not XA then we use a client ack session for consuming - this allows us to get the message, send it to the destination
      //then ack the message.
      //This means that if a failure occurs between sending and acking the message won't be lost but may get delivered
      //twice - i.e we have dups_ok behaviour
     
      JBossSession sess = (JBossSession)sourceConnection.createSession(false, Session.CLIENT_ACKNOWLEDGE);
   
      sourceSession = (SessionDelegate)sess.getDelegate();
           
      sess = (JBossSession)localConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
     
      localSession = (SessionDelegate)sess.getDelegate();
    }
    else
    {
      JBossSession sess = (JBossSession)sourceConnection.createXASession();
     
      sourceSession = (SessionDelegate)sess.getDelegate();
     
      sess = (JBossSession)localConnection.createXASession();
     
      localSession = (SessionDelegate)sess.getDelegate();
    }
           
    JBossDestination dest = new JBossQueue(localQueue.getName(), true);
       
    producer = localSession.createProducerDelegate(dest);
View Full Code Here

TOP

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

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.