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,java.util.concurrent.Future<O>>,org.springframework.beans.factory.InitializingBean
public class AsyncItemProcessor<I,O> extends java.lang.Object implements ItemProcessor<I,java.util.concurrent.Future<O>>, org.springframework.beans.factory.InitializingBean
AnItemProcessorthat delegates to a nested processor and in the background. To allow for background processing the return value from the processor is aFuturewhich needs to be unpacked before the item can be used by a client. Because theFutureis typically unwrapped in theItemWriter, 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 likeStepExecution.filterCountwill not reflect the number of filtered items andItemProcessListener.onProcessError(Object, Exception)will not be called.- Author:
- Dave Syer
- See Also:
AsyncItemWriter
Constructor Summary
Constructors Constructor Description AsyncItemProcessor()
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidafterPropertiesSet()Check mandatory properties (thesetDelegate(ItemProcessor)).java.util.concurrent.Future<O>process(I item)Transform the input by delegating to the provided item processor.voidsetDelegate(ItemProcessor<I,O> delegate)TheItemProcessorto use to delegate processing to in a background thread.voidsetTaskExecutor(org.springframework.core.task.TaskExecutor taskExecutor)TheTaskExecutorto use to allow the item processing to proceed in the background.
Method Detail
afterPropertiesSet
public void afterPropertiesSet() throws java.lang.ExceptionCheck mandatory properties (thesetDelegate(ItemProcessor)).- Specified by:
afterPropertiesSetin interfaceorg.springframework.beans.factory.InitializingBean- Throws:
java.lang.Exception- See Also:
InitializingBean.afterPropertiesSet()
setDelegate
public void setDelegate(ItemProcessor<I,O> delegate)
TheItemProcessorto use to delegate processing to in a background thread.- Parameters:
delegate- theItemProcessorto use as a delegate
setTaskExecutor
public void setTaskExecutor(org.springframework.core.task.TaskExecutor taskExecutor)
TheTaskExecutorto use to allow the item processing to proceed in the background. Defaults to aSyncTaskExecutorso no threads are created unless this is overridden.- Parameters:
taskExecutor- aTaskExecutor
process
public java.util.concurrent.Future<O> process(I item) throws java.lang.Exception
Transform the input by delegating to the provided item processor. The return value is wrapped in aFutureso that clients can unpack it later.- Specified by:
processin interfaceItemProcessor<I,O>- Parameters:
item- to be processed- Returns:
- potentially modified or new item for continued processing,
nullif processing of the provided item should not continue. - Throws:
java.lang.Exception- thrown if exception occurs during processing.- See Also:
ItemProcessor.process(Object)