Package org.jboss.jms.client.state

Examples of org.jboss.jms.client.state.ConnectionState


         JBossConnection jbc = (JBossConnection)conn;

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

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

         int initialServerID = state.getServerID();

         assertEquals(1, initialServerID);

         Session sess = conn.createSession(true, Session.SESSION_TRANSACTED);

         MessageProducer prod = sess.createProducer(queue[1]);

         MessageConsumer cons = sess.createConsumer(queue[1]);

         final int NUM_MESSAGES = 100;

         for (int i = 0; i < NUM_MESSAGES; i++)
         {
            TextMessage tm = sess.createTextMessage("message:" + i);

            prod.send(tm);
         }

         sess.commit();

         conn.start();

         //Now consume half of the messages but don't commit them these will end up in
         //client side resource manager

         for (int i = 0; i < NUM_MESSAGES / 2; i++)
         {
            TextMessage tm = (TextMessage)cons.receive(2000);

            assertNotNull(tm);

            assertEquals("message:" + i, tm.getText());
         }

         //So now, messages should be in queue[1] on server 1
         //So we now kill server 1
         //Which should cause transparent failover of connection conn onto server 2
        
         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");
            }
         }
         state = (ConnectionState)del.getState();

         int finalServerID = state.getServerID();

         conn.start();

         //Now should be able to consume the rest of the messages
View Full Code Here


      assertEquals(1, getServerId(conn1));
     
      assertEquals(0, getServerId(conn2));

      ConnectionState state = this.getConnectionState(conn1);

      // Disable Leasing for Failover
      state.getRemotingConnection().removeConnectionListener();

      ServerManagement.kill(1);

      Thread.sleep(20000);
View Full Code Here

      // this is a bit counterintuitve, as we're not copying from new delegate, but modifying its
      // state based on the old state. It makes sense, since in the end the state makes it to the
      // server

      ConnectionState thisState = (ConnectionState)state;

      if (thisState.getClientID() != null)
      {
         newDelegate.setClientID(thisState.getClientID());
      }

      // synchronize (recursively) the client-side state

      state.synchronizeWith(newDelegate.getState());

      // synchronize the delegates

      remotingConnection = newDelegate.getRemotingConnection();
      versionToUse = newDelegate.getVersionToUse();

      // There is one RM per server, so we need to merge the rms if necessary
      ResourceManagerFactory.instance.handleFailover(serverID, newDelegate.getServerID());

      client = thisState.getRemotingConnection().getRemotingClient();

      serverID = newDelegate.getServerID();
   }
View Full Code Here

         if (versionToUse == null)
         {
            throw new IllegalStateException("Connection version is null");
         }

         ConnectionState connectionState =
            new ConnectionState(serverID, connectionDelegate,
                                remotingConnection, versionToUse);

         listener.setConnectionState(connectionState);
         
         connectionDelegate.setState(connectionState);
