FileDocCategorySizeDatePackage
JBossWorkManager.javaAPI DocJBoss 4.2.18018Fri Jul 13 21:01:18 BST 2007org.jboss.resource.work

JBossWorkManager

public class JBossWorkManager extends org.jboss.system.ServiceMBeanSupport implements JBossWorkManagerMBean, javax.resource.spi.work.WorkManager
The work manager implementation
author
Adrian Brock
version
$Revision: 59886 $

Fields Summary
private boolean
trace
Whether trace is enabled
private org.jboss.util.threadpool.ThreadPool
threadPool
The thread pool
private ObjectName
threadPoolName
The thread pool name
private org.jboss.tm.JBossXATerminator
xaTerminator
The xa terminator
private ObjectName
xaTerminatorName
The xa terminator name
Constructors Summary
Methods Summary
protected voidcancelWork(WorkWrapper wrapper)
Cancel work

param
wrapper the work wrapper
throws
WorkException for any error

      if (trace)
         log.trace("Cancel work " + wrapper);

      ExecutionContext ctx = wrapper.getExecutionContext();
      if (ctx != null)
      {
         Xid xid = ctx.getXid();
         if (xid != null)
         {
            xaTerminator.cancelWork(wrapper.getWork(), xid);
         }
      }
      if (trace)
         log.trace("Canceled work " + wrapper);
   
public voiddoWork(javax.resource.spi.work.Work work, long startTimeout, javax.resource.spi.work.ExecutionContext ctx, javax.resource.spi.work.WorkListener listener)

      if (ctx == null)
         ctx = new ExecutionContext();
      WorkWrapper wrapper = new WorkWrapper(this, work, Task.WAIT_FOR_COMPLETE, startTimeout, ctx, listener);
      importWork(wrapper);
      executeWork(wrapper);
      if (wrapper.getWorkException() != null)
         throw wrapper.getWorkException();
   
public voiddoWork(javax.resource.spi.work.Work work)

      doWork(work, WorkManager.INDEFINITE, null, null);
   
protected voidendWork(WorkWrapper wrapper)
End work

param
wrapper the work wrapper
throws
WorkException for any error

      if (trace)
         log.trace("Ending work " + wrapper);

      ExecutionContext ctx = wrapper.getExecutionContext();
      if (ctx != null)
      {
         Xid xid = ctx.getXid();
         if (xid != null)
         {
            xaTerminator.endWork(wrapper.getWork(), xid);
         }
      }
      if (trace)
         log.trace("Ended work " + wrapper);
   
protected voidexecuteWork(WorkWrapper wrapper)
Execute the work

param
wrapper the work wrapper
throws
WorkException for any error

      if (trace)
         log.trace("Submitting work to thread pool " + wrapper);

      threadPool.runTaskWrapper(wrapper);

      if (trace)
         log.trace("Submitted work to thread pool " + wrapper);
   
public javax.resource.spi.work.WorkManagergetInstance()

      return this;
   
public org.jboss.util.threadpool.ThreadPoolgetThreadPool()
Retrieve the thread pool

return
the thread pool


               
     
   
      return threadPool;
   
public javax.management.ObjectNamegetThreadPoolName()

      return threadPoolName;
   
public javax.management.ObjectNamegetXATerminatorName()

      return xaTerminatorName;
   
protected voidimportWork(WorkWrapper wrapper)
Import any work

param
wrapper the work wrapper
throws
WorkException for any error

      trace = log.isTraceEnabled();
      if (trace)
         log.trace("Importing work " + wrapper);
      
      ExecutionContext ctx = wrapper.getExecutionContext();
      if (ctx != null)
      {
         Xid xid = ctx.getXid();
         if (xid != null)
         {
            //JBAS-4002 base value is in seconds as per the API, here we convert to millis
            long timeout = (ctx.getTransactionTimeout() * 1000);
            xaTerminator.registerWork(wrapper.getWork(), xid, timeout);
         }
      }
      if (trace)
         log.trace("Imported work " + wrapper);
   
public voidscheduleWork(javax.resource.spi.work.Work work, long startTimeout, javax.resource.spi.work.ExecutionContext ctx, javax.resource.spi.work.WorkListener listener)

      if (ctx == null)
         ctx = new ExecutionContext();
      WorkWrapper wrapper = new WorkWrapper(this, work, Task.WAIT_NONE, startTimeout, ctx, listener);
      importWork(wrapper);
      executeWork(wrapper);
      if (wrapper.getWorkException() != null)
         throw wrapper.getWorkException();
   
public voidscheduleWork(javax.resource.spi.work.Work work)

      scheduleWork(work, WorkManager.INDEFINITE, null, null);
   
public voidsetThreadPool(org.jboss.util.threadpool.ThreadPool threadPool)
Set the thread pool

param
threadPool the thread pool

      this.threadPool = threadPool;
   
public voidsetThreadPoolName(javax.management.ObjectName threadPoolName)

      this.threadPoolName = threadPoolName;
   
public voidsetXATerminatorName(javax.management.ObjectName xaTerminatorName)

      this.xaTerminatorName = xaTerminatorName;
   
protected voidstartService()

      if (threadPoolName == null)
         throw new IllegalStateException("No thread pool name");

      threadPool = (ThreadPool) server.getAttribute(threadPoolName, "Instance");

      if (xaTerminatorName == null)
         throw new IllegalStateException("No xa terminator name");

      xaTerminator = (JBossXATerminator) server.getAttribute(xaTerminatorName, "XATerminator");
   
public longstartWork(javax.resource.spi.work.Work work, long startTimeout, javax.resource.spi.work.ExecutionContext ctx, javax.resource.spi.work.WorkListener listener)

      if (ctx == null)
         ctx = new ExecutionContext();
      WorkWrapper wrapper = new WorkWrapper(this, work, Task.WAIT_FOR_START, startTimeout, ctx, listener);
      importWork(wrapper);
      executeWork(wrapper);
      if (wrapper.getWorkException() != null)
         throw wrapper.getWorkException();
      return wrapper.getBlockedElapsed();
   
public longstartWork(javax.resource.spi.work.Work work)

      return startWork(work, WorkManager.INDEFINITE, null, null);
   
protected voidstartWork(WorkWrapper wrapper)
Start work

param
wrapper the work wrapper
throws
WorkException for any error

      if (trace)
         log.trace("Starting work " + wrapper);

      ExecutionContext ctx = wrapper.getExecutionContext();
      if (ctx != null)
      {
         Xid xid = ctx.getXid();
         if (xid != null)
         {
            xaTerminator.startWork(wrapper.getWork(), xid);
         }
      }
      if (trace)
         log.trace("Started work " + wrapper);