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

RuntimeTimerState

public class RuntimeTimerState extends Object
RuntimeTimerState holds all runtime state of an EJB timer, including what fine-grained state it's in, stats about the number of expirations and failed deliveries that have occurred, and any existing JDK timer task that is currently scheduled for this timer. It also caches read-only state of a timer to improve performance.
author
Kenneth Saks

Fields Summary
private static final Logger
logger
private static final int
CREATED
private static final int
SCHEDULED
private static final int
BEING_DELIVERED
private static final int
CANCELLED
private int
state_
private TimerPrimaryKey
timerId_
private Date
initialExpiration_
private long
intervalDuration_
private long
containerId_
private Object
timedObjectPrimaryKey_
private BaseContainer
container_
private EJBTimerTask
currentTask_
private int
numExpirations_
private int
numFailedDeliveries_
Constructors Summary
RuntimeTimerState(TimerPrimaryKey timerId, Date initialExpiration, long intervalDuration, BaseContainer container, Object timedObjectPkey)

    
     
                          
                        
                        

        state_       = CREATED;
        currentTask_ = null;

        timerId_           = timerId;
        initialExpiration_ = initialExpiration;
        intervalDuration_  = intervalDuration;
        timedObjectPrimaryKey_ = timedObjectPkey;
        container_         = container;

        containerId_       = container.getContainerId();        

        if( logger.isLoggable(Level.FINE) ) {
            logger.log(Level.FINE, "RuntimeTimerState " + timerId_ + 
                       " created");
        }
    
Methods Summary
voidcancelled()

        if( logger.isLoggable(Level.FINER) ) {
            printStateTransition(state_, CANCELLED);
        }

        currentTask_ = null;
        state_ = CANCELLED;
    
voiddelivered()

        if( logger.isLoggable(Level.FINER) ) {
            printStateTransition(state_, BEING_DELIVERED);
        }

        currentTask_ = null;

        if( numFailedDeliveries_ == 0 ) {
            numExpirations_++;
        }
        
        state_ = BEING_DELIVERED;
    
public booleanequals(java.lang.Object other)

        boolean equal = false;
        if( other instanceof RuntimeTimerState ) {
            equal = timerId_.equals(((RuntimeTimerState) other).timerId_);
        }
        return equal;
    
BaseContainergetContainer()

        return container_;
    
longgetContainerId()

        return containerId_;
    
EJBTimerTaskgetCurrentTimerTask()

        return currentTask_;
    
java.util.DategetInitialExpiration()

        return initialExpiration_;
    
longgetIntervalDuration()

        return intervalDuration_;
    
java.util.DategetNextTimeout()

        if( !isScheduled() && !isRescheduled() ) {
            throw new IllegalStateException();
        }
        return currentTask_.getTimeout();
    
intgetNumExpirations()

        return numExpirations_;
    
intgetNumFailedDeliveries()
Number of failed deliveries since timer last transitioned to the SCHEDULED state.

        return numFailedDeliveries_;
    
longgetTimeRemaining()

        Date timeout = getNextTimeout();
        Date now = new Date();
        return (timeout.getTime() - now.getTime());
    
java.lang.StringgetTimedObjectApplicationName()

        EjbDescriptor ejbDesc = container_.getEjbDescriptor();
        Application app = ejbDesc.getApplication();
        return (app != null) ? app.getRegistrationName() : "";
    
java.lang.StringgetTimedObjectEjbName()

        return container_.getEjbDescriptor().getName();
    
java.lang.ObjectgetTimedObjectPrimaryKey()

        return timedObjectPrimaryKey_;
    
TimerPrimaryKeygetTimerId()

        return timerId_;
    
public inthashCode()

        return timerId_.hashCode();
    
booleanisActive()

        return (state_ != CANCELLED);
    
booleanisBeingDelivered()

        return (state_ == BEING_DELIVERED);
    
booleanisCancelled()

        return (state_ == CANCELLED);
    
booleanisCreated()

        return (state_ == CREATED);
    
booleanisPeriodic()

return
true if interval timer and false otherwise

        return (intervalDuration_ > 0);
    
booleanisRescheduled()

        return (isScheduled() && (numFailedDeliveries_ > 0));
    
booleanisScheduled()

        return (state_ == SCHEDULED);
    
private voidprintStateTransition(int fromState, int toState)

        logger.log(Level.FINER, timerId_ + ": " + stateToString(fromState) +
                   " to " + stateToString(toState));
    
voidrescheduled(EJBTimerTask timerTask)

        if( logger.isLoggable(Level.FINER) ) {
            printStateTransition(state_, SCHEDULED);
        }
        currentTask_ = timerTask;
        state_ = SCHEDULED;
        numFailedDeliveries_++;
    
voidrestoredToDelivered()
Transition from CANCELLED to DELIVERED when ejbTimeout calls cancel and then rolls back. Don't reset numFailedDeliveries.

        if( logger.isLoggable(Level.FINER) ) {
            printStateTransition(state_, BEING_DELIVERED);
        }

        currentTask_ = null;
        state_ = BEING_DELIVERED;
    
voidscheduled(EJBTimerTask timerTask)

        if( logger.isLoggable(Level.FINER) ) {
            printStateTransition(state_, SCHEDULED);
        }
        currentTask_ = timerTask;
        state_ = SCHEDULED;
        numFailedDeliveries_ = 0;
    
java.lang.StringstateToString()

        return stateToString(state_);
    
private java.lang.StringstateToString(int state)

        switch(state) {
        case CREATED :
            return "CREATED";
        case SCHEDULED :
            return "SCHEDULED";
        case BEING_DELIVERED :
            return "BEING_DELIVERED";
        case CANCELLED :
            return "CANCELLED";
        }
        return state + " NOT FOUND";
    
booleantimedObjectIsEntity()

        return (timedObjectPrimaryKey_ != null);
    
public java.lang.StringtoString()

        StringBuffer buffer = new StringBuffer();        
        buffer.append("'" + getTimerId() + "' ");
        buffer.append("'TimedObject = " + getTimedObjectEjbName() + "' ");
        buffer.append("'Application = " + getTimedObjectApplicationName()
                      + "' ");
        buffer.append("'" + stateToString() + "' ");
        buffer.append("'" + (isPeriodic() ? "PERIODIC' " : "SINGLE-ACTION' "));
        buffer.append("'Container ID = " + containerId_ + "' ");
        buffer.append("'" + getInitialExpiration() + "' ");
        buffer.append("'" + getIntervalDuration() + "' ");
        Object pk = getTimedObjectPrimaryKey();
        if( pk != null ) {
            buffer.append("'" + pk + "' ");
        }
        return buffer.toString();