FileDocCategorySizeDatePackage
JmsSessionFactoryImpl.javaAPI DocJBoss 4.2.111813Fri Jul 13 21:01:16 BST 2007org.jboss.resource.adapter.jms

JmsSessionFactoryImpl

public class JmsSessionFactoryImpl extends Object implements javax.resource.Referenceable, JmsSessionFactory
Implements the JMS Connection API and produces {@link JmsSession} objects.
author
Peter Antman.
author
Jason Dillon
author
Adrian Brock
version
$Revision: 57189 $

Fields Summary
private static final Logger
log
private boolean
closed
Are we closed?
private boolean
trace
Whether trace is enabled
private Reference
reference
private String
userName
private String
password
private String
clientID
private int
type
private boolean
started
private JmsManagedConnectionFactory
mcf
JmsRa own factory
private javax.resource.spi.ConnectionManager
cm
Hook to the appserver
private HashSet
sessions
The sessions
private HashSet
tempQueues
The temporary queues
private HashSet
tempTopics
The temporary topics
Constructors Summary
public JmsSessionFactoryImpl(javax.resource.spi.ManagedConnectionFactory mcf, javax.resource.spi.ConnectionManager cm, int type)

   
      
                                  
                                  
   
      this.mcf = (JmsManagedConnectionFactory) mcf;
      this.cm = cm;
      
      if (cm == null)
         // This is standalone usage, no appserver
         this.cm = new JmsConnectionManager();
      else 
         this.cm = cm;

      this.type = type;

      if (trace)
         log.trace("mcf=" + mcf + ", cm=" + cm + ", type=" + type);
   
Methods Summary
public voidaddTemporaryQueue(javax.jms.TemporaryQueue temp)

      synchronized(tempQueues)
      {
         tempQueues.add(temp);
      }
   
public voidaddTemporaryTopic(javax.jms.TemporaryTopic temp)

      synchronized(tempTopics)
      {
         tempTopics.add(temp);
      }
   
protected JmsSessionallocateConnection(boolean transacted, int acknowledgeMode, int sessionType)

      try
      {
         synchronized (sessions)
         {
            if (mcf.isStrict() && sessions.isEmpty() == false)
               throw new IllegalStateException("Only allowed one session per connection. See the J2EE spec, e.g. J2EE1.4 Section 6.6");
            if (transacted)
               acknowledgeMode = Session.SESSION_TRANSACTED;
            JmsConnectionRequestInfo info = new JmsConnectionRequestInfo(transacted, acknowledgeMode, sessionType);
            info.setUserName(userName);
            info.setPassword(password);
            info.setClientID(clientID);

            if (trace)
               log.trace("Allocating session for " + this + " with request info=" + info);
            JmsSession session = (JmsSession) cm.allocateConnection(mcf, info);
            if (trace)
               log.trace("Allocated  " + this + " session=" + session);
            session.setJmsSessionFactory(this);
            if (started)
               session.start();
            sessions.add(session);
            return session;
         }
      }
      catch (ResourceException e)
      {
         log.error("could not create session", e);
         
         JMSException je = new JMSException
            ("Could not create a session: " + e);
         je.setLinkedException(e);
         throw je;
      }               
   
protected voidcheckClosed()

      if (closed)
         throw new IllegalStateException("The connection is closed");
   
public voidclose()

      if (closed)
         return;
      closed = true;

      if (trace)
         log.trace("close() " + this);
      
      synchronized (sessions)
      {
         for (Iterator i = sessions.iterator(); i.hasNext();)
         {
            JmsSession session = (JmsSession) i.next();
            try
            {
               session.closeSession();
            }
            catch (Throwable t)
            {
               log.trace("Error closing session", t);
            }
            i.remove();
         }
      }
      
      synchronized (tempQueues)
      {
         for (Iterator i = tempQueues.iterator(); i.hasNext();)
         {
            TemporaryQueue temp = (TemporaryQueue) i.next();
            try
            {
               if (trace)
                  log.trace("Closing temporary queue " + temp + " for " + this);
               temp.delete();
            }
            catch (Throwable t)
            {
               log.trace("Error deleting temporary queue", t);
            }
            i.remove();
         }
      }
      
      synchronized (tempTopics)
      {
         for (Iterator i = tempTopics.iterator(); i.hasNext();)
         {
            TemporaryTopic temp = (TemporaryTopic) i.next();
            try
            {
               if (trace)
                  log.trace("Closing temporary topic " + temp + " for " + this);
               temp.delete();
            }
            catch (Throwable t)
            {
               log.trace("Error deleting temporary queue", t);
            }
            i.remove();
         }
      }
   
