public class WorkManagerTaskExecutor extends org.springframework.jndi.JndiLocatorSupport implements org.springframework.core.task.AsyncListenableTaskExecutor, org.springframework.scheduling.SchedulingTaskExecutor, WorkManager, BootstrapContextAware, org.springframework.beans.factory.InitializingBean
TaskExecutor implementation
that delegates to a JCA 1.5 WorkManager, implementing the
WorkManager interface.
This is mainly intended for use within a JCA ResourceAdapter implementation, but may also be used in a standalone environment, delegating to a locally embedded WorkManager implementation (such as Geronimo's).
Also implements the JCA 1.5 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 JCA 1.5 WorkManager interface.
This adapter is also capable of obtaining a JCA WorkManager from JNDI.
This is for example appropriate on the Geronimo application server, where
WorkManager GBeans (e.g. Geronimo's default "DefaultWorkManager" GBean)
can be linked into the J2EE environment through "gbean-ref" entries
in the geronimo-web.xml deployment descriptor.
On JBoss and GlassFish, obtaining the default JCA WorkManager
requires special lookup steps. See the
JBossWorkManagerTaskExecutor
GlassFishWorkManagerTaskExecutor
classes which are the direct equivalent of this generic JCA adapter class.
setWorkManager(javax.resource.spi.work.WorkManager),
WorkManager.scheduleWork(javax.resource.spi.work.Work)TIMEOUT_IMMEDIATE, TIMEOUT_INDEFINITEIMMEDIATE, INDEFINITE, UNKNOWN| Constructor and Description |
|---|
WorkManagerTaskExecutor()
Create a new WorkManagerTaskExecutor, expecting bean-style configuration.
|
WorkManagerTaskExecutor(WorkManager workManager)
Create a new WorkManagerTaskExecutor for the given WorkManager.
|
| Modifier and Type | Method and Description |
|---|---|
void |
afterPropertiesSet() |
void |
doWork(Work work) |
void |
doWork(Work work,
long delay,
ExecutionContext executionContext,
WorkListener workListener) |
void |
execute(java.lang.Runnable task) |
void |
execute(java.lang.Runnable task,
long startTimeout) |
protected WorkManager |
getDefaultWorkManager()
Obtain a default WorkManager to delegate to.
|
boolean |
prefersShortLivedTasks()
This task executor prefers short-lived work units.
|
void |
scheduleWork(Work work) |
void |
scheduleWork(Work work,
long delay,
ExecutionContext executionContext,
WorkListener workListener) |
void |
setBlockUntilCompleted(boolean blockUntilCompleted)
Set whether to let
execute(java.lang.Runnable) block until the work
has been completed. |
void |
setBlockUntilStarted(boolean blockUntilStarted)
Set whether to let
execute(java.lang.Runnable) block until the work
has been actually started. |
void |
setBootstrapContext(BootstrapContext bootstrapContext)
Specify the JCA BootstrapContext that contains the
WorkManager to delegate to.
|
void |
setTaskDecorator(org.springframework.core.task.TaskDecorator taskDecorator)
Specify a custom
TaskDecorator to be applied to any Runnable
about to be executed. |
void |
setWorkListener(WorkListener workListener)
Specify a JCA 1.5 WorkListener to apply, if any.
|
void |
setWorkManager(WorkManager workManager)
Specify the JCA WorkManager instance to delegate to.
|
void |
setWorkManagerName(java.lang.String workManagerName)
Set the JNDI name of the JCA WorkManager.
|
long |
startWork(Work work) |
long |
startWork(Work work,
long delay,
ExecutionContext executionContext,
WorkListener workListener) |
<T> java.util.concurrent.Future<T> |
submit(java.util.concurrent.Callable<T> task) |
java.util.concurrent.Future<?> |
submit(java.lang.Runnable task) |
<T> org.springframework.util.concurrent.ListenableFuture<T> |
submitListenable(java.util.concurrent.Callable<T> task) |
org.springframework.util.concurrent.ListenableFuture<?> |
submitListenable(java.lang.Runnable task) |
convertJndiName, isResourceRef, lookup, lookup, setResourceRefpublic WorkManagerTaskExecutor()
public WorkManagerTaskExecutor(WorkManager workManager)
workManager - the JCA WorkManager to delegate topublic void setWorkManager(WorkManager workManager)
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(javax.resource.spi.work.WorkManager),
JndiLocatorSupport.setResourceRef(boolean)public void setBootstrapContext(BootstrapContext bootstrapContext)
setBootstrapContext in interface BootstrapContextAwarebootstrapContext - BootstrapContext object to be used by this objectInitializingBean.afterPropertiesSet(),
ApplicationContextAware.setApplicationContext(org.springframework.context.ApplicationContext)public void setBlockUntilStarted(boolean blockUntilStarted)
execute(java.lang.Runnable) block until the work
has been actually started.
Uses the JCA startWork operation underneath,
instead of the default scheduleWork.
public void setBlockUntilCompleted(boolean blockUntilCompleted)
execute(java.lang.Runnable) block until the work
has been completed.
Uses the JCA doWork operation underneath,
instead of the default scheduleWork.
public void setWorkListener(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 setTaskDecorator(org.springframework.core.task.TaskDecorator taskDecorator)
TaskDecorator to be applied to any Runnable
about to be executed.
Note that such a decorator is not necessarily being applied to the
user-supplied Runnable/Callable but rather to the actual
execution callback (which may be a wrapper around the user-supplied task).
The primary use case is to set some execution context around the task's invocation, or to provide some monitoring/statistics for task execution.
public void afterPropertiesSet()
throws javax.naming.NamingException
afterPropertiesSet in interface org.springframework.beans.factory.InitializingBeanjavax.naming.NamingExceptionprotected WorkManager getDefaultWorkManager()
The default implementation returns a SimpleTaskWorkManager.
Can be overridden in subclasses.
public void execute(java.lang.Runnable task)
execute in interface java.util.concurrent.Executorexecute in interface org.springframework.core.task.TaskExecutorpublic void execute(java.lang.Runnable task,
long startTimeout)
execute in interface org.springframework.core.task.AsyncTaskExecutorpublic java.util.concurrent.Future<?> submit(java.lang.Runnable task)
submit in interface org.springframework.core.task.AsyncTaskExecutorpublic <T> java.util.concurrent.Future<T> submit(java.util.concurrent.Callable<T> task)
submit in interface org.springframework.core.task.AsyncTaskExecutorpublic org.springframework.util.concurrent.ListenableFuture<?> submitListenable(java.lang.Runnable task)
submitListenable in interface org.springframework.core.task.AsyncListenableTaskExecutorpublic <T> org.springframework.util.concurrent.ListenableFuture<T> submitListenable(java.util.concurrent.Callable<T> task)
submitListenable in interface org.springframework.core.task.AsyncListenableTaskExecutorpublic boolean prefersShortLivedTasks()
prefersShortLivedTasks in interface org.springframework.scheduling.SchedulingTaskExecutorpublic void doWork(Work work) throws WorkException
doWork in interface WorkManagerWorkExceptionpublic void doWork(Work work, long delay, ExecutionContext executionContext, WorkListener workListener) throws WorkException
doWork in interface WorkManagerWorkExceptionpublic long startWork(Work work) throws WorkException
startWork in interface WorkManagerWorkExceptionpublic long startWork(Work work, long delay, ExecutionContext executionContext, WorkListener workListener) throws WorkException
startWork in interface WorkManagerWorkExceptionpublic void scheduleWork(Work work) throws WorkException
scheduleWork in interface WorkManagerWorkExceptionpublic void scheduleWork(Work work, long delay, ExecutionContext executionContext, WorkListener workListener) throws WorkException
scheduleWork in interface WorkManagerWorkException