java.lang.Object
   ↳ org.springframework.jndi.JndiAccessor
     ↳ org.springframework.jndi.JndiLocatorSupport
       ↳ org.springframework.jca.work.WorkManagerTaskExecutor
Known Direct Subclasses

Class Overview

TaskExecutor implementation that delegates to a JCA 1.5 WorkManager, implementing the javax.resource.spi.work.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.

See Also

Summary

[Expand]
Inherited Constants
From class org.springframework.jndi.JndiLocatorSupport
From interface org.springframework.core.task.AsyncTaskExecutor
[Expand]
Inherited Fields
From class org.springframework.jndi.JndiAccessor
Public Constructors
WorkManagerTaskExecutor()
Create a new WorkManagerTaskExecutor, expecting bean-style configuration.
WorkManagerTaskExecutor(WorkManager workManager)
Create a new WorkManagerTaskExecutor for the given WorkManager.
Public Methods
void afterPropertiesSet()
Invoked by a BeanFactory after it has set all bean properties supplied (and satisfied BeanFactoryAware and ApplicationContextAware).
void doWork(Work work)
void doWork(Work work, long delay, ExecutionContext executionContext, WorkListener workListener)
void execute(Runnable task)
Execute the given task.
void execute(Runnable task, long startTimeout)
Execute the given task.
boolean prefersShortLivedTasks()
This task executor prefers short-lived work units.
void scheduleWork(Work work, long delay, ExecutionContext executionContext, WorkListener workListener)
void scheduleWork(Work work)
void setBlockUntilCompleted(boolean blockUntilCompleted)
Set whether to let execute(Runnable) block until the work has been completed.
void setBlockUntilStarted(boolean blockUntilStarted)
Set whether to let execute(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 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(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> Future<T> submit(Callable<T> task)
Submit a Callable task for execution, receiving a Future representing that task.
Future<?> submit(Runnable task)
Submit a Runnable task for execution, receiving a Future representing that task.
Protected Methods
WorkManager getDefaultWorkManager()
Obtain a default WorkManager to delegate to.
[Expand]
Inherited Methods
From class org.springframework.jndi.JndiLocatorSupport
From class org.springframework.jndi.JndiAccessor
From class java.lang.Object
From interface java.util.concurrent.Executor
From interface org.springframework.beans.factory.InitializingBean
From interface org.springframework.core.task.AsyncTaskExecutor
From interface org.springframework.core.task.TaskExecutor
From interface org.springframework.jca.context.BootstrapContextAware
From interface org.springframework.scheduling.SchedulingTaskExecutor

Public Constructors

public WorkManagerTaskExecutor ()

Create a new WorkManagerTaskExecutor, expecting bean-style configuration.

public WorkManagerTaskExecutor (WorkManager workManager)

Create a new WorkManagerTaskExecutor for the given WorkManager.

Parameters
workManager the JCA WorkManager to delegate to

Public Methods

public void afterPropertiesSet ()

Invoked by a BeanFactory after it has set all bean properties supplied (and satisfied BeanFactoryAware and ApplicationContextAware).

This method allows the bean instance to perform initialization only possible when all bean properties have been set and to throw an exception in the event of misconfiguration.

public void doWork (Work work)

Throws
WorkException

public void doWork (Work work, long delay, ExecutionContext executionContext, WorkListener workListener)

Throws
WorkException

public void execute (Runnable task)

Execute the given task.

The call might return immediately if the implementation uses an asynchronous execution strategy, or might block in the case of synchronous execution.

Parameters
task the Runnable to execute (never null)

public void execute (Runnable task, long startTimeout)

Execute the given task.

Parameters
task the Runnable to execute (never null)
startTimeout the time duration (milliseconds) within which the task is supposed to start. This is intended as a hint to the executor, allowing for preferred handling of immediate tasks. Typical values are TIMEOUT_IMMEDIATE or TIMEOUT_INDEFINITE (the default as used by execute(Runnable)).

public boolean prefersShortLivedTasks ()

This task executor prefers short-lived work units.

Returns
  • true if this TaskExecutor prefers short-lived tasks

public void scheduleWork (Work work, long delay, ExecutionContext executionContext, WorkListener workListener)

Throws
WorkException

public void scheduleWork (Work work)

Throws
WorkException

public void setBlockUntilCompleted (boolean blockUntilCompleted)

Set whether to let execute(Runnable) block until the work has been completed.

Uses the JCA doWork operation underneath, instead of the default scheduleWork.

See Also
  • javax.resource.spi.work.WorkManager#doWork
  • javax.resource.spi.work.WorkManager#scheduleWork

public void setBlockUntilStarted (boolean blockUntilStarted)

Set whether to let execute(Runnable) block until the work has been actually started.

Uses the JCA startWork operation underneath, instead of the default scheduleWork.

See Also
  • javax.resource.spi.work.WorkManager#startWork
  • javax.resource.spi.work.WorkManager#scheduleWork

public void setBootstrapContext (BootstrapContext bootstrapContext)

Specify the JCA BootstrapContext that contains the WorkManager to delegate to.

Parameters
bootstrapContext BootstrapContext object to be used by this object

public void setWorkListener (WorkListener workListener)

Specify a JCA 1.5 WorkListener to apply, if any.

This shared WorkListener instance will be passed on to the WorkManager by all execute(Runnable) calls on this TaskExecutor.

public void setWorkManager (WorkManager workManager)

Specify the JCA WorkManager instance to delegate to.

public void setWorkManagerName (String workManagerName)

Set the JNDI name of the JCA WorkManager.

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".

public long startWork (Work work)

Throws
WorkException

public long startWork (Work work, long delay, ExecutionContext executionContext, WorkListener workListener)

Throws
WorkException

public Future<T> submit (Callable<T> task)

Submit a Callable task for execution, receiving a Future representing that task. The Future will return the Callable's result upon completion.

Parameters
task the Callable to execute (never null)
Returns
  • a Future representing pending completion of the task

public Future<?> submit (Runnable task)

Submit a Runnable task for execution, receiving a Future representing that task. The Future will return a null result upon completion.

Parameters
task the Runnable to execute (never null)
Returns
  • a Future representing pending completion of the task

Protected Methods

protected WorkManager getDefaultWorkManager ()

Obtain a default WorkManager to delegate to. Called if no explicit WorkManager or WorkManager JNDI name has been specified.

The default implementation returns a SimpleTaskWorkManager. Can be overridden in subclasses.