001/*
002 * Copyright 2012 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.configuration;
017
018import org.springframework.batch.core.Step;
019import org.springframework.batch.core.launch.NoSuchJobException;
020import org.springframework.batch.core.step.NoSuchStepException;
021
022import java.util.Collection;
023
024/**
025 * Registry keeping track of all the {@link Step} defined in a
026 * {@link org.springframework.batch.core.Job}.
027 *
028 * @author Sebastien Gerard
029 * @author Stephane Nicoll
030 */
031public interface StepRegistry {
032
033    /**
034     * Registers all the step of the given job. If the job is already registered,
035     * the method {@link #unregisterStepsFromJob(String)} is called before registering
036     * the given steps.
037     *
038     * @param jobName the give job name
039     * @param steps   the job steps
040     * @throws DuplicateJobException if a job with the same job name has already been registered.
041     */
042    void register(String jobName, Collection<Step> steps) throws DuplicateJobException;
043
044    /**
045     * Unregisters all the steps of the given job. If the job is not registered,
046     * nothing happens.
047     *
048     * @param jobName the given job name
049     */
050    void unregisterStepsFromJob(String jobName);
051
052    /**
053     * Returns the {@link Step} of the specified job based on its name.
054     *
055     * @param jobName  the name of the job
056     * @param stepName the name of the step to retrieve
057     * @return the step with the given name belonging to the mentioned job
058     * @throws NoSuchJobException  no such job with that name exists
059     * @throws NoSuchStepException no such step with that name for that job exists
060     */
061    Step getStep(String jobName, String stepName) throws NoSuchJobException, NoSuchStepException;
062
063}