Class AsyncItemProcessor<I,O>
java.lang.Object
org.springframework.batch.integration.async.AsyncItemProcessor<I,O>
- Type Parameters:
I
- the input object typeO
- the output object type (will be wrapped in a Future)
- All Implemented Interfaces:
ItemProcessor<I,
,Future<O>> org.springframework.beans.factory.InitializingBean
public class AsyncItemProcessor<I,O>
extends Object
implements ItemProcessor<I,Future<O>>, org.springframework.beans.factory.InitializingBean
An
ItemProcessor
that delegates to a nested processor and in the background. To
allow for background processing the return value from the processor is a Future
which needs to be unpacked before the item can be used by a client.
Because the Future
is typically unwrapped in the ItemWriter
, there are
lifecycle and stats limitations (since the framework doesn't know what the result of
the processor is). While not an exhaustive list, things like
StepExecution.filterCount
will not reflect the number of filtered items and
ItemProcessListener.onProcessError(Object, Exception)
will not be called.- Author:
- Dave Syer
- See Also:
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
Check mandatory properties (thesetDelegate(ItemProcessor)
).Transform the input by delegating to the provided item processor.void
setDelegate
(ItemProcessor<I, O> delegate) TheItemProcessor
to use to delegate processing to in a background thread.void
setTaskExecutor
(org.springframework.core.task.TaskExecutor taskExecutor) TheTaskExecutor
to use to allow the item processing to proceed in the background.
-
Constructor Details
-
AsyncItemProcessor
public AsyncItemProcessor()
-
-
Method Details
-
afterPropertiesSet
Check mandatory properties (thesetDelegate(ItemProcessor)
).- Specified by:
afterPropertiesSet
in interfaceorg.springframework.beans.factory.InitializingBean
- Throws:
Exception
- See Also:
-
InitializingBean.afterPropertiesSet()
-
setDelegate
TheItemProcessor
to use to delegate processing to in a background thread.- Parameters:
delegate
- theItemProcessor
to use as a delegate
-
setTaskExecutor
public void setTaskExecutor(org.springframework.core.task.TaskExecutor taskExecutor) TheTaskExecutor
to use to allow the item processing to proceed in the background. Defaults to aSyncTaskExecutor
so no threads are created unless this is overridden.- Parameters:
taskExecutor
- aTaskExecutor
-
process
Transform the input by delegating to the provided item processor. The return value is wrapped in aFuture
so that clients can unpack it later.- Specified by:
process
in interfaceItemProcessor<I,
O> - Parameters:
item
- to be processed, nevernull
.- Returns:
- potentially modified or new item for continued processing,
null
if processing of the provided item should not continue. - Throws:
Exception
- thrown if exception occurs during processing.- See Also:
-