/** * A convenient "deep" close operation. Call this instead of {@link #close()} if the execution for the current * context is ending. * Delegates to {@link #close(Object)} and then ensures that {@link #close()} is also called in a finally block. */ public void release() { C context = getContext(); try { if (context != null) { close(context); } } finally { close(); } }
/** * 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 execution the execution to register * @return a new context or the current one if it has the same * execution */ @Nullable public C register(@Nullable E execution) { if (execution == null) { return null; } getCurrent().push(execution); C context; synchronized (contexts) { context = contexts.get(execution); if (context == null) { context = createNewContext(execution, null); contexts.put(execution, context); } } increment(); return context; }
/** * Method for unregistering the current context - should always and only be * used by in conjunction with a matching {@link #register(Object)} to ensure that {@link #getContext()} always returns * the correct value. * Does not call close on the context - 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 execution actually ended. */ public void close() { C oldSession = getContext(); if (oldSession == null) { return; } decrement(); }
/** * 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); }
/** * Getter for the current context if there is one, otherwise returns {@code null}. * * @return the current context or {@code null} if there is none (if one * has not been registered for this thread). */ @Nullable public C getContext() { if (getCurrent().isEmpty()) { return null; } synchronized (contexts) { return contexts.get(getCurrent().peek()); } }
/** * 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(); }
/** * Getter for the current context if there is one, otherwise returns {@code null}. * * @return the current {@link StepContext} or {@code null} if there is none (if one * has not been registered for this thread). */ @Nullable public static StepContext getContext() { return manager.getContext(); }
/** * 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); }
private void decrement() { E current = getCurrent().pop(); if (current != null) { int remaining = counts.get(current).decrementAndGet(); if (remaining <= 0) { synchronized (contexts) { contexts.remove(current); counts.remove(current); } } } }
/** * 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(); }
/** * Getter for the current context if there is one, otherwise returns {@code null}. * * @return the current {@link JobContext} or {@code null} if there is none (if one * has not been registered for this thread). */ @Nullable public static JobContext getContext() { return manager.getContext(); }
/** * 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 execution the execution to register * @param propertyContext instance of {@link BatchPropertyContext} to be registered with this thread. * @return a new context or the current one if it has the same * execution */ @Nullable public C register(@Nullable E execution, @Nullable BatchPropertyContext propertyContext) { if (execution == null) { return null; } getCurrent().push(execution); C context; synchronized (contexts) { context = contexts.get(execution); if (context == null) { context = createNewContext(execution, propertyContext); contexts.put(execution, context); } } increment(); return context; }
/** * Method for unregistering the current context - should always and only be * used by in conjunction with a matching {@link #register(Object)} to ensure that {@link #getContext()} always returns * the correct value. * Does not call close on the context - 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 execution actually ended. */ public void close() { C oldSession = getContext(); if (oldSession == null) { return; } decrement(); }
/** * A convenient "deep" close operation. Call this instead of {@link #close()} if the execution for the current * context is ending. * Delegates to {@link #close(Object)} and then ensures that {@link #close()} is also called in a finally block. */ public void release() { C context = getContext(); try { if (context != null) { close(context); } } finally { close(); } }
/** * 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 * @param propertyContext an instance of {@link BatchPropertyContext} to be * used by the StepSynchronizationManager. * @return a new {@link StepContext} or the current one if it has the same * {@link StepExecution} */ public static StepContext register(StepExecution stepExecution, BatchPropertyContext propertyContext) { return manager.register(stepExecution, propertyContext); }
public void increment() { E current = getCurrent().peek(); if (current != null) { AtomicInteger count; synchronized (counts) { count = counts.get(current); if (count == null) { count = new AtomicInteger(); counts.put(current, count); } } count.incrementAndGet(); } }
/** * 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(); }