net.freeutils.util.LifeCycle Maven / Gradle / Ivy
Show all versions of jelementary Show documentation
/*
* Copyright © 2003-2024 Amichai Rothman
*
* This file is part of JElementary - the Java Elementary Utilities package.
*
* JElementary is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* JElementary is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with JElementary. If not, see .
*
* For additional info see https://www.freeutils.net/source/jelementary/
*/
package net.freeutils.util;
/**
* An interface for controlling the life cycle of components,
* which can be started and stopped.
*
* By default, the contract allows for the component to be started
* and stopped multiple times, but some components may only be
* started once, in which case they should document it explicitly.
*/
public interface LifeCycle {
/**
* Starts the component.
*
* @throws Exception if an error occurs
*/
void start() throws Exception;
/**
* Stops the component.
*
* The implementation should ideally support being called
* even when the {@link #start} method has not been called
* or not completed successfully (i.e. an exception was thrown),
* as well as being re-entrant (called multiple times).
* This ensures that the component is always properly stopped,
* its resources released, etc.
*
* @throws Exception if an error occurs
*/
void stop() throws Exception;
}