Methods Summary |
---|
public void | cancel()
// First set the timer to the cancelled state. This step is
// performed whether or not the current server instance owns
// the timer.
if( getState() == CANCELLED ) {
// already cancelled
return;
}
setState(CANCELLED);
// Only proceed with JDK timer task cancellation if this timer
// is owned by the current server instance.
if( timerOwnedByThisServer() ) {
TimerPrimaryKey timerId = new TimerPrimaryKey(getTimerId());
// Cancel existing timer task. Save time at which task would
// have executed in case cancellation is rolled back. The
// nextTimeout can be null if the timer is currently being
// delivered.
Date nextTimeout = getEJBTimerService().cancelTask(timerId);
ContainerSynchronization containerSynch = getContainerSynch();
Synchronization timerSynch =
containerSynch.getTimerSynchronization(timerId);
if( timerSynch != null ) {
// This timer was created and cancelled within the
// same transaction. No tx synchronization actions
// are needed, since whether tx commits or rolls back,
// timer will not exist.
containerSynch.removeTimerSynchronization(timerId);
getEJBTimerService().expungeTimer(timerId);
} else {
// Set tx synchronization action to handle timer cancellation.
timerSynch = new TimerSynch(timerId, CANCELLED, nextTimeout,
getContainer(getContainerId()));
containerSynch.addTimerSynchronization(timerId, timerSynch);
}
}
// NOTE that it's the caller's responsibility to call remove().
return;
|
public void | ejbActivate()
|
public TimerPrimaryKey | ejbCreate(java.lang.String timerId, long containerId, java.lang.String ownerId, java.lang.Object timedObjectPrimaryKey, java.util.Date initialExpiration, long intervalDuration, java.io.Serializable info)
setTimerId(timerId);
setOwnerId(ownerId);
return null;
|
public boolean | ejbHomeCheckStatus(java.lang.String resourceJndiName, boolean checkDatabase)
boolean success = false;
Connection connection = null;
try {
InitialContext ic = new InitialContext();
DataSource dataSource = (DataSource) ic.lookup(resourceJndiName);
if( checkDatabase ) {
connection = dataSource.getConnection();
connection.close();
connection = null;
// Now try to a query that will access the timer table itself.
// Use a query that won't return a lot of data(even if the
// table is large) to reduce the overhead of this check.
ejbSelectCountTimersByContainer(0);
}
success = true;
} catch(Exception e) {
logger.log(Level.WARNING, "ejb.timer_service_init_error",
"");
// Log exception itself at FINE level. The most likely cause
// is a connection error when the database is not started. This
// is already logged twice by the jdbc layer.
logger.log(Level.FINE, "ejb.timer_service_init_error", e);
} finally {
if( connection != null ) {
try {
connection.close();
} catch(Exception e) {
logger.log(Level.FINE, "timer connection close exception",
e);
}
}
}
return success;
|
public java.util.Set | ejbHomeSelectActiveTimerIdsByContainer(long containerId)
return toPKeys(ejbSelectTimerIdsByContainerAndState(containerId,
ACTIVE));
|
public java.util.Set | ejbHomeSelectActiveTimerIdsOwnedByThisServerByContainer(long containerId)
return toPKeys(ejbSelectTimerIdsByContainerAndOwnerAndState
(containerId, getOwnerIdOfThisServer(), ACTIVE));
|
public java.util.Set | ejbHomeSelectActiveTimersByContainer(long containerId)
return ejbSelectTimersByContainerAndState(containerId,
ACTIVE);
|
public java.util.Set | ejbHomeSelectActiveTimersOwnedByThisServerByContainer(long containerId)
return ejbSelectTimersByContainerAndOwnerAndState
(containerId, getOwnerIdOfThisServer(), ACTIVE);
|
public java.util.Set | ejbHomeSelectAllActiveTimerIdsOwnedBy(java.lang.String ownerId)
return toPKeys(ejbSelectAllTimerIdsByOwnerAndState
(ownerId, ACTIVE));
|
public java.util.Set | ejbHomeSelectAllActiveTimerIdsOwnedByThisServer()
return toPKeys(ejbSelectAllTimerIdsByOwnerAndState
(getOwnerIdOfThisServer(), ACTIVE));
|
public java.util.Set | ejbHomeSelectAllActiveTimersOwnedBy(java.lang.String ownerId)
return ejbSelectAllTimersByOwnerAndState
(ownerId, ACTIVE);
|
public java.util.Set | ejbHomeSelectAllActiveTimersOwnedByThisServer()
return ejbSelectAllTimersByOwnerAndState
(getOwnerIdOfThisServer(), ACTIVE);
|
public java.util.Set | ejbHomeSelectAllCancelledTimerIdsOwnedBy(java.lang.String ownerId)
return toPKeys(ejbSelectAllTimerIdsByOwnerAndState
(ownerId, CANCELLED));
|
public java.util.Set | ejbHomeSelectAllCancelledTimerIdsOwnedByThisServer()
return toPKeys(ejbSelectAllTimerIdsByOwnerAndState
(getOwnerIdOfThisServer(), CANCELLED));
|
public java.util.Set | ejbHomeSelectAllCancelledTimersOwnedBy(java.lang.String ownerId)
return ejbSelectAllTimersByOwnerAndState
(ownerId, CANCELLED);
|
public java.util.Set | ejbHomeSelectAllCancelledTimersOwnedByThisServer()
return ejbSelectAllTimersByOwnerAndState
(getOwnerIdOfThisServer(), CANCELLED);
|
public java.util.Set | ejbHomeSelectAllTimerIdsOwnedBy(java.lang.String ownerId)
return toPKeys(ejbSelectAllTimerIdsByOwner(ownerId));
|
public java.util.Set | ejbHomeSelectAllTimerIdsOwnedByThisServer()
return toPKeys(ejbSelectAllTimerIdsByOwner(getOwnerIdOfThisServer()));
|
public java.util.Set | ejbHomeSelectAllTimersOwnedBy(java.lang.String ownerId)
return ejbSelectAllTimersByOwner(ownerId);
|
public java.util.Set | ejbHomeSelectAllTimersOwnedByThisServer()
return ejbSelectAllTimersByOwner(getOwnerIdOfThisServer());
|
public java.util.Set | ejbHomeSelectCancelledTimerIdsByContainer(long containerId)
return toPKeys(ejbSelectTimerIdsByContainerAndState
(containerId, CANCELLED));
|
public java.util.Set | ejbHomeSelectCancelledTimerIdsOwnedByThisServerByContainer(long containerId)
return toPKeys(ejbSelectTimerIdsByContainerAndOwnerAndState
(containerId, getOwnerIdOfThisServer(), CANCELLED));
|
public java.util.Set | ejbHomeSelectCancelledTimersByContainer(long containerId)
return ejbSelectTimersByContainerAndState
(containerId, CANCELLED);
|
public java.util.Set | ejbHomeSelectCancelledTimersOwnedByThisServerByContainer(long containerId)
return ejbSelectTimersByContainerAndOwnerAndState
(containerId, getOwnerIdOfThisServer(), CANCELLED);
|
public int | ejbHomeSelectCountActiveTimersByContainer(long containerId)
return ejbSelectCountTimersByContainerAndState(containerId,
ACTIVE);
|
public int | ejbHomeSelectCountActiveTimersOwnedByThisServerByContainer(long containerId)
return ejbSelectCountTimersByContainerAndOwnerAndState
(containerId, getOwnerIdOfThisServer(), ACTIVE);
|
public int | ejbHomeSelectCountAllActiveTimersOwnedBy(java.lang.String ownerId)
return ejbSelectCountAllTimersByOwnerAndState
(ownerId, ACTIVE);
|
public int | ejbHomeSelectCountAllActiveTimersOwnedByThisServer()
return ejbSelectCountAllTimersByOwnerAndState
(getOwnerIdOfThisServer(), ACTIVE);
|
public int | ejbHomeSelectCountAllCancelledTimersOwnedBy(java.lang.String ownerId)
return ejbSelectCountAllTimersByOwnerAndState
(ownerId, CANCELLED);
|
public int | ejbHomeSelectCountAllCancelledTimersOwnedByThisServer()
return ejbSelectCountAllTimersByOwnerAndState
(getOwnerIdOfThisServer(), CANCELLED);
|
public int | ejbHomeSelectCountAllTimersOwnedBy(java.lang.String ownerId)
return ejbSelectCountAllTimersByOwner(ownerId);
|
public int | ejbHomeSelectCountAllTimersOwnedByThisServer()
return ejbSelectCountAllTimersByOwner(getOwnerIdOfThisServer());
|
public int | ejbHomeSelectCountCancelledTimersByContainer(long containerId)
return ejbSelectCountTimersByContainerAndState
(containerId, CANCELLED);
|
public int | ejbHomeSelectCountCancelledTimersOwnedByThisServerByContainer(long containerId)
return ejbSelectCountTimersByContainerAndOwnerAndState
(containerId, getOwnerIdOfThisServer(), CANCELLED);
|
public int | ejbHomeSelectCountTimersByContainer(long containerId)
return ejbSelectCountTimersByContainer(containerId);
|
public int | ejbHomeSelectCountTimersOwnedByThisServerByContainer(long containerId)
return ejbSelectCountTimersByContainerAndOwner
(containerId, getOwnerIdOfThisServer());
|
public java.util.Set | ejbHomeSelectTimerIdsByContainer(long containerId)
return toPKeys(ejbSelectTimerIdsByContainer(containerId));
|
public java.util.Set | ejbHomeSelectTimerIdsOwnedByThisServerByContainer(long containerId)
return toPKeys(ejbSelectTimerIdsByContainerAndOwner
(containerId, getOwnerIdOfThisServer()));
|
public java.util.Set | ejbHomeSelectTimersByContainer(long containerId)
return ejbSelectTimersByContainer(containerId);
|
public java.util.Set | ejbHomeSelectTimersOwnedByThisServerByContainer(long containerId)
return ejbSelectTimersByContainerAndOwner
(containerId, getOwnerIdOfThisServer());
|
public void | ejbLoad()
long lastExpirationRaw = getLastExpirationRaw();
lastExpiration_ = (lastExpirationRaw > 0) ?
new Date(lastExpirationRaw) : null;
// Populate derived state of immutable cmp fields.
creationTime_ = new Date(getCreationTimeRaw());
initialExpiration_ = new Date(getInitialExpirationRaw());
// Lazily deserialize Blob state. This makes the
// Timer bootstrapping code easier, since some of the Timer
// state must be loaded from the database before the
// container and application classloader are known.
timedObjectPrimaryKey_ = null;
info_ = null;
blobLoaded_ = false;
|
public void | ejbPassivate()
|
public void | ejbPostCreate(java.lang.String timerId, long containerId, java.lang.String ownerId, java.lang.Object timedObjectPrimaryKey, java.util.Date initialExpiration, long intervalDuration, java.io.Serializable info)
Date creationTime = new Date();
setCreationTimeRaw(creationTime.getTime());
creationTime_ = creationTime;
setInitialExpirationRaw(initialExpiration.getTime());
initialExpiration_ = initialExpiration;
setLastExpirationRaw(0);
lastExpiration_ = null;
setIntervalDuration(intervalDuration);
setContainerId(containerId);
timedObjectPrimaryKey_ = timedObjectPrimaryKey;
info_ = info;
blobLoaded_ = true;
Blob blob = null;
try {
blob = new Blob(timedObjectPrimaryKey, info);
} catch(IOException ioe) {
CreateException ce = new CreateException();
ce.initCause(ioe);
throw ce;
}
setBlob(blob);
setState(ACTIVE);
if( logger.isLoggable(Level.FINE) ) {
logger.log(Level.FINE, "TimerBean.postCreate() ::timerId=" +
getTimerId() + " ::containerId=" + getContainerId() +
" ::timedObjectPK=" + timedObjectPrimaryKey +
" ::info=" + info +
" ::initialExpiration=" + initialExpiration +
" ::intervalDuration=" + intervalDuration +
" :::state=" + stateToString(getState()) +
" :::creationTime=" + creationTime +
" :::ownerId=" + getOwnerId());
}
//
// Only proceed with transactional semantics if this timer
// is owned by the current server instance. NOTE that this
// will *ALWAYS* be the case for timers created from EJB
// applications via the javax.ejb.EJBTimerService.create methods.
//
// For testing purposes, ejbCreate takes an ownerId parameter,
// which allows us to easily simulate other server instances
// by creating timers for them. In those cases, we don't need
// the timer transaction semantics and ejbTimeout logic. Simulating
// the creation of timers for the same application and different
// server instances from a script is difficult since the
// containerId is not generated until after deployment.
//
if( timerOwnedByThisServer() ) {
// Register a synchronization object to handle the commit/rollback
// semantics and ejbTimeout notifications.
Synchronization timerSynch =
new TimerSynch(new TimerPrimaryKey(getTimerId()), ACTIVE,
getInitialExpiration(),
getContainer(containerId));
try {
ContainerSynchronization containerSynch = getContainerSynch();
containerSynch.addTimerSynchronization
(new TimerPrimaryKey(getTimerId()), timerSynch);
} catch(Exception e) {
CreateException ce = new CreateException();
ce.initCause(e);
throw ce;
}
}
|
public void | ejbRemove()
|
public abstract java.util.Set | ejbSelectAllTimerIdsByOwner(java.lang.String ownerId)
|
public abstract java.util.Set | ejbSelectAllTimerIdsByOwnerAndState(java.lang.String ownerId, int state)
|
public abstract java.util.Set | ejbSelectAllTimersByOwner(java.lang.String ownerId)
|
public abstract java.util.Set | ejbSelectAllTimersByOwnerAndState(java.lang.String ownerId, int state)
|
public abstract int | ejbSelectCountAllTimersByOwner(java.lang.String ownerId)
|
public abstract int | ejbSelectCountAllTimersByOwnerAndState(java.lang.String ownerId, int state)
|
public abstract int | ejbSelectCountTimersByContainer(long containerId)
|
public abstract int | ejbSelectCountTimersByContainerAndOwner(long containerId, java.lang.String ownerId)
|
public abstract int | ejbSelectCountTimersByContainerAndOwnerAndState(long containerId, java.lang.String ownerId, int state)
|
public abstract int | ejbSelectCountTimersByContainerAndState(long containerId, int state)
|
public abstract java.util.Set | ejbSelectTimerIdsByContainer(long containerId)
|
public abstract java.util.Set | ejbSelectTimerIdsByContainerAndOwner(long containerId, java.lang.String ownerId)
|
public abstract java.util.Set | ejbSelectTimerIdsByContainerAndOwnerAndState(long containerId, java.lang.String ownerId, int state)
|
public abstract java.util.Set | ejbSelectTimerIdsByContainerAndState(long containerId, int state)
|
public abstract java.util.Set | ejbSelectTimersByContainer(long containerId)
|
public abstract java.util.Set | ejbSelectTimersByContainerAndOwner(long containerId, java.lang.String ownerId)
|
public abstract java.util.Set | ejbSelectTimersByContainerAndOwnerAndState(long containerId, java.lang.String ownerId, int state)
|
public abstract java.util.Set | ejbSelectTimersByContainerAndState(long containerId, int state)
|
public void | ejbStore()
|
public abstract com.sun.ejb.containers.TimerBean$Blob | getBlob()
|
private BaseContainer | getContainer(long containerId)
ContainerFactory cf = Switch.getSwitch().getContainerFactory();
return (BaseContainer) cf.getContainer(containerId);
|
public abstract long | getContainerId()
|
private ContainerSynchronization | getContainerSynch()
EntityContainer container = (EntityContainer) context_.getContainer();
ContainerFactoryImpl containerFactory = (ContainerFactoryImpl)
Switch.getSwitch().getContainerFactory();
Transaction transaction = context_.getTransaction();
if( transaction == null ) {
logger.log(Level.FINE, "Context transaction = null. Using " +
"invocation instead.");
InvocationManager iMgr = Switch.getSwitch().getInvocationManager();
ComponentInvocation i = iMgr.getCurrentInvocation();
transaction = i.transaction;
}
if( transaction == null ) {
throw new Exception("transaction = null in getContainerSynch " +
"for timerId = " + getTimerId());
}
ContainerSynchronization containerSync =
containerFactory.getContainerSync(transaction);
return containerSync;
|
public java.util.Date | getCreationTime()
return creationTime_;
|
public abstract long | getCreationTimeRaw()
|
private static EJBTimerService | getEJBTimerService()
ContainerFactoryImpl containerFactory = (ContainerFactoryImpl)
Switch.getSwitch().getContainerFactory();
return containerFactory.getEJBTimerService();
|
public java.io.Serializable | getInfo()
if( !blobLoaded_ ) {
loadBlob();
}
return info_;
|
public java.util.Date | getInitialExpiration()
return initialExpiration_;
|
public abstract long | getInitialExpirationRaw()
|
public abstract long | getIntervalDuration()
|
public java.util.Date | getLastExpiration()
return lastExpiration_;
|
public abstract long | getLastExpirationRaw()
|
public abstract java.lang.String | getOwnerId()
|
private java.lang.String | getOwnerIdOfThisServer()
return getEJBTimerService().getOwnerIdOfThisServer();
|
public abstract int | getPkHashCode()
|
public abstract int | getState()
|
public java.lang.Object | getTimedObjectPrimaryKey()
if( !blobLoaded_ ) {
loadBlob();
}
return timedObjectPrimaryKey_;
|
public abstract java.lang.String | getTimerId()
|
public boolean | isActive()
return (getState() == ACTIVE);
|
public boolean | isCancelled()
return (getState() == CANCELLED);
|
private void | loadBlob()
EJBTimerService timerService = getEJBTimerService();
ClassLoader cl = timerService.getTimerClassLoader(getContainerId());
if( cl != null ) {
loadBlob(cl);
} else {
throw new EJBException("No timer classloader for " + getTimerId());
}
|
private void | loadBlob(java.lang.ClassLoader cl)
try {
Blob blob = getBlob();
timedObjectPrimaryKey_ = blob.getTimedObjectPrimaryKey(cl);
info_ = blob.getInfo(cl);
blobLoaded_ = true;
} catch(Exception e) {
EJBException ejbEx = new EJBException();
ejbEx.initCause(e);
throw ejbEx;
}
|
public boolean | repeats()
return (getIntervalDuration() > 0);
|
public abstract void | setBlob(com.sun.ejb.containers.TimerBean$Blob blob)
|
public abstract void | setContainerId(long containerId)
|
public abstract void | setCreationTimeRaw(long creationTime)
|
public void | setEntityContext(javax.ejb.EntityContext context)
context_ = (EJBContextImpl) context;
|
public abstract void | setInitialExpirationRaw(long initialExpiration)
|
public abstract void | setIntervalDuration(long intervalDuration)
|
public void | setLastExpiration(java.util.Date lastExpiration)
// can be null
lastExpiration_ = lastExpiration;
long lastExpirationRaw = (lastExpiration != null) ?
lastExpiration.getTime() : 0;
setLastExpirationRaw(lastExpirationRaw);
|
public abstract void | setLastExpirationRaw(long lastExpiration)
|
public abstract void | setOwnerId(java.lang.String ownerId)
|
public abstract void | setPkHashCode(int pkHash)
|
public abstract void | setState(int state)
|
public abstract void | setTimerId(java.lang.String timerId)
|
private static java.lang.String | stateToString(int state)
String stateStr = "UNKNOWN_TIMER_STATE";
switch(state) {
case ACTIVE :
stateStr = "TIMER_ACTIVE";
break;
case CANCELLED :
stateStr = "TIMER_CANCELLED";
break;
default :
stateStr = "UNKNOWN_TIMER_STATE";
break;
}
return stateStr;
|
public static void | testCreate(java.lang.String timerId, javax.ejb.EJBContext context, java.lang.String ownerId, java.util.Date initialExpiration, long intervalDuration, java.io.Serializable info)
EJBTimerService ejbTimerService = getEJBTimerService();
TimerLocalHome timerLocalHome = ejbTimerService.getTimerBeanHome();
EjbDescriptor ejbDesc = (EjbDescriptor)
Switch.getSwitch().
getDescriptorFor(((EJBContextImpl) context).getContainer());
long containerId = ejbDesc.getUniqueId();
Object timedObjectPrimaryKey = (context instanceof EntityContext) ?
((EntityContext)context).getPrimaryKey() : null;
timerLocalHome.create(timerId, containerId, ownerId,
timedObjectPrimaryKey, initialExpiration,
intervalDuration, info);
return;
|
public static void | testMigrate(java.lang.String fromOwnerId)
EJBTimerService ejbTimerService = getEJBTimerService();
ejbTimerService.migrateTimers(fromOwnerId);
|
private boolean | timerOwnedByThisServer()Checks whether this timer is owned by the server instance in
which we are running.
String ownerIdOfThisServer = getOwnerIdOfThisServer();
return ( (ownerIdOfThisServer != null) &&
(ownerIdOfThisServer.equals(getOwnerId())) );
|
private java.util.Set | toPKeys(java.util.Set ids)
Set pkeys = new HashSet();
for(Iterator iter = ids.iterator(); iter.hasNext();) {
pkeys.add(new TimerPrimaryKey((String) iter.next()));
}
return pkeys;
|
private static java.lang.String | txStatusToString(int txStatus)
String txStatusStr = "UNMATCHED TX STATUS";
switch(txStatus) {
case Status.STATUS_ACTIVE :
txStatusStr = "TX_STATUS_ACTIVE";
break;
case Status.STATUS_COMMITTED :
txStatusStr = "TX_STATUS_COMMITTED";
break;
case Status.STATUS_COMMITTING :
txStatusStr = "TX_STATUS_COMMITTING";
break;
case Status.STATUS_MARKED_ROLLBACK :
txStatusStr = "TX_STATUS_MARKED_ROLLBACK";
break;
case Status.STATUS_NO_TRANSACTION :
txStatusStr = "TX_STATUS_NO_TRANSACTION";
break;
case Status.STATUS_PREPARED :
txStatusStr = "TX_STATUS_PREPARED";
break;
case Status.STATUS_PREPARING :
txStatusStr = "TX_STATUS_PREPARING";
break;
case Status.STATUS_ROLLEDBACK :
txStatusStr = "TX_STATUS_ROLLEDBACK";
break;
case Status.STATUS_ROLLING_BACK :
txStatusStr = "TX_STATUS_ROLLING_BACK";
break;
case Status.STATUS_UNKNOWN :
txStatusStr = "TX_STATUS_UNKNOWN";
break;
default :
txStatusStr = "UNMATCHED TX STATUS";
break;
}
return txStatusStr;
|
public void | unsetEntityContext()
context_ = null;
|