| Method from org.jboss.ejb.txtimer.EJBTimerServiceImpl Detail: |
public TimerService createTimerService(ObjectName containerId,
Object instancePk,
Container container) {
TimedObjectInvoker invoker = null;
try
{
TimedObjectId timedObjectId = new TimedObjectId(containerId, instancePk);
Class invokerClass = getClass().getClassLoader().loadClass(timedObjectInvokerClassName);
Constructor constr = invokerClass.getConstructor(new Class[]{TimedObjectId.class, Container.class});
invoker = (TimedObjectInvoker)constr.newInstance(new Object[]{timedObjectId, container});
}
catch (Exception e)
{
log.error("Cannot create TimedObjectInvoker: " + timedObjectInvokerClassName, e);
return null;
}
return createTimerService(containerId, instancePk, invoker);
}
Create a TimerService for a given TimedObjectId that lives in a JBoss Container.
The TimedObjectInvoker is constructed from the invokerClassName. |
public TimerService createTimerService(ObjectName containerId,
Object instancePk,
TimedObjectInvoker invoker) {
TimedObjectId timedObjectId = new TimedObjectId(containerId, instancePk);
TimerServiceImpl timerService = (TimerServiceImpl)timerServiceMap.get(timedObjectId);
if (timerService == null)
{
timerService = new TimerServiceImpl(timedObjectId, invoker,
transactionManager, persistencePolicy, retryPolicy, timerIdGenerator);
log.debug("createTimerService: " + timerService);
timerServiceMap.put(timedObjectId, timerService);
}
return timerService;
}
Create a TimerService for a given TimedObjectId that is invoked through the given invoker |
public ObjectName getPersistencePolicy() {
return persistencePolicyName;
}
Get the object name of the persistence policy. |
public ObjectName getRetryPolicy() {
// Attributes ----------------------------------------------------
return retryPolicyName;
}
Get the object name of the retry policy. |
public String getTimedObjectInvokerClassName() {
return timedObjectInvokerClassName;
}
Get the TimedObjectInvoker class name |
public String getTimerIdGeneratorClassName() {
return timerIdGeneratorClassName;
}
Get the TimerIdGenerator class name |
public TimerService getTimerService(ObjectName containerId,
Object instancePk) {
TimedObjectId timedObjectId = new TimedObjectId(containerId, instancePk);
return (TimerServiceImpl)timerServiceMap.get(timedObjectId);
}
Get the TimerService for a given TimedObjectId |
public String listTimers() {
StringBuffer retBuffer = new StringBuffer();
Iterator it = timerServiceMap.entrySet().iterator();
while (it.hasNext())
{
Map.Entry entry = (Map.Entry)it.next();
TimedObjectId timedObjectId = (TimedObjectId)entry.getKey();
retBuffer.append(timedObjectId + "\n");
TimerServiceImpl timerService = (TimerServiceImpl)entry.getValue();
Collection col = timerService.getAllTimers();
for (Iterator iterator = col.iterator(); iterator.hasNext();)
{
TimerImpl timer = (TimerImpl)iterator.next();
TimerHandleImpl handle = new TimerHandleImpl(timer);
retBuffer.append(" handle: " + handle + "\n");
retBuffer.append(" " + timer + "\n");
}
}
return retBuffer.toString();
}
List the timers registered with all TimerService objects |
public void removeTimerService(ObjectName containerId,
Object instancePk) {
TimedObjectId timedObjectId = new TimedObjectId(containerId, instancePk);
// remove a single timer service
if (timedObjectId.getInstancePk() != null)
{
TimerServiceImpl timerService = (TimerServiceImpl)getTimerService(containerId, instancePk);
if (timerService != null)
{
log.debug("removeTimerService: " + timerService);
// don't keep persistent state about the timer
// this is really an entity- >remove()
timerService.shutdown(false);
timerServiceMap.remove(timedObjectId);
}
}
else
{
// assume we don't want to keep timer state when the container
// gets undeployed, this is the legacy behaviour
removeTimerService(containerId, false);
}
}
Remove the TimerService for a given containerId/pKey (TimedObjectId),
along with any persisted timer information.
This should be used for removing the TimerService and Timers
associated with a particular entity bean, when it gets removed. |
public void removeTimerService(ObjectName containerId,
boolean keepState) throws IllegalStateException {
// remove all timers with the given containerId
Iterator it = timerServiceMap.entrySet().iterator();
while (it.hasNext())
{
Map.Entry entry = (Map.Entry)it.next();
TimedObjectId key = (TimedObjectId)entry.getKey();
TimerServiceImpl timerService = (TimerServiceImpl)entry.getValue();
if (containerId.equals(key.getContainerId()))
{
log.debug("removeTimerService: " + timerService);
timerService.shutdown(keepState);
it.remove();
}
}
}
Remove the TimerService for a given containerId.
This should be used to remove the timer service and timers for
any type of container (session, entity, message) at the time of
undeployment. |
public void removeTimerService(ObjectName containerId,
Object instancePk,
boolean keepState) throws IllegalStateException {
// remove a single timer service
TimedObjectId timedObjectId = new TimedObjectId(containerId, instancePk);
if (timedObjectId.getInstancePk() != null)
{
TimerServiceImpl timerService = (TimerServiceImpl)getTimerService(containerId, instancePk);
if (timerService != null)
{
log.debug("removeTimerService: " + timerService);
timerService.shutdown(false);
timerServiceMap.remove(timedObjectId);
}
}
// remove all timers with the given containerId
else
{
Iterator it = timerServiceMap.entrySet().iterator();
while (it.hasNext())
{
Map.Entry entry = (Map.Entry)it.next();
TimedObjectId key = (TimedObjectId)entry.getKey();
TimerServiceImpl timerService = (TimerServiceImpl)entry.getValue();
if (containerId.equals(key.getContainerId()))
{
log.debug("removeTimerService: " + timerService);
timerService.shutdown(keepState);
it.remove();
}
}
}
}
Remove the TimerService for a given containerId/pKey (TimedObjectId). |
public void restoreTimers(ObjectName containerId,
ClassLoader loader) throws IllegalStateException {
assert persistencePolicy != null : "persistencePolicy is not set";
// find out all the persisted handles, for the specified container
List handles = persistencePolicy.listTimerHandles(containerId, loader);
if (handles.isEmpty() == false)
{
// first remove the persisted handles from the db
for (Iterator i = handles.iterator(); i.hasNext(); )
{
TimerHandleImpl handle = (TimerHandleImpl)i.next();
persistencePolicy.deleteTimer(handle.getTimerId(), handle.getTimedObjectId());
}
// make a second pass to re-create the timers; use the container
// itself to retrieve the correct TimerService/ for each handle,
// then use the standard ejb timer API to recreate the timer
for (Iterator i = handles.iterator(); i.hasNext(); )
{
TimerHandleImpl handle = (TimerHandleImpl)i.next();
try
{
TimedObjectId targetId = handle.getTimedObjectId();
ContainerMBean container = (ContainerMBean)MBeanProxyExt.create(ContainerMBean.class, containerId, server);
TimerService timerService = container.getTimerService(targetId.getInstancePk());
timerService.createTimer(handle.getFirstTime(), handle.getPeriode(), handle.getInfo());
}
catch (Exception e)
{
log.warn("Unable to restore timer record: " + handle, e);
}
}
}
}
Restore the persisted timers for a given ejb container |
public void setPersistencePolicy(ObjectName persistencePolicyName) {
this.persistencePolicyName = persistencePolicyName;
}
Set the object name of the persistence policy. |
public void setRetryPolicy(ObjectName retryPolicyName) {
this.retryPolicyName = retryPolicyName;
}
Set the object name of the retry policy. |
public void setTimedObjectInvokerClassName(String timedObjectInvokerClassName) {
this.timedObjectInvokerClassName = timedObjectInvokerClassName;
}
Set the TimedObjectInvoker class name |
public void setTimerIdGeneratorClassName(String timerIdGeneratorClassName) {
this.timerIdGeneratorClassName = timerIdGeneratorClassName;
}
Get the TimerIdGenerator class name |
public void setTransactionManagerFactory(TransactionManagerFactory factory) {
this.transactionManagerFactory = factory;
}
Set the TransactionManagerFactory |
protected void startService() throws Exception {
// Setup plugins, fall back to safe defaults
// Get the TransactionManager from the factory, fall-back to the locator
if (transactionManagerFactory != null)
transactionManager = transactionManagerFactory.getTransactionManager();
else
transactionManager = TransactionManagerLocator.getInstance().locate();
// Get a proxy to the retry policy
try
{
retryPolicy = (RetryPolicy)MBeanProxyExt.create(RetryPolicy.class, getRetryPolicy(), server);
}
catch (Exception e)
{
log.error("Cannot obtain the implementation of a RetryPolicy", e);
}
// Get a proxy to the persistence policy
try
{
persistencePolicy = (PersistencePolicy)MBeanProxyExt.create(PersistencePolicy.class, persistencePolicyName, server);
}
catch (Exception e)
{
log.warn("Cannot obtain the implementation of a PersistencePolicy, using NoopPersistencePolicy: " + e.toString());
persistencePolicy = new NoopPersistencePolicy();
}
// Get the timerId generator
try
{
Class timerIdGeneratorClass = getClass().getClassLoader().loadClass(timerIdGeneratorClassName);
timerIdGenerator = (TimerIdGenerator)timerIdGeneratorClass.newInstance();
}
catch (Exception e)
{
log.warn("Cannot obtain the implementation of a TimerIdGenerator, using BigIntegerTimerIdGenerator: " + e.toString());
timerIdGenerator = new BigIntegerTimerIdGenerator();
}
}
|
protected void stopService() {
// Cleanup plugins
transactionManager = null;
retryPolicy = null;
persistencePolicy = null;
timerIdGenerator = null;
}
|