org.objectweb.jonas_lib
Class JWorkManager

java.lang.Object
  extended by org.objectweb.jonas_lib.JWorkManager
All Implemented Interfaces:
javax.resource.spi.work.WorkManager

public class JWorkManager
extends java.lang.Object
implements javax.resource.spi.work.WorkManager

Jonas Implementation of the Resource Work Manager

Author:
durieuxp

Field Summary
protected static long FEW_MORE_SECONDS
           
protected  int freeThreads
           
protected  int maxpoolsz
           
protected  int minpoolsz
           
protected static int poolnumber
           
protected  int poolsz
           
protected static int threadnumber
           
protected  boolean valid
           
protected  long waitingTime
           
protected  java.util.LinkedList workList
           
 
Fields inherited from interface javax.resource.spi.work.WorkManager
IMMEDIATE, INDEFINITE, UNKNOWN
 
Constructor Summary
JWorkManager(int minsz, int maxsz, org.objectweb.transaction.jta.TransactionManager tm, long threadwait)
          Constructor
 
Method Summary
 void doWork(javax.resource.spi.work.Work work)
          Accepts a Work instance for processing.
 void doWork(javax.resource.spi.work.Work work, long timeout, javax.resource.spi.work.ExecutionContext ectx, javax.resource.spi.work.WorkListener listener)
          Accepts a Work instance for processing.
 int getCurrentPoolSize()
           
 int getMaxPoolSize()
           
 int getMinPoolSize()
           
 void nextWork()
          Get the next JWork object to be run.
 void scheduleWork(javax.resource.spi.work.Work work)
          Accepts a Work instance for processing.
 void scheduleWork(javax.resource.spi.work.Work work, long timeout, javax.resource.spi.work.ExecutionContext ectx, javax.resource.spi.work.WorkListener listener)
          Accepts a Work instance for processing.
 void setMaxPoolSize(int maxsz)
          Set the max pool size
 void setMinPoolSize(int minsz)
          Set the min pool size
 long startWork(javax.resource.spi.work.Work work)
          Accepts a Work instance for processing.
 long startWork(javax.resource.spi.work.Work work, long timeout, javax.resource.spi.work.ExecutionContext ectx, javax.resource.spi.work.WorkListener listener)
          Accepts a Work instance for processing.
 void stopThreads()
          Remove this WorkManager : Stop all threads
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

workList

protected java.util.LinkedList workList

poolnumber

protected static int poolnumber

threadnumber

protected static int threadnumber

maxpoolsz

protected int maxpoolsz

minpoolsz

protected int minpoolsz

poolsz

protected int poolsz

freeThreads

protected int freeThreads

waitingTime

protected long waitingTime

valid

protected boolean valid

FEW_MORE_SECONDS

protected static final long FEW_MORE_SECONDS
See Also:
Constant Field Values
Constructor Detail

JWorkManager

public JWorkManager(int minsz,
                    int maxsz,
                    org.objectweb.transaction.jta.TransactionManager tm,
                    long threadwait)
Constructor

Parameters:
threadwait - max time in seconds a thread will wait
Method Detail

getCurrentPoolSize

public int getCurrentPoolSize()
Returns:
current pool size

getMinPoolSize

public int getMinPoolSize()
Returns:
min pool size

getMaxPoolSize

public int getMaxPoolSize()
Returns:
max pool size

setMinPoolSize

public void setMinPoolSize(int minsz)
Set the min pool size

Parameters:
minsz -

setMaxPoolSize

public void setMaxPoolSize(int maxsz)
Set the max pool size

Parameters:
maxsz -

doWork

public void doWork(javax.resource.spi.work.Work work)
            throws javax.resource.spi.work.WorkException
Accepts a Work instance for processing. This call blocks until the Work instance completes execution. There is no guarantee on when the accepted Work instance would start execution ie., there is no time constraint to start execution.

Specified by:
doWork in interface javax.resource.spi.work.WorkManager
Parameters:
work - The unit of work to be done. Could be long or short-lived.
Throws:
javax.resource.spi.work.WorkRejectedException - a Work instance has been rejected from further processing.
javax.resource.spi.work.WorkCompletedException - a Work instance has completed execution with an exception.
javax.resource.spi.work.WorkException

doWork

public void doWork(javax.resource.spi.work.Work work,
                   long timeout,
                   javax.resource.spi.work.ExecutionContext ectx,
                   javax.resource.spi.work.WorkListener listener)
            throws javax.resource.spi.work.WorkException
Accepts a Work instance for processing. This call blocks until the Work instance completes execution.

