/** * Execute the batch callback until the completion policy decides that we * are finished. Wait for the whole batch to finish before returning even if * the task executor is asynchronous. * * @see org.springframework.batch.repeat.RepeatOperations#iterate(org.springframework.batch.repeat.RepeatCallback) */ @Override public RepeatStatus iterate(RepeatCallback callback) { RepeatContext outer = RepeatSynchronizationManager.getContext(); RepeatStatus result = RepeatStatus.CONTINUABLE; try { // This works with an asynchronous TaskExecutor: the // interceptors have to wait for the child processes. result = executeInternal(callback); } finally { RepeatSynchronizationManager.clear(); if (outer != null) { RepeatSynchronizationManager.register(outer); } } return result; }
public void testSetSessionCompleteOnly() { assertNull(RepeatSynchronizationManager.getContext()); RepeatSynchronizationManager.register(context); assertFalse(RepeatSynchronizationManager.getContext().isCompleteOnly()); RepeatSynchronizationManager.setCompleteOnly(); assertTrue(RepeatSynchronizationManager.getContext().isCompleteOnly()); }
/** * Delegate to the {@link CompletionPolicy}. * * @return a {@link RepeatContext} object that can be used by the implementation to store * internal state for a batch step. * * @see org.springframework.batch.repeat.CompletionPolicy#start(RepeatContext) */ protected RepeatContext start() { RepeatContext parent = RepeatSynchronizationManager.getContext(); RepeatContext context = completionPolicy.start(parent); RepeatSynchronizationManager.register(context); logger.debug("Starting repeat context."); return context; }
/** * Clear the current context at the end of a batch - should only be used by * {@link RepeatOperations} implementations. * * @return the old value if there was one. */ public static RepeatContext clear() { RepeatContext context = getContext(); RepeatSynchronizationManager.contextHolder.set(null); return context; }
public void testSetSessionCompleteOnlyWithParent() { assertNull(RepeatSynchronizationManager.getContext()); RepeatContext child = new RepeatContextSupport(context); RepeatSynchronizationManager.register(child); assertFalse(child.isCompleteOnly()); RepeatSynchronizationManager.setAncestorsCompleteOnly(); assertTrue(child.isCompleteOnly()); assertTrue(context.isCompleteOnly()); }
@Override protected void setUp() throws Exception { RepeatSynchronizationManager.clear(); }
@Override protected void setUp() throws Exception { RepeatSynchronizationManager.register(context); }
/** * Method for registering a context - should only be used by * {@link RepeatOperations} implementations to ensure that * {@link #getContext()} always returns the correct value. * * @param context a new context at the start of a batch. * @return the old value if there was one. */ public static RepeatContext register(RepeatContext context) { RepeatContext oldSession = getContext(); RepeatSynchronizationManager.contextHolder.set(context); return oldSession; }
public void testGetContext() { RepeatSynchronizationManager.register(context); assertEquals(context, RepeatSynchronizationManager.getContext()); }
@Override protected void tearDown() throws Exception { RepeatSynchronizationManager.clear(); }
RepeatSynchronizationManager.register(new RepeatContextSupport(null));
public void testClear() { RepeatSynchronizationManager.register(context); assertEquals(context, RepeatSynchronizationManager.getContext()); RepeatSynchronizationManager.clear(); assertEquals(null, RepeatSynchronizationManager.getContext()); }
/** * Convenience method to set the current repeat operation to complete if it * exists. */ public static void setCompleteOnly() { RepeatContext context = getContext(); if (context != null) { context.setCompleteOnly(); } }
/** * Delegate to the {@link CompletionPolicy}. * * @return a {@link RepeatContext} object that can be used by the implementation to store * internal state for a batch step. * * @see org.springframework.batch.repeat.CompletionPolicy#start(RepeatContext) */ protected RepeatContext start() { RepeatContext parent = RepeatSynchronizationManager.getContext(); RepeatContext context = completionPolicy.start(parent); RepeatSynchronizationManager.register(context); logger.debug("Starting repeat context."); return context; }
@Override protected void tearDown() throws Exception { RepeatSynchronizationManager.clear(); }
/** * Execute the batch callback, and store the result, or any exception * that is thrown for retrieval later by caller. * * @see java.lang.Runnable#run() */ @Override public void run() { boolean clearContext = false; try { if (RepeatSynchronizationManager.getContext() == null) { clearContext = true; RepeatSynchronizationManager.register(context); } if (logger.isDebugEnabled()) { logger.debug("Repeat operation about to start at count=" + context.getStartedCount()); } result = callback.doInIteration(context); } catch (Throwable e) { error = e; } finally { if (clearContext) { RepeatSynchronizationManager.clear(); } queue.put(this); } }
/** * Set current session and all ancestors (via parent) to complete., */ public static void setAncestorsCompleteOnly() { RepeatContext context = getContext(); while (context != null) { context.setCompleteOnly(); context = context.getParent(); } }
@After public void tearDown() throws Exception { RepeatSynchronizationManager.clear(); }
/** * Execute the batch callback until the completion policy decides that we * are finished. Wait for the whole batch to finish before returning even if * the task executor is asynchronous. * * @see org.springframework.batch.repeat.RepeatOperations#iterate(org.springframework.batch.repeat.RepeatCallback) */ @Override public RepeatStatus iterate(RepeatCallback callback) { RepeatContext outer = RepeatSynchronizationManager.getContext(); RepeatStatus result = RepeatStatus.CONTINUABLE; try { // This works with an asynchronous TaskExecutor: the // interceptors have to wait for the child processes. result = executeInternal(callback); } finally { RepeatSynchronizationManager.clear(); if (outer != null) { RepeatSynchronizationManager.register(outer); } } return result; }
/** * Get the parent context (the retry is in an inner "chunk" loop and we want * the exception to be handled at the outer "step" level). * @return the {@link RepeatContext} that should hold the exhausted flag. */ private RepeatContext getRepeatContext() { RepeatContext context = RepeatSynchronizationManager.getContext(); if (context.getParent() != null) { return context.getParent(); } return context; }