001/*
002 * Copyright 2006-2018 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 */
016package org.springframework.batch.core.step.tasklet;
017
018import org.springframework.batch.core.StepContribution;
019import org.springframework.batch.core.scope.context.ChunkContext;
020import org.springframework.batch.repeat.RepeatStatus;
021import org.springframework.lang.Nullable;
022
023/**
024 * Strategy for processing in a step.
025 * 
026 * @author Dave Syer
027 * @author Mahmoud Ben Hassine
028 * 
029 */
030public interface Tasklet {
031
032        /**
033         * Given the current context in the form of a step contribution, do whatever
034         * is necessary to process this unit inside a transaction. Implementations
035         * return {@link RepeatStatus#FINISHED} if finished. If not they return
036         * {@link RepeatStatus#CONTINUABLE}. On failure throws an exception.
037         * 
038         * @param contribution mutable state to be passed back to update the current
039         * step execution
040         * @param chunkContext attributes shared between invocations but not between
041         * restarts
042         * @return an {@link RepeatStatus} indicating whether processing is
043         * continuable. Returning {@code null} is interpreted as {@link RepeatStatus#FINISHED}
044         *
045         * @throws Exception thrown if error occurs during execution.
046         */
047        @Nullable
048        RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception;
049
050}