FileDocCategorySizeDatePackage
ResourceHandle.javaAPI DocGlassfish v2 API10196Fri May 04 22:35:14 BST 2007com.sun.enterprise.resource

ResourceHandle

public class ResourceHandle extends Object
ResourceHandle encapsulates a resource connection. Equality on the handle is based on the id field
author
Tony Ng

Fields Summary
private static long
idSequence
private long
id
private ClientSecurityInfo
info
private Object
resource
private ResourceSpec
spec
private XAResource
xares
private Object
usercon
private ResourceAllocator
alloc
private Object
instance
private int
shareCount
private boolean
supportsXAResource
private Subject
subject
private ResourceState
state
private javax.resource.spi.ConnectionEventListener
listener
private boolean
associated_
private long
threadId_
private static Logger
logger
private boolean
supportsLazyEnlistment_
private boolean
supportsLazyAssoc_
private boolean
enlistmentSuspended
public final Object
lock
private boolean
dirty_
private long
lastValidated
private int
usageCount
private boolean
connectionErrorOccurred
Constructors Summary
public ResourceHandle(Object resource, ResourceSpec spec, ResourceAllocator alloc, ClientSecurityInfo info)

        this.id = getNextId();
        this.spec = spec;
        this.info = info;
        this.resource = resource;
        this.alloc = alloc;

	if ( alloc instanceof LocalTxConnectorAllocator)
	    supportsXAResource = false;
	else
	    supportsXAResource = true;

        if ( resource instanceof 
            javax.resource.spi.LazyEnlistableManagedConnection ) {
            supportsLazyEnlistment_ = true;
        }

        if ( resource instanceof 
            javax.resource.spi.DissociatableManagedConnection ) {
            supportsLazyAssoc_ = true;
        }
    
public ResourceHandle(Object resource, ResourceSpec spec, ResourceAllocator alloc, ClientSecurityInfo info, boolean supportsXA)

        this.id = getNextId();
        this.spec = spec;
        this.info = info;
        this.resource = resource;
        this.alloc = alloc;

	supportsXAResource = supportsXA;

        dirty_ = false;
    
Methods Summary
public voiddecrementCount()

        if (shareCount == 0) {
            throw new IllegalStateException("shareCount cannot be negative");
        } else {
            shareCount--;
        }
    
public booleanequals(java.lang.Object other)

        if (other == null) return false;
        if (other instanceof ResourceHandle) {
            return this.id == (((ResourceHandle) other).id);
        }
        return false;
    
public voidfillInResourceObjects(java.lang.Object userConnection, javax.transaction.xa.XAResource xaRes)

        if (userConnection != null) usercon = userConnection;
        if (xaRes !=null) {
           if(logger.isLoggable(Level.FINEST)){
             //When Log level is Finest, XAResourceWrapper is used to log
             //all XA interactions - Don't wrap XAResourceWrapper if it is 
             //already wrapped
               if ((xaRes instanceof XAResourceWrapper) ||
                       (xaRes instanceof ConnectorXAResource)) {
                   this.xares = xaRes;
               } else {
                   this.xares = new XAResourceWrapper(xaRes);
               }
           } else {
            this.xares = xaRes;
           }
        }
    
public ClientSecurityInfogetClientSecurityInfo()

        return info;
    
public java.lang.ObjectgetComponentInstance()

        return instance;
    
public longgetLastValidated()

     return lastValidated;
    
public javax.resource.spi.ConnectionEventListenergetListener()

        return listener;
    
private static longgetNextId()

 //holds the no. of times the handle(connection) is used so far.
    
        
	synchronized (ResourceHandle.class) {
	    idSequence++;
            return idSequence;
        }
    
public java.lang.ObjectgetResource()

        return resource;
    
public ResourceAllocatorgetResourceAllocator()

        return alloc;
    
public ResourceSpecgetResourceSpec()

        return spec;
    
public ResourceStategetResourceState()

        return state;
    
public intgetShareCount()

        return shareCount;
    
public javax.security.auth.SubjectgetSubject()

        return subject;
    
public longgetThreadId()

        return threadId_;
    
public intgetUsageCount()

        return usageCount;
    
public java.lang.ObjectgetUserConnection()

        return usercon;
    
public javax.transaction.xa.XAResourcegetXAResource()

        return xares;
    
public booleanhasConnectionErrorOccurred()

	return connectionErrorOccurred;
    
public inthashCode()

        return Long.valueOf(id).hashCode();
    
public voidincrementCount()

        shareCount++;
    
public voidincrementUsageCount()

        usageCount++;
     
public booleanisAssociated()

        return associated_;
    
public booleanisDirty()

        return dirty_;
    
public booleanisEnlisted()

        return state != null && state.isEnlisted();
    
public booleanisEnlistmentSuspended()
To check whether lazy enlistment is suspended or not.
If true, TM will not do enlist/lazy enlist.

return
boolean

        return enlistmentSuspended;
    
public booleanisShareable()

       return alloc.shareableWithinComponent();
    
public booleanisTransactional()
Does this resource need enlistment to transaction manager?

        return alloc.isTransactional();
    
public voidsetAssociated(boolean flag)

        associated_ = flag;
    
public voidsetComponentInstance(java.lang.Object instance)

        this.instance = instance;
    
public voidsetConnectionErrorOccurred()


       
	connectionErrorOccurred = true;
    
public voidsetDirty()

        dirty_ = true;
    
public voidsetEnlistmentSuspended(boolean enlistmentSuspended)

        this.enlistmentSuspended = enlistmentSuspended;
    
public voidsetLastValidated(long lastValidated)

     this.lastValidated = lastValidated;
    
public voidsetListener(javax.resource.spi.ConnectionEventListener l)

        this.listener = l;
    
public voidsetResourceSpec(ResourceSpec spec)

        this.spec = spec;
    
public voidsetResourceState(ResourceState state)

        this.state = state;
    
public voidsetSubject(javax.security.auth.Subject subject)

        this.subject = subject;
    
public voidsetThreadId(long threadId)

        threadId_ = threadId;
    
public booleansupportsLazyAssociation()

        return supportsLazyAssoc_;
    
public booleansupportsLazyEnlistment()

        return supportsLazyEnlistment_;
    
public booleansupportsXA()

        return supportsXAResource;
    
public java.lang.StringtoString()

        return String.valueOf(id);