FileDocCategorySizeDatePackage
EJBTimerServiceWrapper.javaAPI DocGlassfish v2 API9252Fri May 04 22:32:58 BST 2007com.sun.ejb.containers

EJBTimerServiceWrapper

public class EJBTimerServiceWrapper extends Object implements javax.ejb.TimerService

Fields Summary
private EJBTimerService
timerService_
private EJBContextImpl
ejbContext_
private long
containerId_
private boolean
entity_
private Object
timedObjectPrimaryKey_
Constructors Summary
public EJBTimerServiceWrapper(EJBTimerService timerService, EJBContextImpl ejbContext)

        timerService_ = timerService;
        ejbContext_   = ejbContext;
        BaseContainer container = (BaseContainer) ejbContext.getContainer(); 
        containerId_  = container.getEjbDescriptor().getUniqueId();
        entity_       = false;
        timedObjectPrimaryKey_   = null;
    
public EJBTimerServiceWrapper(EJBTimerService timerService, EntityContextImpl entityContext)

        this(timerService, ((EJBContextImpl)entityContext));
        entity_       = true;
        // Delay access of primary key since this might have been called 
        // from ejbCreate
        timedObjectPrimaryKey_   = null;
    
Methods Summary
private voidcheckCallPermission()

        ejbContext_.checkTimerServiceMethodAccess();
    
private voidcheckCreateTimerCallPermission()

        if( ejbContext_.isTimedObject() ) {
            checkCallPermission();
        } else {
            throw new IllegalStateException("EJBTimerService.createTimer can "
                + "only be called from a timed object.  This EJB does not " 
                + "implement javax.ejb.TimedObject");                 
        }
    
public javax.ejb.TimercreateTimer(long duration, java.io.Serializable info)


        checkCreateTimerCallPermission();

        if( duration < 0 ) {
            throw new IllegalArgumentException("invalid duration=" + duration);
        } 
                             
        TimerPrimaryKey timerId = null;

        try {
            timerId = timerService_.createTimer
                (containerId_, getTimedObjectPrimaryKey(), duration, 0, info);
        } catch(CreateException ce) {            
            EJBException ejbEx = new EJBException();
            ejbEx.initCause(ce);
            throw ejbEx;            
        }

        return new TimerWrapper(timerId, timerService_);
    
public javax.ejb.TimercreateTimer(long initialDuration, long intervalDuration, java.io.Serializable info)


        checkCreateTimerCallPermission();

        if( initialDuration < 0 ) {
            throw new IllegalArgumentException("invalid initial duration = " +
                                               initialDuration);
        } else if( intervalDuration < 0 ) {
            throw new IllegalArgumentException("invalid interval duration = " +
                                               intervalDuration);
        }
                             
        TimerPrimaryKey timerId = null;

        try {
            timerId = timerService_.createTimer
                (containerId_, getTimedObjectPrimaryKey(), initialDuration, 
                 intervalDuration, info);
        } catch(CreateException ce) {
            EJBException ejbEx = new EJBException();
            ejbEx.initCause(ce);
            throw ejbEx;                       
        }

        return new TimerWrapper(timerId, timerService_);
    
public javax.ejb.TimercreateTimer(java.util.Date expiration, java.io.Serializable info)

                             
        checkCreateTimerCallPermission();

        if( expiration == null ) {
            throw new IllegalArgumentException("null expiration");
        } 

        TimerPrimaryKey timerId = null;

        try {
            timerId = timerService_.createTimer(containerId_, 
                                                getTimedObjectPrimaryKey(),
                                                expiration, 0, info);
        } catch(CreateException ce) {
            EJBException ejbEx = new EJBException();
            ejbEx.initCause(ce);
            throw ejbEx;           
        }

        return new TimerWrapper(timerId, timerService_);
    
public javax.ejb.TimercreateTimer(java.util.Date initialExpiration, long intervalDuration, java.io.Serializable info)


        checkCreateTimerCallPermission();

        if( initialExpiration == null ) {
            throw new IllegalArgumentException("null expiration");
        } else if ( intervalDuration < 0 ) {
            throw new IllegalArgumentException("invalid interval duration = " +
                                               intervalDuration);
        }

        TimerPrimaryKey timerId = null;
        try {
            timerId = timerService_.createTimer(containerId_, 
                getTimedObjectPrimaryKey(), initialExpiration, 
                intervalDuration, info);
        } catch(CreateException e) {
            EJBException ejbEx = new EJBException();
            ejbEx.initCause(e);
            throw ejbEx;                       
        }

        return new TimerWrapper(timerId, timerService_);
    
private java.lang.ObjectgetTimedObjectPrimaryKey()

        if( !entity_ ) {
            return null;
        } else {
            synchronized(this) {
                if( timedObjectPrimaryKey_ == null ) {
                    timedObjectPrimaryKey_ = 
                        ((EntityContextImpl) ejbContext_).getPrimaryKey();
                }
            }
        }
        return timedObjectPrimaryKey_;
    
public java.util.CollectiongetTimers()

        
        checkCallPermission();
        
        Collection timerIds = new HashSet();

        if( ejbContext_.isTimedObject() ) {        
            try {
                timerIds = timerService_.getTimerIds
                    (containerId_,  getTimedObjectPrimaryKey());
            } catch(FinderException fe) {
                EJBException ejbEx = new EJBException();
                ejbEx.initCause(fe);
                throw ejbEx;                         
            }
        } 
                                                        
        Collection timerWrappers = new HashSet();

        for(Iterator iter = timerIds.iterator(); iter.hasNext();) {
            TimerPrimaryKey next = (TimerPrimaryKey) iter.next();
            timerWrappers.add( new TimerWrapper(next, timerService_) );
        }

        return timerWrappers;