View Full Code Here

   public Object handleCreateSessionDelegate(Invocation invocation) throws Throwable
   {
      ClientSessionDelegate sessionDelegate = (ClientSessionDelegate)invocation.invokeNext();
      DelegateSupport delegate = (DelegateSupport)sessionDelegate;

      ConnectionState connectionState = (ConnectionState)getState(invocation);

      MethodInvocation mi = (MethodInvocation)invocation;
      boolean transacted = ((Boolean)mi.getArguments()[0]).booleanValue();
      int ackMode = ((Integer)mi.getArguments()[1]).intValue();
      boolean xa = ((Boolean)mi.getArguments()[2]).booleanValue();
View Full Code Here

               log.trace(this + " got local connection delegate " + cd);
              
               if (supportsFailover)
               {
                 ConnectionState state = (ConnectionState)((DelegateSupport)cd).getState();
 
                 state.initializeFailoverCommandCenter();
 
                 FailoverCommandCenter fcc = state.getFailoverCommandCenter();
 
                 // add a connection listener to detect failure; the consolidated remoting connection
                 // listener must be already in place and configured
                 state.getRemotingConnection().getConnectionListener().
                    setDelegateListener(new ConnectionFailureListener(fcc, state.getRemotingConnection()));
 
                 log.trace(this + " installed failure listener on " + cd);
 
                 // also cache the username and the password into state, useful in case
                 // FailoverCommandCenter needs to create a new connection instead of a failed on
                 state.setUsername(username);
                 state.setPassword(password);
 
                 // also add a reference to the clustered ConnectionFactory delegate, useful in case
                 // FailoverCommandCenter needs to create a new connection instead of a failed on
                 state.setClusteredConnectionFactoryDeleage(clusteredDelegate);
                
                 log.trace("Successfully initialised new connection");
               }

               return res;
View Full Code Here

      //Sanity check
      if (state.isXA() && !isXAAndConsideredNonTransacted(state))
      {
         if (trace) { log.trace("Session is XA"); }
        
         ConnectionState connState = (ConnectionState)state.getParent();
        
         ResourceManager rm = connState.getResourceManager();
        
         // An XASession should never be closed if there is prepared ack work that has not yet been
         // committed or rolled back. Imagine if messages had been consumed in the session, and
         // prepared but not committed. Then the connection was explicitly closed causing the
         // session to close. Closing the session causes any outstanding delivered but unacked
         // messages to be cancelled to the server which means they would be available for other
         // consumers to consume. If another consumer then consumes them, then recover() is called
         // and the original transaction is committed, then this means the same message has been
         // delivered twice which breaks the once and only once delivery guarantee.
        
         if (rm.checkForAcksInSession(state.getSessionID()))
         {
            throw new IllegalStateException(
               "Attempt to close an XASession when there are still uncommitted acknowledgements!");
         }       
      }
           
      int ackMode = state.getAcknowledgeMode();
 
      //We need to either ack (for auto_ack) or cancel (for client_ack)
      //any deliveries - this is because the message listener might have closed
      //before on message had finished executing
     
      if (ackMode == Session.AUTO_ACKNOWLEDGE || isXAAndConsideredNonTransacted(state))
      {
         //Acknowledge or cancel any outstanding auto ack
       
         DeliveryInfo remainingAutoAck = state.getAutoAckInfo();
        
         if (remainingAutoAck != null)
         {
            if (trace) { log.trace(this + " handleClosing(). Found remaining auto ack. Will ack " + remainingAutoAck); }
           
            try
            {
               ackDelivery(del, remainingAutoAck);
              
               if (trace) { log.trace(this + " acked it"); }              
            }
            finally
            {                       
               state.setAutoAckInfo(null);
            }
         }
      }
      else if (ackMode == Session.DUPS_OK_ACKNOWLEDGE)
      {
         //Ack any remaining deliveries
                         
         if (!state.getClientAckList().isEmpty())
         {              
            try
            {
               acknowledgeDeliveries(del, state.getClientAckList());
            }
            finally
            {           
               state.getClientAckList().clear();
              
               state.setAutoAckInfo(null);
            }
         }
      }
      else if (ackMode == Session.CLIENT_ACKNOWLEDGE)
      {
         // Cancel any oustanding deliveries
         // We cancel any client ack or transactional, we do this explicitly so we can pass the
         // updated delivery count information from client to server. We could just do this on the
         // server but we would lose delivery count info.
                 
         // CLIENT_ACKNOWLEDGE cannot be used with MDBs (i.e. no connection consumer)
         // so is always safe to cancel on this session                 
        
         cancelDeliveries(del, state.getClientAckList());
        
         state.getClientAckList().clear();
      }
      else if (state.isTransacted() && !state.isXA())
      {
         //We need to explicitly cancel any deliveries back to the server
         //from the resource manager, otherwise delivery count won't be updated
        
         ConnectionState connState = (ConnectionState)state.getParent();
        
         ResourceManager rm = connState.getResourceManager();
        
         List dels = rm.getDeliveriesForSession(state.getSessionID());
        
         cancelDeliveries(del, dels);       
      }
View Full Code Here

     }
     finally
     {        
         SessionState state = getState(invocation);
  
         ConnectionState connState = (ConnectionState)state.getParent();
  
         Object xid = state.getCurrentTxId();
  
         if (xid != null)
         {
            //Remove transaction from the resource manager
            connState.getResourceManager().removeTx(xid);
         }
  
         // We must explicitly shutdown the executor
  
         state.getExecutor().shutdownNow();
View Full Code Here

            {
               // the session is non-XA and transacted, or XA and enrolled in a global transaction. An
               // XA session that has not been enrolled in a global transaction behaves as a
               // transacted session.
              
               ConnectionState connState = (ConnectionState)state.getParent();
     
               if (trace) { log.trace("sending acknowlegment transactionally, queueing on resource manager"); }
     
               // If the ack is for a delivery that came through via a connection consumer then we use
               // the connectionConsumer session as the session id, otherwise we use this sessions'
               // session ID
              
               ClientSessionDelegate connectionConsumerDelegate =
                  (ClientSessionDelegate)info.getConnectionConsumerSession();
              
               String sessionId = connectionConsumerDelegate != null ?
                  connectionConsumerDelegate.getID() : state.getSessionID();
              
               connState.getResourceManager().addAck(txID, sessionId, info);
            }       
         }
      }
     
      return null;
View Full Code Here

         if (state.isXA())
         {
            throw new TransactionInProgressException("Cannot call commit on an XA session");
         }
  
         ConnectionState connState = (ConnectionState)state.getParent();
         ConnectionDelegate conn = (ConnectionDelegate)connState.getDelegate();
    
         try
         {
            connState.getResourceManager().commitLocal((LocalTx)state.getCurrentTxId(), conn);
         }
         finally
         {
            //Start new local tx
            Object xid = connState.getResourceManager().createLocalTx();
  
            state.setCurrentTxId(xid);
         }
        
         //TODO on commit we don't want to ACK any messages that have exceeded the max delivery count OR
View Full Code Here

TOP

Related Classes of org.jboss.jms.client.state.ConnectionState

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.