Supporting persistence of ejb timers
starksm64 Aug 22, 2005 12:54 PMI spent some time looking at supporting persistence of timers across ejb redeployments/server shutdowns and org.jboss.ejb.txtimer.EJBTimerService needs to change to expose such a notion:
/** * Remove the TimerService for a given TimedObjectId * * @param containerId The identifier for a class of TimedObjects * @param pKey The primary key for an instance of a TimedObject, may be null * @param removePersistentState a flag indicating if the timer persistence state should be removed */ void removeTimerService(ObjectName containerId, Object pKey, boolean removePersistentState) throws IllegalStateException; /** * Restore the timers for a given ejb container. * * @param containerId The identifier for a class of TimedObjects */ void restoreTimers(ObjectName containerId);
The org.jboss.ejb.txtimer.PersistencePolicy interface also needs a more targeted restoration notion
/** * Restore the persistet timers for the given container * @param containerID the id of the ejb container whose timers should be restored. A null value indicates all container timers should be restored. * @return the timer handles that need to be restored */ List<TimerHandleImpl> restoreTimers(ObjectName containerID);
A general problem with the current PersistencePolicy interface is that too much detail about the restoration process is pushed to the PersistencePolicy implementation. Currently, the PersistencePolicy.restoreTimers is responsible for creating the timers in the various ejb containers.
This should simply be returning the list of TimerHandleImpl that need to be created. Currently the org.jboss.ejb.txtimer.DatabasePersistencePolicy has to know implementation details of the ejb container timer service that I don't think it should. Its coupling of restoration to the server startup is also something it should not be dealing with. Restoration needs to be done on redeployment as well if timers persist across restarts.
Restoration of timers should be requests from the ejb deployer to the ejb timer service. Hence the addition of the restoreTimers(ObjectName) to the EJBTimerService interface. If we want the initial restoration to be coupled to completion of the server startup, this notion needs to be moved from the DatabasePersistencePolicy to the EJBTimerServiceImpl.