|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
The WorkManager is the abstraction for dispatching and monitoring asynchronous work and is a factory for creating application short or long lived Works.
WorkManagers are created by the server administrator. The vendor specific systems management console allows the administrator to create one or more WorkManagers and associate a JNDI name with each one. The administrator may specify implementation specific information such as min/max Works for each WorkManager. An application that requires a WorkManager should declare a resource-ref in the EJB or webapp that needs the WorkManager. The vendor descriptor editor or J2EE IDE can be used to bind this resource-ref to a physical WorkManager at deploy or development time. An EJB or servlet can then get a reference to a WorkManager by looking up the resource-ref name in JNDI and then casting it. For example, if the resource-ref was called wm/WorkManager:
<resource-ref> <res-ref-name>wm/WorkManager</res-ref-name> <res-type>commonj.work.WorkManager</res-type> <res-auth>Container</res-auth> <res-sharing-scope>Shareable</res-sharing-scope> </resource-ref>The Java code to look this up would look like:
InitialContext ic = new InitialContext();
WorkManager wm = (WorkManager)ic.lookup("java:comp/env/wm/WorkManager");
The res-auth and res-sharing scopes are ignored in this version of the specification.
The EJB or servlet can then use the WorkManager as it needs to.A WorkManager can also be a pinned WorkManager. This is a WorkManager obtained using the RemoteWorkItem.getWorkManager method. This allows subsequent scheduleWorks to be send to the same remote WorkManager as the one that is associated with the RemoteWorkItem. Pinned WorkManagers are only supported on vendor implementations that support remote Works. However, applications that follow the programming model will work on all implementations however serializable Works will be executed within the local JVM only on those implementations.
Work,
RemoteWorkItem| Field Summary | |
|---|---|
static long |
IMMEDIATE
This constant can be used as a timeout for the waitForXXX methods. |
static long |
INDEFINITE
This constant can be used as a timeout for either the waitForXXX methods. |
| Method Summary | |
|---|---|
WorkItem |
schedule(Work work)
Dispatches a Work asynchronously. |
WorkItem |
schedule(Work work,
WorkListener wl)
Dispatches a Work asynchronously. |
boolean |
waitForAll(java.util.Collection workItems,
long timeout_ms)
Wait for all WorkItems in the collection to finish successfully or otherwise. |
java.util.Collection |
waitForAny(java.util.Collection workItems,
long timeout_ms)
Wait for any of the WorkItems in the collection to finish. |
| Field Detail |
public static final long IMMEDIATE
public static final long INDEFINITE
| Method Detail |
public WorkItem schedule(Work work)
throws WorkException,
java.lang.IllegalArgumentException
At-most-once semantics are provided. If the server fails then the Work will not be executed on restart.
If this WorkManager is a pinned one, i.e. one obtained using RemoteWorkItem.getPinnedWorkManager() and that JVM that it
represents has failed then a WorkRejectedException will be thrown even if the remote JVM restarts. The pinned WorkManager
must be refreshed by using a normal WorkManager and then acquiring a new pinned WorkManager.
work - the Work to execute.
If - queuing this up results in an exception then a
WorkException is thrown.
java.lang.IllegalArgumentException - This is thrown if work is an Enterprise Bean.
WorkException
public WorkItem schedule(Work work,
WorkListener wl)
throws WorkException,
java.lang.IllegalArgumentException
At-most-once semantics are provided. If the server fails then the Work will not be executed on restart.
The WorkListener methods are called using the J2EE context of the caller as the Work progresses through processing.
If this WorkManager is a pinned one, i.e. one obtained using RemoteWorkItem.getPinnedWorkManager() and that JVM that it
represents has failed then a WorkRejectedException will be thrown even if the remote JVM restarts. The pinned WorkManager
must be refreshed by using a normal WorkManager and then acquiring a new pinned WorkManager.
work - the Work to execute.wl - can be null or a WorkListener which is used to inform
the application of the progress of a Work.
WorkException - If queuing this up results in an exception then a
WorkException is thrown.
java.lang.IllegalArgumentException - thrown if work is an Enterprise Bean or
public boolean waitForAll(java.util.Collection workItems,
long timeout_ms)
timeout_ms - the timout in milliseconds. If this is 0 then this method returns immediately.
public java.util.Collection waitForAny(java.util.Collection workItems,
long timeout_ms)
timeout_ms - the timeout in ms. If this is 0 then the method returns immediately, i.e. does not block.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||