001/* 002 * Copyright 2006-2007 the original author or authors. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * https://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 017package org.springframework.batch.repeat; 018 019import org.springframework.core.AttributeAccessor; 020 021/** 022 * Base interface for context which controls the state and completion / 023 * termination of a batch step. A new context is created for each call to the 024 * {@link RepeatOperations}. Within a batch callback code can communicate via 025 * the {@link AttributeAccessor} interface. 026 * 027 * @author Dave Syer 028 * 029 * @see RepeatOperations#iterate(RepeatCallback) 030 * 031 */ 032public interface RepeatContext extends AttributeAccessor { 033 034 /** 035 * If batches are nested, then the inner batch will be created with the 036 * outer one as a parent. This is an accessor for the parent if it exists. 037 * 038 * @return the parent context or null if there is none 039 */ 040 RepeatContext getParent(); 041 042 /** 043 * Public access to a counter for the number of operations attempted. 044 * 045 * @return the number of batch operations started. 046 */ 047 int getStartedCount(); 048 049 /** 050 * Signal to the framework that the current batch should complete normally, 051 * independent of the current {@link CompletionPolicy}. 052 */ 053 void setCompleteOnly(); 054 055 /** 056 * Public accessor for the complete flag. 057 * 058 * @return indicator if the repeat is complete 059 */ 060 boolean isCompleteOnly(); 061 062 /** 063 * Signal to the framework that the current batch should complete 064 * abnormally, independent of the current {@link CompletionPolicy}. 065 */ 066 void setTerminateOnly(); 067 068 /** 069 * Public accessor for the termination flag. If this flag is set then the 070 * complete flag will also be. 071 * 072 * @return indicates if the repeat should terminate 073 */ 074 boolean isTerminateOnly(); 075 076 /** 077 * Register a callback to be executed on close, associated with the 078 * attribute having the given name. The {@link Runnable} callback should not 079 * throw any exceptions. 080 * 081 * @param name the name of the attribute to associated this callback with. 082 * If this attribute is removed the callback should never be called. 083 * @param callback a {@link Runnable} to execute when the context is closed. 084 */ 085 void registerDestructionCallback(String name, Runnable callback); 086 087 /** 088 * Allow resources to be cleared, especially in destruction callbacks. 089 * Implementations should ensure that any registered destruction callbacks 090 * are executed here, as long as the corresponding attribute is still 091 * available. 092 */ 093 void close(); 094 095}