public voidcloseSession(JmsSession session)

      synchronized (sessions)
      {
         sessions.remove(session);
      }
   
public javax.jms.ConnectionConsumercreateConnectionConsumer(javax.jms.Destination destination, javax.jms.ServerSessionPool pool, int maxMessages)

      throw new IllegalStateException(ISE);
   
public javax.jms.ConnectionConsumercreateConnectionConsumer(javax.jms.Destination destination, java.lang.String name, javax.jms.ServerSessionPool pool, int maxMessages)

      throw new IllegalStateException(ISE);
   
public javax.jms.ConnectionConsumercreateConnectionConsumer(javax.jms.Queue queue, java.lang.String messageSelector, javax.jms.ServerSessionPool sessionPool, int maxMessages)

      throw new IllegalStateException(ISE);
   
public javax.jms.ConnectionConsumercreateConnectionConsumer(javax.jms.Topic topic, java.lang.String messageSelector, javax.jms.ServerSessionPool sessionPool, int maxMessages)

      throw new IllegalStateException(ISE);
   
public javax.jms.ConnectionConsumercreateDurableConnectionConsumer(javax.jms.Topic topic, java.lang.String subscriptionName, java.lang.String messageSelector, javax.jms.ServerSessionPool sessionPool, int maxMessages)

      throw new IllegalStateException(ISE);
   
public javax.jms.QueueSessioncreateQueueSession(boolean transacted, int acknowledgeMode)

      checkClosed();
      if (type == JmsConnectionFactory.TOPIC)
         throw new IllegalStateException("Can not get a queue session from a topic connection");
      return allocateConnection(transacted, acknowledgeMode, type);
   
public javax.jms.SessioncreateSession(boolean transacted, int acknowledgeMode)

      checkClosed();
      return allocateConnection(transacted, acknowledgeMode, type);
   
public javax.jms.TopicSessioncreateTopicSession(boolean transacted, int acknowledgeMode)

 
      checkClosed();
      if (type == JmsConnectionFactory.QUEUE)
         throw new IllegalStateException("Can not get a topic session from a queue connection");
      return allocateConnection(transacted, acknowledgeMode, type);
   
public java.lang.StringgetClientID()

      checkClosed();
      return clientID;
   
public javax.jms.ExceptionListenergetExceptionListener()

      throw new IllegalStateException(ISE);
   
public javax.jms.ConnectionMetaDatagetMetaData()

      checkClosed();
      return mcf.getMetaData();
   
public javax.naming.ReferencegetReference()

      return reference;
   
public voidsetClientID(java.lang.String cID)

      if (mcf.isStrict())
         throw new IllegalStateException(ISE);
      
      checkClosed();
      if (clientID != null)
         throw new IllegalStateException("Cannot change client id");
      clientID = cID;
   
public voidsetExceptionListener(javax.jms.ExceptionListener listener)

      throw new IllegalStateException(ISE);
   
public voidsetPassword(java.lang.String password)

      this.password = password;
   
public voidsetReference(javax.naming.Reference reference)

      this.reference = reference;
   
public voidsetUserName(java.lang.String name)

      userName = name;
   
public voidstart()

      checkClosed();
      if (trace)
         log.trace("start() " + this);
      synchronized (sessions)
      {
         if (started)
            return;
         started = true;
         for (Iterator i = sessions.iterator(); i.hasNext();)
         {
            JmsSession session = (JmsSession) i.next();
            session.start();
         }
      }
   
public voidstop()

      if (mcf.isStrict())
         throw new IllegalStateException(ISE);
      checkClosed();
      if (trace)
         log.trace("stop() " + this);
      synchronized (sessions)
      {
         if (started == false)
            return;
         started = true;
         for (Iterator i = sessions.iterator(); i.hasNext();)
         {
            JmsSession session = (JmsSession) i.next();
            session.stop();
         }
      }