Package org.jboss.jms.client.state

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


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

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

         remotingConnection.getConnectionListener().setConnectionState(connectionState);
         remotingConnection.getConnectionListener().start();
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();

      SessionState sessionState =
         new SessionState(connectionState, sessionDelegate, transacted,
                          ackMode, xa, sessionDelegate.getDupsOKBatchSize(),
                          connectionState.isEnableOrderingGroup(), connectionState.getDefaultOrderingGroupName());

      delegate.setState(sessionState);
      return delegate;
   }
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

         if (state.isXA())
         {
            throw new TransactionInProgressException("Cannot call rollback on an XA session");
         }
        
         ConnectionState connState = (ConnectionState)state.getParent();
         ResourceManager rm = connState.getResourceManager();
         try
         {
            rm.rollbackLocal((LocalTx)state.getCurrentTxId());
         }
         finally
View Full Code Here

      {
         // the session is non-XA and transacted, or XA and enrolled in a global transaction, so
         // we add the message to a transaction instead of sending it now. An XA session that has
         // not been enrolled in a global transaction behaves as a non-transacted session.

         ConnectionState connState = (ConnectionState)state.getParent();
         MethodInvocation mi = (MethodInvocation)invocation;
         Message m = (Message)mi.getArguments()[0];

         if (trace) { log.trace("sending message " + m + " transactionally, queueing on resource manager txID=" + txID + " sessionID= " + state.getSessionID()); }

         connState.getResourceManager().addMessage(txID, state.getSessionID(), (JBossMessage)m);

         // ... and we don't invoke any further interceptors in the stack
         return null;
      }
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

      boolean isCC = ((Boolean)mi.getArguments()[4]).booleanValue();

      // Create the message handler
      SessionState sessionState =
         (SessionState)((DelegateSupport)invocation.getTargetObject()).getState();
      ConnectionState connectionState = (ConnectionState)sessionState.getParent();
      SessionDelegate sessionDelegate = (SessionDelegate)invocation.getTargetObject();
      ConsumerState consumerState = (ConsumerState)((DelegateSupport)consumerDelegate).getState();
      String consumerID = consumerState.getConsumerID();
      int prefetchSize = consumerState.getBufferSize();
      Executor executor = sessionState.getExecutor();
      int maxDeliveries = consumerState.getMaxDeliveries();
      long redeliveryDelay = consumerState.getRedeliveryDelay();
     
      //We need the queue name for recovering any deliveries after failover
      String queueName = null;
      if (consumerState.getSubscriptionName() != null)
      {
         // I have to use the clientID from connectionDelegate instead of connectionState...
         // this is because when a pre configured CF is used we need to get the clientID from
         // server side.
         // This was a condition verified by the TCK and it was fixed as part of
         // http://jira.jboss.com/jira/browse/JBMESSAGING-939
         queueName = MessageQueueNameHelper.
            createSubscriptionName(((ConnectionDelegate)connectionState.getDelegate()).getClientID(),
                                   consumerState.getSubscriptionName());
      }
      else if (consumerState.getDestination().isQueue())
      {
         queueName = consumerState.getDestination().getName();
      }
     
      boolean autoFlowControl = ((Boolean)mi.getArguments()[5]).booleanValue();
     
      ClientConsumer messageHandler =
         new ClientConsumer(isCC, sessionState.getAcknowledgeMode(),
                            sessionDelegate, consumerDelegate, consumerID, queueName,
                            prefetchSize, executor, maxDeliveries, consumerState.isShouldAck(),
                            redeliveryDelay);
     
      sessionState.addCallbackHandler(messageHandler);
     
      CallbackManager cm = connectionState.getRemotingConnection().getCallbackManager();
      cm.registerHandler(consumerID, messageHandler);
        
      consumerState.setClientConsumer(messageHandler);
     
      if (autoFlowControl)
View Full Code Here

         // First we call close on the ClientConsumer which waits for onMessage invocations
         // to complete and the last delivery to arrive
         consumerState.getClientConsumer().close(lastDeliveryId);

         SessionState sessionState = (SessionState) consumerState.getParent();
         ConnectionState connectionState = (ConnectionState) sessionState.getParent();

         sessionState.removeCallbackHandler(consumerState.getClientConsumer());

         CallbackManager cm = connectionState.getRemotingConnection().getCallbackManager();
         cm.unregisterHandler(consumerState.getConsumerID());

         //And then we cancel any messages still in the message callback handler buffer
         consumerState.getClientConsumer().cancelBuffer();

         return l;

      }
      catch (Exception proxiedException)
      {
         ConnectionState connectionState = (ConnectionState) (consumerState.getParent().getParent());
         // if ServerPeer is shutdown or
         // if there is no failover in place... we just close the consumerState as well
         if (proxiedException instanceof MessagingShutdownException ||
                 (connectionState.getFailoverCommandCenter() == null))


         {
            if (!consumerState.getClientConsumer().isClosed())
            {
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.