FileDocCategorySizeDatePackage
JmsServerSession.javaAPI DocJBoss 4.2.113772Fri Jul 13 21:01:16 BST 2007org.jboss.resource.adapter.jms.inflow

JmsServerSession

public class JmsServerSession extends Object implements javax.jms.ServerSession, javax.jms.MessageListener, javax.resource.spi.work.Work, javax.resource.spi.work.WorkListener
A generic jms session pool.
author
Adrian Brock
author
Omit source code)

');
Fields Summary
private static final Logger
log
The log
JmsServerSessionPool
pool
The session pool
boolean
transacted
The transacted flag
int
acknowledge
The acknowledge mode
javax.jms.Session
session
The session
javax.jms.XASession
xaSession
Any XA session
javax.resource.spi.endpoint.MessageEndpoint
endpoint
The endpoint
DLQHandler
dlqHandler
Any DLQ handler
TransactionDemarcationStrategy
txnStrategy
Constructors Summary
public JmsServerSession(JmsServerSessionPool pool)
Create a new JmsServerSession

param
pool the server session pool


                  
     
   
      this.pool = pool;

   
Methods Summary
private org.jboss.resource.adapter.jms.inflow.JmsServerSession$TransactionDemarcationStrategycreateTransactionDemarcation()

      return new DemarcationStrategyFactory().getStrategy();

   
public javax.jms.SessiongetSession()

      return session;
   
public voidonMessage(javax.jms.Message message)

      try
      {
         endpoint.beforeDelivery(JmsActivation.ONMESSAGE);

         try
         {
            if (dlqHandler == null || dlqHandler.handleRedeliveredMessage(message) == false)
            {
               MessageListener listener = (MessageListener) endpoint;
               listener.onMessage(message);
            }
         }
         finally
         {
            endpoint.afterDelivery();

            if (dlqHandler != null)
               dlqHandler.messageDelivered(message);
         }
      }

      catch (Throwable t)
      {
         log.error("Unexpected error delivering message " + message, t);

         if (txnStrategy != null)
            txnStrategy.error();

      }

   
public voidrelease()

   
public voidrun()


      try
      {
         txnStrategy = createTransactionDemarcation();

      }
      catch (Throwable t)
      {
         log.error("Error creating transaction demarcation. Cannot continue.");
         return;
      }

      try
      {
         session.run();
      }
      catch (Throwable t)
      {
         if (txnStrategy != null)
            txnStrategy.error();

      }
      finally
      {
         if (txnStrategy != null)
            txnStrategy.end();

         txnStrategy = null;
      }

   
public voidsetup()
Setup the session

      JmsActivation activation = pool.getActivation();
      JmsActivationSpec spec = activation.getActivationSpec();

      dlqHandler = activation.getDLQHandler();

      Connection connection = activation.getConnection();

      // Create the session
      if (connection instanceof XAConnection && activation.isDeliveryTransacted())
      {
         xaSession = ((XAConnection) connection).createXASession();
         session = xaSession.getSession();
      }
      else
      {
         transacted = spec.isSessionTransacted();
         acknowledge = spec.getAcknowledgeModeInt();
         session = connection.createSession(transacted, acknowledge);
      }

      // Get the endpoint
      MessageEndpointFactory endpointFactory = activation.getMessageEndpointFactory();
      XAResource xaResource = null;

      if (activation.isDeliveryTransacted() && xaSession != null)
         xaResource = xaSession.getXAResource();

      endpoint = endpointFactory.createEndpoint(xaResource);

      // Set the message listener
      session.setMessageListener(this);
   
public voidstart()

      JmsActivation activation = pool.getActivation();
      WorkManager workManager = activation.getWorkManager();
      try
      {
         workManager.scheduleWork(this, 0, null, this);
      }
      catch (WorkException e)
      {
         log.error("Unable to schedule work", e);
         throw new JMSException("Unable to schedule work: " + e.toString());
      }
   
public voidteardown()
Stop the session

      try
      {
         if (endpoint != null)
            endpoint.release();
      }
      catch (Throwable t)
      {
         log.debug("Error releasing endpoint " + endpoint, t);
      }

      try
      {
         if (xaSession != null)
            xaSession.close();
      }
      catch (Throwable t)
      {
         log.debug("Error releasing xaSession " + xaSession, t);
      }

      try
      {
         if (session != null)
            session.close();
      }
      catch (Throwable t)
      {
         log.debug("Error releasing session " + session, t);
      }
   
public voidworkAccepted(javax.resource.spi.work.WorkEvent e)

   
public voidworkCompleted(javax.resource.spi.work.WorkEvent e)

      pool.returnServerSession(this);
   
public voidworkRejected(javax.resource.spi.work.WorkEvent e)

      pool.returnServerSession(this);
   
public voidworkStarted(javax.resource.spi.work.WorkEvent e)