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

ResourceManagerImpl

public class ResourceManagerImpl extends Object implements ResourceManager
Resource Manager for any resource request from a component.
author
Binod PG

Fields Summary
static Logger
_logger
Constructors Summary
Methods Summary
public voiddelistResource(ResourceHandle resource, int xaresFlag)
delist the ResourceHandle from the transaction

param
resource ResourceHandle object
param
xaresFlag flag indicating transaction success. This can be XAResource.TMSUCCESS or XAResource.TMFAIL
exception
PoolingException

        unregisterResource(resource,xaresFlag);
    
protected voidenlist(J2EETransactionManager tm, javax.transaction.Transaction tran, ResourceHandle h)

        try {
            tm.enlistResource( tran, h );
        } catch( Exception e ) {
            PoolingException pe = new PoolingException( e.getMessage() );
            pe.initCause( e );
            throw pe;
        }
    
public voidenlistResource(ResourceHandle h)
Enlist the ResourceHandle in the transaction

param
h ResourceHandle object
exception
PoolingException

        registerResource(h);
    
public java.lang.ObjectgetComponent()
Returns the component invoking resource request.

return
Handle to the component.

        
        InvocationManager invmgr =
        Switch.getSwitch().getInvocationManager();
        ComponentInvocation inv = invmgr.getCurrentInvocation();
        if (inv == null) {
            return null;
        }
        
        return inv.getInstance();
    
public javax.transaction.TransactiongetTransaction()
Returns the transaction component is participating.

return
Handle to the Transaction object.
exception
PoolingException

     
        _logger = LogDomains.getLogger(LogDomains.RSR_LOGGER);
    
        InvocationManager invmgr =
        Switch.getSwitch().getInvocationManager();
        ComponentInvocation inv = invmgr.getCurrentInvocation();
        if (inv == null) {
	    try {
                return Switch.getSwitch().getTransactionManager().getTransaction();
            } catch (Exception ex) {
	        return null;
	    }
        }
        return inv.getTransaction();
    
public voidregisterResource(ResourceHandle handle)
Register the ResourceHandle in the transaction

param
handle ResourceHandle object
exception
PoolingException

        try {
            Transaction tran = null;
            J2EETransactionManager tm = 
            Switch.getSwitch().getTransactionManager();
            // enlist if necessary
            if (handle.isTransactional()) {
                InvocationManager invmgr =
                Switch.getSwitch().getInvocationManager();
                ComponentInvocation inv = invmgr.getCurrentInvocation();
                              
                if (inv == null) {
                    //throw new InvocationException();
                    
                    //Go to the tm and get the transaction
		    //This is mimicking the current behavior of
		    //the SystemResourceManagerImpl registerResource method
		    //in that, you return the transaction from the TxManager
		    try {
                        tran = tm.getTransaction(); 	
                    } catch( Exception e ) {
		        tran = null;
			_logger.log(Level.INFO, e.getMessage());
		    }
                } else {
                    tran = inv.getTransaction();
                    tm.registerComponentResource(handle);
                }
                
                if (tran != null) {
 	 	    try{            
 	 	        tm.enlistResource(tran, handle);
 	 	    } catch (Exception ex) {
 	 	        _logger.fine("Exception whle trying to enlist resource " + ex.getMessage());
 	 	        //If transactional, remove the connection handle from the
 	 	        //component's resource list as there has been exception attempting
 	 	        //to enlist the resource
 	 	        if(inv != null) {
 	 	            _logger.fine("Attempting to unregister component resource");
 	 	            tm.unregisterComponentResource(handle);
 	 	        }
 	 	        throw ex;
 	 	    }
                }
            }
                        
        } catch (Exception ex) {
            _logger.log(Level.SEVERE,"poolmgr.component_register_exception",ex);
            throw new PoolingException(ex.toString(), ex);
        }
    
public voidrollBackTransaction()
Get's the component's transaction and marks it for rolling back.

        InvocationManager invmgr =
        Switch.getSwitch().getInvocationManager();
	J2EETransactionManager tm = Switch.getSwitch().getTransactionManager();
	Transaction tran = null;
        try {
            ComponentInvocation inv = invmgr.getCurrentInvocation();
            if (inv == null) {
                //throw new InvocationException();
                    
               //Go to the tm and get the transaction
               //This is mimicking the current behavior of
               //the SystemResourceManagerImpl registerResource method
               //in that, you return the transaction from the TxManager
	       try {
                   tran = tm.getTransaction(); 	
               } catch( Exception e ) {
	           tran = null;
                   _logger.log(Level.INFO, e.getMessage());
               }

            } else {
                tran = inv.getTransaction();
	    }
            if (tran != null) {
                tran.setRollbackOnly();
            }
        } catch (SystemException ex) {
            _logger.log(Level.WARNING,"poolmgr.system_exception",ex);
        } catch (IllegalStateException ex) {
            // ignore
        }
    
public voidunregisterResource(ResourceHandle resource, int xaresFlag)
Unregister the ResourceHandle from the transaction

param
resource ResourceHandle object
param
xaresFlag flag indicating transaction success. This can be XAResource.TMSUCCESS or XAResource.TMFAIL
exception
PoolingException


        J2EETransactionManager tm =
                Switch.getSwitch().getTransactionManager();
        Transaction tran = null;

        try {
            // delist with TMSUCCESS if necessary
            if (resource.isTransactional()) {
                InvocationManager invmgr =
                        Switch.getSwitch().getInvocationManager();
                ComponentInvocation inv = invmgr.getCurrentInvocation();
                if (inv == null) {
                    //throw new InvocationException();

                    //Go to the tm and get the transaction
                    //This is mimicking the current behavior of
                    //the SystemResourceManagerImpl registerResource method
                    //in that, you return the transaction from the TxManager
                    try {
                        tran = tm.getTransaction();
                    } catch (Exception e) {
                        tran = null;
                        _logger.log(Level.INFO, e.getMessage());
                    }
                } else {
                    tran = inv.getTransaction();
                    tm.unregisterComponentResource(resource);
                }
                if (tran != null && resource.isEnlisted()) {
                    tm.delistResource(tran, resource, xaresFlag);
                }
            }
        } catch (SystemException ex) {
            _logger.log(Level.WARNING, "poolmgr.system_exception", ex);
        } catch (IllegalStateException ex) {
            // transaction aborted. Do nothing
        } catch (InvocationException ex) {
            // unregisterResource is called outside of component context
            // likely to be container-forced destroy. Do nothing
        }