|
spring-context-support | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.springframework.jndi.JndiAccessor
org.springframework.jndi.JndiLocatorSupport
org.springframework.scheduling.commonj.WorkManagerTaskExecutor
public class WorkManagerTaskExecutor
TaskExecutor implementation that delegates to a CommonJ WorkManager,
implementing the WorkManager
interface,
which either needs to be specified as reference or through the JNDI name.
This is the central convenience class for setting up a CommonJ WorkManager in a Spring context.
Also implements the CommonJ WorkManager interface itself, delegating all calls to the target WorkManager. Hence, a caller can choose whether it wants to talk to this executor through the Spring TaskExecutor interface or the CommonJ WorkManager interface.
The CommonJ WorkManager will usually be retrieved from the application server's JNDI environment, as defined in the server's management console.
Note: At the time of this writing, the CommonJ WorkManager facility is only supported on IBM WebSphere 6.0+ and BEA WebLogic 9.0+, despite being such a crucial API for an application server. (There is a similar facility available on WebSphere 5.1 Enterprise, though, which we will discuss below.)
On JBoss and GlassFish, a similar facility is available through
the JCA WorkManager. See the
org.springframework.jca.work.jboss.JBossWorkManagerTaskExecutor
org.springframework.jca.work.glassfish.GlassFishWorkManagerTaskExecutor
classes which are the direct equivalent of this CommonJ adapter class.
A similar facility is available on WebSphere 5.1, under the name "Asynch Beans". Its central interface is called WorkManager too and is also obtained from JNDI, just like a standard CommonJ WorkManager. However, this WorkManager variant is notably different: The central execution method is called "startWork" instead of "schedule", and takes a slightly different Work interface as parameter.
Support for this WebSphere 5.1 variant can be built with this class
and its helper DelegatingWork as template: Call the WorkManager's
startWork(Work)
instead of schedule(Work)
in the execute(Runnable)
implementation. Furthermore,
for simplicity's sake, drop the entire "Implementation of the CommonJ
WorkManager interface" section (and the corresponding
implements WorkManager
clause at the class level).
Of course, you also need to change all commonj.work
imports in
your WorkManagerTaskExecutor and DelegatingWork variants to the corresponding
WebSphere API imports (com.ibm.websphere.asynchbeans.WorkManager
and com.ibm.websphere.asynchbeans.Work
, respectively).
This should be sufficient to get a TaskExecutor adapter for WebSphere 5.
Field Summary |
---|
Fields inherited from class org.springframework.jndi.JndiLocatorSupport |
---|
CONTAINER_PREFIX |
Fields inherited from class org.springframework.jndi.JndiAccessor |
---|
logger |
Fields inherited from interface org.springframework.core.task.AsyncTaskExecutor |
---|
TIMEOUT_IMMEDIATE, TIMEOUT_INDEFINITE |
Fields inherited from interface commonj.work.WorkManager |
---|
IMMEDIATE, INDEFINITE |
Constructor Summary | |
---|---|
WorkManagerTaskExecutor()
|
Method Summary | ||
---|---|---|
void |
afterPropertiesSet()
|
|
void |
execute(java.lang.Runnable task)
|
|
void |
execute(java.lang.Runnable task,
long startTimeout)
|
|
boolean |
prefersShortLivedTasks()
This task executor prefers short-lived work units. |
|
commonj.work.WorkItem |
schedule(commonj.work.Work work)
|
|
commonj.work.WorkItem |
schedule(commonj.work.Work work,
commonj.work.WorkListener workListener)
|
|
void |
setWorkListener(commonj.work.WorkListener workListener)
Specify a CommonJ WorkListener to apply, if any. |
|
void |
setWorkManager(commonj.work.WorkManager workManager)
Specify the CommonJ WorkManager to delegate to. |
|
void |
setWorkManagerName(java.lang.String workManagerName)
Set the JNDI name of the CommonJ WorkManager. |
|
|
submit(java.util.concurrent.Callable<T> task)
|
|
java.util.concurrent.Future<?> |
submit(java.lang.Runnable task)
|
|
boolean |
waitForAll(java.util.Collection workItems,
long timeout)
|
|
java.util.Collection |
waitForAny(java.util.Collection workItems,
long timeout)
|
Methods inherited from class org.springframework.jndi.JndiLocatorSupport |
---|
convertJndiName, isResourceRef, lookup, lookup, setResourceRef |
Methods inherited from class org.springframework.jndi.JndiAccessor |
---|
getJndiEnvironment, getJndiTemplate, setJndiEnvironment, setJndiTemplate |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public WorkManagerTaskExecutor()
Method Detail |
---|
public void setWorkManager(commonj.work.WorkManager workManager)
Alternatively, you can also specify the JNDI name of the target WorkManager.
setWorkManagerName(java.lang.String)
public void setWorkManagerName(java.lang.String workManagerName)
This can either be a fully qualified JNDI name, or the JNDI name relative to the current environment naming context if "resourceRef" is set to "true".
setWorkManager(commonj.work.WorkManager)
,
JndiLocatorSupport.setResourceRef(boolean)
public void setWorkListener(commonj.work.WorkListener workListener)
This shared WorkListener instance will be passed on to the
WorkManager by all execute(java.lang.Runnable)
calls on this TaskExecutor.
public void afterPropertiesSet() throws javax.naming.NamingException
afterPropertiesSet
in interface org.springframework.beans.factory.InitializingBean
javax.naming.NamingException
public void execute(java.lang.Runnable task)
execute
in interface java.util.concurrent.Executor
execute
in interface org.springframework.core.task.TaskExecutor
public void execute(java.lang.Runnable task, long startTimeout)
execute
in interface org.springframework.core.task.AsyncTaskExecutor
public java.util.concurrent.Future<?> submit(java.lang.Runnable task)
submit
in interface org.springframework.core.task.AsyncTaskExecutor
public <T> java.util.concurrent.Future<T> submit(java.util.concurrent.Callable<T> task)
submit
in interface org.springframework.core.task.AsyncTaskExecutor
public boolean prefersShortLivedTasks()
prefersShortLivedTasks
in interface org.springframework.scheduling.SchedulingTaskExecutor
public commonj.work.WorkItem schedule(commonj.work.Work work) throws commonj.work.WorkException, java.lang.IllegalArgumentException
schedule
in interface commonj.work.WorkManager
commonj.work.WorkException
java.lang.IllegalArgumentException
public commonj.work.WorkItem schedule(commonj.work.Work work, commonj.work.WorkListener workListener) throws commonj.work.WorkException, java.lang.IllegalArgumentException
schedule
in interface commonj.work.WorkManager
commonj.work.WorkException
java.lang.IllegalArgumentException
public boolean waitForAll(java.util.Collection workItems, long timeout) throws java.lang.InterruptedException, java.lang.IllegalArgumentException
waitForAll
in interface commonj.work.WorkManager
java.lang.InterruptedException
java.lang.IllegalArgumentException
public java.util.Collection waitForAny(java.util.Collection workItems, long timeout) throws java.lang.InterruptedException, java.lang.IllegalArgumentException
waitForAny
in interface commonj.work.WorkManager
java.lang.InterruptedException
java.lang.IllegalArgumentException
|
spring-context-support | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |