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

JmsManagedConnectionFactory

public class JmsManagedConnectionFactory extends Object implements javax.resource.spi.ManagedConnectionFactory
Jms ManagedConectionFactory
author
Peter Antman .
author
Adrian Brock
version
$Revision: 57189 $

Fields Summary
private static final long
serialVersionUID
private static final Logger
log
private JmsMCFProperties
mcfProperties
Settable attributes in ra.xml
private boolean
strict
Whether we are strict
private org.jboss.jms.jndi.JMSProviderAdapter
adapter
For local access.
Constructors Summary
public JmsManagedConnectionFactory()


    
   
      // empty
   
Methods Summary
public java.lang.ObjectcreateConnectionFactory()
Create a "non managed" connection factory. No appserver involved

      return createConnectionFactory(null);
   
public java.lang.ObjectcreateConnectionFactory(javax.resource.spi.ConnectionManager cxManager)
Create a ConnectionFactory with appserver hook

      Object cf = new JmsConnectionFactoryImpl(this, cxManager);

      if (log.isTraceEnabled())
      {
         log.trace("Created connection factory: " + cf + ", using connection manager: " + cxManager);
      }

      return cf;
   
public javax.resource.spi.ManagedConnectioncreateManagedConnection(javax.security.auth.Subject subject, javax.resource.spi.ConnectionRequestInfo info)
Create a new connection to manage in pool

      boolean trace = log.isTraceEnabled();

      info = getInfo(info);
      if (trace)
         log.trace("connection request info: " + info);

      JmsCred cred = JmsCred.getJmsCred(this, subject, info);
      if (trace)
         log.trace("jms credentials: " + cred);

      // OK we got autentication stuff
      JmsManagedConnection mc = new JmsManagedConnection(this, info, cred.name, cred.pwd);

      if (trace)
         log.trace("created new managed connection: " + mc);

      return mc;
   
public booleanequals(java.lang.Object obj)
Checks for equality ower the configured properties.

      if (obj == null)
         return false;
      if (obj instanceof JmsManagedConnectionFactory)
      {
         return mcfProperties.equals(((JmsManagedConnectionFactory) obj).getProperties());
      }
      else
      {
         return false;
      }
   
public java.lang.StringgetClientID()
Get client id, may be null.

      return mcfProperties.getClientID();
   
private javax.resource.spi.ConnectionRequestInfogetInfo(javax.resource.spi.ConnectionRequestInfo info)

      if (info == null)
      {
         // Create a default one
         return new JmsConnectionRequestInfo(mcfProperties);
      }
      else
      {
         // Fill the one with any defaults
         ((JmsConnectionRequestInfo) info).setDefaults(mcfProperties);
         return info;
      }
   
public org.jboss.jms.jndi.JMSProviderAdaptergetJmsProviderAdapter()

      return adapter;
   
public java.lang.StringgetJmsProviderAdapterJNDI()

      return mcfProperties.getProviderJNDI();
   
public java.io.PrintWritergetLogWriter()

      // 
      // jason: screw the logWriter stuff for now it sucks ass
      //

      return null;
   
public javax.jms.ConnectionMetaDatagetMetaData()

      return new JmsConnectionMetaData();
   
public java.lang.StringgetPassword()
Get password, may be null.

      return mcfProperties.getPassword();
   
protected JmsMCFPropertiesgetProperties()

      return mcfProperties;
   
public java.lang.StringgetSessionDefaultType()

      return mcfProperties.getSessionDefaultType();
   
public java.lang.StringgetUserName()
Get userName, may be null.

      return mcfProperties.getUserName();
   
public inthashCode()

      return mcfProperties.hashCode();
   
public booleanisStrict()

      return strict;
   
public javax.resource.spi.ManagedConnectionmatchManagedConnections(java.util.Set connectionSet, javax.security.auth.Subject subject, javax.resource.spi.ConnectionRequestInfo info)
Match a set of connections from the pool

      boolean trace = log.isTraceEnabled();

      // Get cred
      info = getInfo(info);
      JmsCred cred = JmsCred.getJmsCred(this, subject, info);

      if (trace)
         log.trace("Looking for connection matching credentials: " + cred);

      // Traverse the pooled connections and look for a match, return first
      // found
      Iterator connections = connectionSet.iterator();

      while (connections.hasNext())
      {
         Object obj = connections.next();

         // We only care for connections of our own type
         if (obj instanceof JmsManagedConnection)
         {
            // This is one from the pool
            JmsManagedConnection mc = (JmsManagedConnection) obj;

            // Check if we even created this on
            ManagedConnectionFactory mcf = mc.getManagedConnectionFactory();

            // Only admit a connection if it has the same username as our
            // asked for creds

            // FIXME, Here we have a problem, jms connection
            // may be anonymous, have a user name

            if ((mc.getUserName() == null || (mc.getUserName() != null && mc.getUserName().equals(cred.name)))
                  && mcf.equals(this))
            {
               // Now check if ConnectionInfo equals
               if (info.equals(mc.getInfo()))
               {

                  if (trace)
                     log.trace("Found matching connection: " + mc);

                  return mc;
               }
            }
         }
      }

      if (trace)
         log.trace("No matching connection was found");

      return null;
   
public voidsetClientID(java.lang.String clientID)
Set client id, null by default.

      mcfProperties.setClientID(clientID);
   
public voidsetJmsProviderAdapter(org.jboss.jms.jndi.JMSProviderAdapter adapter)
For local access

      this.adapter = adapter;
   
public voidsetJmsProviderAdapterJNDI(java.lang.String jndi)

      mcfProperties.setProviderJNDI(jndi);
   
public voidsetLogWriter(java.io.PrintWriter out)

      // 
      // jason: screw the logWriter stuff for now it sucks ass
      //
   
public voidsetPassword(java.lang.String password)
Set password, null by default.

      mcfProperties.setPassword(password);
   
public voidsetSessionDefaultType(java.lang.String type)
Set the default session typ

param
type either javax.jms.Topic or javax.jms.Queue
exception
ResourceException if type was not a valid type.

      mcfProperties.setSessionDefaultType(type);
   
public voidsetStrict(boolean strict)

      this.strict = strict;
   
public voidsetStrict(java.lang.Boolean strict)

      this.strict = strict.booleanValue();
   
public voidsetUserName(java.lang.String userName)
Set userName, null by default.

      mcfProperties.setUserName(userName);