Package org.jboss.jms.client.state

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


      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());

      delegate.setState(sessionState);
      return delegate;
   }
View Full Code Here


   public Object handleCreateConsumerDelegate(Invocation invocation) throws Throwable
   {
      ClientConsumerDelegate consumerDelegate = (ClientConsumerDelegate)invocation.invokeNext();
      DelegateSupport delegate = (DelegateSupport)consumerDelegate;

      SessionState sessionState = (SessionState)getState(invocation);

      MethodInvocation mi = (MethodInvocation)invocation;
      JBossDestination dest = (JBossDestination)mi.getArguments()[0];
      String selector = (String)mi.getArguments()[1];
      boolean noLocal = ((Boolean)mi.getArguments()[2]).booleanValue();
View Full Code Here

      // ProducerDelegates are not created on the server

      ProducerDelegate producerDelegate = new ClientProducerDelegate();
      DelegateSupport delegate = (DelegateSupport)producerDelegate;

      SessionState sessionState = (SessionState)getState(invocation);

      MethodInvocation mi = (MethodInvocation)invocation;
      Destination dest = ((Destination)mi.getArguments()[0]);

      ProducerState producerState = new ProducerState(sessionState, producerDelegate, dest);
View Full Code Here

      MethodInvocation mi = (MethodInvocation)invocation;

      ClientBrowserDelegate browserDelegate = (ClientBrowserDelegate)invocation.invokeNext();
      DelegateSupport delegate = (DelegateSupport)browserDelegate;

      SessionState sessionState = (SessionState)getState(invocation);

      JBossDestination destination = (JBossDestination)mi.getArguments()[0];
      String selector = (String)mi.getArguments()[1];

      BrowserState state =
View Full Code Here

         }
      }

      m.setJMSDestination(destination);
     
      SessionState sessionState = (SessionState)producerState.getParent();
                 
      // Generate the message id
      ConnectionState connectionState = (ConnectionState)sessionState.getParent();
     
      long id =
         connectionState.getIdGenerator().getId((ConnectionDelegate)connectionState.getDelegate());
   
      JBossMessage messageToSend;
      boolean foreign = false;

      if (!(m instanceof MessageProxy))
      {
         // it's a foreign message

         foreign = true;
        
         // JMS 1.1 Sect. 3.11.4: A provider must be prepared to accept, from a client,
         // a message whose implementation is not one of its own.

         // create a matching JBossMessage Type from JMS Type
         if(m instanceof BytesMessage)
         {
            messageToSend = new JBossBytesMessage((BytesMessage)m,0);
         }
         else if(m instanceof MapMessage)
         {
            messageToSend = new JBossMapMessage((MapMessage)m,0);
         }
         else if(m instanceof ObjectMessage)
         {
            messageToSend = new JBossObjectMessage((ObjectMessage)m,0);
         }
         else if(m instanceof StreamMessage)
         {
            messageToSend = new JBossStreamMessage((StreamMessage)m,0);
         }
         else if(m instanceof TextMessage)
         {
            messageToSend = new JBossTextMessage((TextMessage)m,0);
         }
         else
         {
            messageToSend = new JBossMessage(m, 0);
         }
        
         messageToSend.setJMSMessageID(null);
      }
      else
      {
         // get the actual message
         MessageProxy proxy = (MessageProxy)m;
                                   
         //The following line executed on the proxy should cause a copy to occur
         //if it is necessary
         proxy.setJMSMessageID(null);
        
         //Get the underlying message
         messageToSend = proxy.getMessage();    
        
         proxy.beforeSend();
      }
     
      // Set the new id
     
      messageToSend.setMessageId(id);
     
      // This only really used for BytesMessages and StreamMessages to reset their state
      messageToSend.doBeforeSend();
     
      // now that we know the messageID, set it also on the foreign message, if is the case
      if (foreign)
      {
         m.setJMSMessageID(messageToSend.getJMSMessageID());
      }
           
      // we now invoke the send(Message) method on the session, which will eventually be fielded
      // by connection endpoint
      ((SessionDelegate)sessionState.getDelegate()).send(messageToSend, false);
     
      return null;
   }
View Full Code Here

      ConsumerDelegate consumerDelegate = (ConsumerDelegate)invocation.invokeNext();

      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();
      int consumerID = consumerState.getConsumerID();
      int prefetchSize = consumerState.getBufferSize();
      QueuedExecutor sessionExecutor = sessionState.getExecutor();
      int maxDeliveries = consumerState.getMaxDeliveries();
     
      //We need the queue name for recovering any deliveries after failover
      String queueName = null;
      if (consumerState.getSubscriptionName() != null)
      {
         queueName = MessageQueueNameHelper.
            createSubscriptionName(connectionState.getClientID(),
                                   consumerState.getSubscriptionName());
      }
      else if (consumerState.getDestination().isQueue())
      {
         queueName = consumerState.getDestination().getName();
      }
     
      MessageCallbackHandler messageHandler =
         new MessageCallbackHandler(isCC, sessionState.getAcknowledgeMode(),
                                    sessionDelegate, consumerDelegate, consumerID, queueName,
                                    prefetchSize, sessionExecutor, maxDeliveries);
     
      sessionState.addCallbackHandler(messageHandler);
     
      CallbackManager cm = connectionState.getRemotingConnection().getCallbackManager();
      cm.registerHandler(consumerID, messageHandler);
        
      consumerState.setMessageCallbackHandler(messageHandler);
View Full Code Here

     
      // First we call close on the messagecallbackhandler which waits for onMessage invocations     
      // to complete and the last delivery to arrive
      consumerState.getMessageCallbackHandler().close(lastDeliveryId);
               
      SessionState sessionState = (SessionState)consumerState.getParent();
      ConnectionState connectionState = (ConnectionState)sessionState.getParent();
                
      sessionState.removeCallbackHandler(consumerState.getMessageCallbackHandler());

      CallbackManager cm = connectionState.getRemotingConnection().getCallbackManager();
      cm.unregisterHandler(consumerState.getConsumerID());
        
      //And then we cancel any messages still in the message callback handler buffer    
View Full Code Here

  
   // XASession implementation
  
   public Session getSession() throws JMSException
   {     
      SessionState state = (SessionState)((DelegateSupport)delegate).getState();
      if (!state.isXA())
      {
         throw new IllegalStateException("Isn't an XASession");
      }
     
      return this;
View Full Code Here

   // Public --------------------------------------------------------
  
   public Object handleClosing(Invocation invocation) throws Throwable
   {
      MethodInvocation mi = (MethodInvocation)invocation;
      SessionState state = getState(invocation);
      SessionDelegate del = (SessionDelegate)mi.getTargetObject();
           
      if (trace) { log.trace("handleClosing()"); }

      //Sanity check
      if (state.isXA())
      {
         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)
      {
         //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
            {
               del.acknowledgeDeliveries(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

  
   public Object handleClose(Invocation invocation) throws Throwable
   {     
      Object res = invocation.invokeNext();
     
      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();

      return res;
   }
View Full Code Here

TOP

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

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.