org.ow2.easybeans.jca.workmanager
Class ResourceWorkManager

java.lang.Object
  extended by org.ow2.easybeans.jca.workmanager.ResourceWorkManager
All Implemented Interfaces:
WorkManager

public class ResourceWorkManager
extends java.lang.Object
implements WorkManager

Implementation of the Resource Work Manager API.

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

Field Summary
 
Fields inherited from interface javax.resource.spi.work.WorkManager
IMMEDIATE, INDEFINITE, UNKNOWN
 
Constructor Summary
ResourceWorkManager(TransactionManager transactionManager, int minsz, int maxsz, long threadwait)
          Default Constructor.
 
Method Summary
 void doWork(Work work)
          Accepts a Work instance for processing.
 void doWork(Work work, long timeout, ExecutionContext executionContext, 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(Work work)
          Accepts a Work instance for processing.
 void scheduleWork(Work work, long timeout, ExecutionContext executionContext, 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(Work work)
          Accepts a Work instance for processing.
 long startWork(Work work, long timeout, ExecutionContext executionContext, 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
 

Constructor Detail

ResourceWorkManager

public ResourceWorkManager(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(Work work)
            throws WorkRejectedException,
                   WorkCompletedException,
                   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 WorkManager
Parameters:
work - The unit of work to be done. Could be long or short-lived.
Throws:
WorkRejectedException - a Work instance has been rejected from further processing.
WorkCompletedException - a Work instance has completed execution with an exception.
WorkException - if work is not done

doWork

public void doWork(Work work,
                   long timeout,
                   ExecutionContext executionContext,
                   WorkListener workListener)
            throws WorkRejectedException,
                   WorkCompletedException,
                   WorkException
Accepts a Work instance for processing. This call blocks until the Work instance completes execution.

Specified by:
doWork in interface 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:
WorkRejectedException - a Work instance has been rejected from further processing.
WorkCompletedException - a Work instance has completed execution with an exception.
WorkException - if work is not done

startWork

public long startWork(Work work)
               throws WorkRejectedException,
                      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 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:
WorkRejectedException - a Work instance has been rejected from further processing.
WorkException - if work is not started

startWork

public long startWork(Work work,
                      long timeout,
                      ExecutionContext executionContext,
                      WorkListener workListener)
               throws WorkRejectedException,
                      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 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:
WorkRejectedException - a Work instance has been rejected from further processing.
WorkException - if work is not started

scheduleWork

public void scheduleWork(Work work)
                  throws WorkRejectedException,
                         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 WorkManager
Parameters:
work - The unit of work to be done. Could be long or short-lived.
Throws:
WorkRejectedException - - indicates that a Work instance has been rejected from further processing. This can occur due to internal factors.
WorkException - if work is not scheduled.

scheduleWork

public void scheduleWork(Work work,
                         long timeout,
                         ExecutionContext executionContext,
                         WorkListener workListener)
                  throws WorkRejectedException,
                         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 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:
WorkRejectedException - a Work instance has been rejected from further processing.
WorkException - if work is not scheduled.

nextWork

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

Throws:
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.



Copyright © 2006-2009 OW2 Consortium. All Rights Reserved.