/** * @return the current step execution if there is one */ private StepExecution getStepExecution() { StepContext context = StepSynchronizationManager.getContext(); if (context==null) { return null; } StepExecution stepExecution = context.getStepExecution(); return stepExecution; }
public ChunkTransactionCallback(ChunkContext chunkContext, Semaphore semaphore) { this.chunkContext = chunkContext; this.stepExecution = chunkContext.getStepContext().getStepExecution(); this.semaphore = semaphore; }
@Override protected void doExecutionRegistration(StepExecution stepExecution) { StepSynchronizationManager.register(stepExecution, propertyContext); } }
@Override public StepContext call() throws Exception { try { StepSynchronizationManager.register(stepExecution); StepContext context = StepSynchronizationManager.getContext(); context.setAttribute("foo", "bar"); return context; } finally { StepSynchronizationManager.close(); } } });
@Override public JobContext call() throws Exception { try { JobSynchronizationManager.register(jobExecution); JobContext context = JobSynchronizationManager.getContext(); context.setAttribute("foo", "bar"); return context; } finally { JobSynchronizationManager.close(); } } });
@Override public RepeatStatus doInChunkContext(RepeatContext context, ChunkContext chunkContext) throws Exception { if (addedAttribute) { removedAttribute = chunkContext.hasAttribute("foo"); chunkContext.removeAttribute("foo"); } else { addedAttribute = true; chunkContext.setAttribute("foo", "bar"); } return RepeatStatus.FINISHED; } };
@Override protected void close(StepContext context) { context.close(); } };
@Override protected StepContext createNewContext(StepExecution execution, BatchPropertyContext propertyContext) { StepContext context; if(propertyContext != null) { context = new StepContext(execution, propertyContext); } else { context = new StepContext(execution); } return context; }
/** * Releases the most recent {@link StepExecution} */ protected void doExecutionRelease() { StepSynchronizationManager.release(); }
@Override protected void close(JobContext context) { context.close(); } };
@Override protected JobContext createNewContext(JobExecution execution, BatchPropertyContext args) { return new JobContext(execution); }
/** * Register a context with the current thread - always put a matching * {@link #close()} call in a finally block to ensure that the correct * context is available in the enclosing block. * * @param JobExecution the step context to register * @return a new {@link JobContext} or the current one if it has the same * {@link JobExecution} */ public static JobContext register(JobExecution JobExecution) { return manager.register(JobExecution); }
/** * A convenient "deep" close operation. Call this instead of * {@link #close()} if the step execution for the current context is ending. * Delegates to {@link JobContext#close()} and then ensures that * {@link #close()} is also called in a finally block. */ public static void release() { manager.release(); } }
/** * Method for unregistering the current context - should always and only be * used by in conjunction with a matching {@link #register(StepExecution)} * to ensure that {@link #getContext()} always returns the correct value. * Does not call {@link StepContext#close()} - that is left up to the caller * because he has a reference to the context (having registered it) and only * he has knowledge of when the step actually ended. */ public static void close() { manager.close(); }
@Override public Message<?> preSend(Message<?> message, MessageChannel channel) { StepContext context = StepSynchronizationManager.getContext(); if (context == null) { return message; } return MessageBuilder.fromMessage(message).setHeader(STEP_EXECUTION, context.getStepExecution()).build(); }
/** * Registers the {@link StepExecution} for property resolution via {@link StepScope} * * @param stepExecution StepExecution to use when hydrating the StepScoped beans */ protected void doExecutionRegistration(StepExecution stepExecution) { StepSynchronizationManager.register(stepExecution); }
/** * Register a context with the current thread - always put a matching * {@link #close()} call in a finally block to ensure that the correct * context is available in the enclosing block. * * @param stepExecution the step context to register * @return a new {@link StepContext} or the current one if it has the same * {@link StepExecution} */ public static StepContext register(StepExecution stepExecution) { return manager.register(stepExecution); }
/** * A convenient "deep" close operation. Call this instead of * {@link #close()} if the step execution for the current context is ending. * Delegates to {@link StepContext#close()} and then ensures that * {@link #close()} is also called in a finally block. */ public static void release() { manager.release(); } }
/** * Method for unregistering the current context - should always and only be * used by in conjunction with a matching {@link #register(JobExecution)} * to ensure that {@link #getContext()} always returns the correct value. * Does not call {@link JobContext#close()} - that is left up to the caller * because he has a reference to the context (having registered it) and only * he has knowledge of when the step actually ended. */ public static void close() { manager.close(); }
public String process(String item) throws Exception { StepContext context = StepSynchronizationManager.getContext(); assertTrue(context != null && context.getStepExecution() != null); return item + item; }; };