Specified by:
doWork in interface javax.resource.spi.work.WorkManager
Parameters:
work - The unit of work to be done. Could be long or short-lived.
timeout - a time duration (in milliseconds) within which the execution of the Work instance must start. Otherwise, the Work instance is rejected with a WorkRejectedException set to an appropriate error code (WorkRejectedException.TIMED_OUT).
ectx - an object containing the execution context with which the submitted Work instance must be executed.
listener - an object which would be notified when the various Work processing events (work accepted, work rejected, work started, work completed) occur.
Throws:
javax.resource.spi.work.WorkRejectedException - a Work instance has been rejected from further processing.
javax.resource.spi.work.WorkCompletedException - a Work instance has completed execution with an exception.
javax.resource.spi.work.WorkException

startWork

public long startWork(javax.resource.spi.work.Work work)
               throws javax.resource.spi.work.WorkException
Accepts a Work instance for processing. This call blocks until the Work instance starts execution but not until its completion. There is no guarantee on when the accepted Work instance would start execution ie., there is no time constraint to start execution.

Specified by:
startWork in interface javax.resource.spi.work.WorkManager
Parameters:
work - The unit of work to be done. Could be long or short-lived.
Returns:
the time elapsed (in milliseconds) from Work acceptance until start of execution. Note, this does not offer real-time guarantees. It is valid to return -1, if the actual start delay duration is unknown.
Throws:
javax.resource.spi.work.WorkRejectedException - a Work instance has been rejected from further processing.
javax.resource.spi.work.WorkException

startWork

public long startWork(javax.resource.spi.work.Work work,
                      long timeout,
                      javax.resource.spi.work.ExecutionContext ectx,
                      javax.resource.spi.work.WorkListener listener)
               throws javax.resource.spi.work.WorkException
Accepts a Work instance for processing. This call blocks until the Work instance starts execution but not until its completion. There is no guarantee on when the accepted Work instance would start execution ie., there is no time constraint to start execution.

Specified by:
startWork in interface javax.resource.spi.work.WorkManager
Parameters:
work - The unit of work to be done. Could be long or short-lived.
timeout - a time duration (in milliseconds) within which the execution of the Work instance must start. Otherwise, the Work instance is rejected with a WorkRejectedException set to an appropriate error code (WorkRejectedException.TIMED_OUT).
ectx - an object containing the execution context with which the submitted Work instance must be executed.
listener - an object which would be notified when the various Work processing events (work accepted, work rejected, work started, work completed) occur.
Returns:
the time elapsed (in milliseconds) from Work acceptance until start of execution. Note, this does not offer real-time guarantees. It is valid to return -1, if the actual start delay duration is unknown.
Throws:
javax.resource.spi.work.WorkRejectedException - a Work instance has been rejected from further processing.
javax.resource.spi.work.WorkException

scheduleWork

public void scheduleWork(javax.resource.spi.work.Work work)
                  throws javax.resource.spi.work.WorkException
Accepts a Work instance for processing. This call does not block and returns immediately once a Work instance has been accepted for processing. There is no guarantee on when the submitted Work instance would start execution ie., there is no time constraint to start execution.

Specified by:
scheduleWork in interface javax.resource.spi.work.WorkManager
Parameters:
work - The unit of work to be done. Could be long or short-lived.
timeout - a time duration (in milliseconds) within which the execution of the Work instance must start. Otherwise, the Work instance is rejected with a WorkRejectedException set to an appropriate error code (WorkRejectedException.TIMED_OUT).
ectx - an object containing the execution context with which the submitted Work instance must be executed.
listener - an object which would be notified when the various Work processing events (work accepted, work rejected, work started, work completed) occur.
Throws:
javax.resource.spi.work.WorkRejectedException - a Work instance has been rejected from further processing.
javax.resource.spi.work.WorkException

scheduleWork

public void scheduleWork(javax.resource.spi.work.Work work,
                         long timeout,
                         javax.resource.spi.work.ExecutionContext ectx,
                         javax.resource.spi.work.WorkListener listener)
                  throws javax.resource.spi.work.WorkException
Accepts a Work instance for processing. This call does not block and returns immediately once a Work instance has been accepted for processing. There is no guarantee on when the submitted Work instance would start execution ie., there is no time constraint to start execution.

Specified by:
scheduleWork in interface javax.resource.spi.work.WorkManager
Parameters:
work - The unit of work to be done. Could be long or short-lived.
timeout - a time duration (in milliseconds) within which the execution of the Work instance must start. Otherwise, the Work instance is rejected with a WorkRejectedException set to an appropriate error code (WorkRejectedException.TIMED_OUT).
ectx - an object containing the execution context with which the submitted Work instance must be executed.
listener - an object which would be notified when the various Work processing events (work accepted, work rejected, work started, work completed) occur.
Throws:
javax.resource.spi.work.WorkRejectedException - a Work instance has been rejected from further processing.
javax.resource.spi.work.WorkException

nextWork

public void nextWork()
              throws javax.resource.spi.work.WorkException,
                     java.lang.InterruptedException
Get the next JWork object to be run.

Throws:
javax.resource.spi.work.WorkException
java.lang.InterruptedException

stopThreads

public void stopThreads()
Remove this WorkManager : Stop all threads