org.objectweb.easybeans.jca.workmanager
Class ResourceWorkManager

java.lang.Object
  extended by org.objectweb.easybeans.jca.workmanager.ResourceWorkManager
All Implemented Interfaces:
javax.resource.spi.work.WorkManager

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

Implementation of the Resource Work Manager API.

Author:
Philippe Durieux (JOnAS), Florent Benoit (EasyBeans)

Field Summary
private static long FEW_MORE_SECONDS
          Wait few more seconds when waiting.
private  int freeThreads
          Threads that are ready to work.
private static JLog logger
          Logger.
private  int maxpoolsz
          The maximum size of the pool.
private static long MILLISECONDS
          MilliSeconds value.
private  int minpoolsz
          The minimum size of the pool.
private static int poolnumber
          Identifier of this pool.
private  int poolsz
          The current size of thread pool.
private  boolean stopped
          Pool status : by default, it is not stopped.
private static int threadnumber
          Thread number (when building ResourceWorkThread, it assigns a new thread number).
private  javax.transaction.TransactionManager transactionManager
          TransactionManager to use.
private  long waitingTime
          The time to wait (in millisec).
private  java.util.LinkedList<ResourceWork> workList
          List of ResourceWork (which wrap Work object).
 
Fields inherited from interface javax.resource.spi.work.WorkManager
IMMEDIATE, INDEFINITE, UNKNOWN
 
Constructor Summary
ResourceWorkManager(javax.transaction.TransactionManager transactionManager, int minsz, int maxsz, long threadwait)
          Default Constructor.
 
Method Summary
private  void doMyWork(javax.resource.spi.work.Work work, long timeout, javax.resource.spi.work.ExecutionContext executionContext, javax.resource.spi.work.WorkListener workListener, long creationTime)
          Internal method doing the work.
 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 executionContext, javax.resource.spi.work.WorkListener workListener)
          Accepts a Work instance for processing.
 int getCurrentPoolSize()
           
 int getMaxPoolSize()
           
 int getMinPoolSize()
           
 void nextWork()
          Do 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 executionContext, javax.resource.spi.work.WorkListener workListener)
          Accepts a Work instance for processing.
 void setMaxPoolSize(int maxsz)
          Sets the max pool size.
 void setMinPoolSize(int minsz)
          Sets 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 executionContext, javax.resource.spi.work.WorkListener workListener)
          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

MILLISECONDS

private static final long MILLISECONDS
MilliSeconds value.

See Also:
Constant Field Values

logger

private static JLog logger
Logger.


workList

private java.util.LinkedList<ResourceWork> workList
List of ResourceWork (which wrap Work object).


poolnumber

private static int poolnumber
Identifier of this pool.


threadnumber

private static int threadnumber
Thread number (when building ResourceWorkThread, it assigns a new thread number).


maxpoolsz

private int maxpoolsz
The maximum size of the pool.


minpoolsz

private int minpoolsz
The minimum size of the pool.


poolsz

private int poolsz
The current size of thread pool.


freeThreads

private int freeThreads
Threads that are ready to work.


waitingTime

private long waitingTime
The time to wait (in millisec).


stopped

private boolean stopped
Pool status : by default, it is not stopped.


FEW_MORE_SECONDS

private static final long FEW_MORE_SECONDS
Wait few more seconds when waiting.

See Also:
Constant Field Values

transactionManager

private javax.transaction.TransactionManager transactionManager
TransactionManager to use.

Constructor Detail

ResourceWorkManager

public ResourceWorkManager(javax.transaction.TransactionManager transactionManager,
                           int minsz,
                           int maxsz,
                           long threadwait)
Default Constructor.

Parameters:
minsz - the minimum pool size
maxsz - the maximum pool size
transactionManager - the transaction manager to use.
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)
Sets the min pool size.

Parameters:
minsz - the min pool size.

setMaxPoolSize

public void setMaxPoolSize(int maxsz)
Sets the max pool size.

Parameters:
maxsz - the max pool size.

doWork

public void doWork(javax.resource.spi.work.Work work)
            throws javax.resource.spi.work.WorkRejectedException,
                   javax.resource.spi.work.WorkCompletedException,
                   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 - if work is not done

doWork

public void doWork(javax.resource.spi.work.Work work,
                   long timeout,
                   javax.resource.spi.work.ExecutionContext executionContext,
                   javax.resource.spi.work.WorkListener workListener)
            throws javax.resource.spi.work.WorkRejectedException,
                   javax.resource.spi.work.WorkCompletedException,
                   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).
executionContext - an object containing the execution context with which the submitted Work instance must be executed.
workListener - 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 - if work is not done

startWork

public long startWork(javax.resource.spi.work.Work work)
               throws javax.resource.spi.work.WorkRejectedException,
                      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 - if work is not started

startWork

public long startWork(javax.resource.spi.work.Work work,
                      long timeout,
                      javax.resource.spi.work.ExecutionContext executionContext,
                      javax.resource.spi.work.WorkListener workListener)
               throws javax.resource.spi.work.WorkRejectedException,
                      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).
executionContext - an object containing the execution context with which the submitted Work instance must be executed.
workListener - 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 - if work is not started

scheduleWork

public void scheduleWork(javax.resource.spi.work.Work work)
                  throws javax.resource.spi.work.WorkRejectedException,
                         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.
Throws:
javax.resource.spi.work.WorkRejectedException - - indicates that a Work instance has been rejected from further processing. This can occur due to internal factors.
javax.resource.spi.work.WorkException - if work is not scheduled.

scheduleWork

public void scheduleWork(javax.resource.spi.work.Work work,
                         long timeout,
                         javax.resource.spi.work.ExecutionContext executionContext,
                         javax.resource.spi.work.WorkListener workListener)
                  throws javax.resource.spi.work.WorkRejectedException,
                         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).
executionContext - an object containing the execution context with which the submitted Work instance must be executed.
workListener - 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 - if work is not scheduled.

doMyWork

private void doMyWork(javax.resource.spi.work.Work work,
                      long timeout,
                      javax.resource.spi.work.ExecutionContext executionContext,
                      javax.resource.spi.work.WorkListener workListener,
                      long creationTime)
               throws javax.resource.spi.work.WorkException
Internal method doing the work.

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).
executionContext - an object containing the execution context with which the submitted Work instance must be executed.
workListener - an object which would be notified when the various Work processing events (work accepted, work rejected, work started, work completed) occur.
creationTime - the date of the creation of the work
Throws:
javax.resource.spi.work.WorkException - if work is not performed.

nextWork

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

Throws:
javax.resource.spi.work.WorkException - if work is not done
java.lang.InterruptedException - if one object can't wait.
ResourceWorkManagerStoppedException - if the manager is stopped.

stopThreads

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