001/*
002 * jPOS Project [http://jpos.org]
003 * Copyright (C) 2000-2026 jPOS Software SRL
004 *
005 * This program is free software: you can redistribute it and/or modify
006 * it under the terms of the GNU Affero General Public License as
007 * published by the Free Software Foundation, either version 3 of the
008 * License, or (at your option) any later version.
009 *
010 * This program is distributed in the hope that it will be useful,
011 * but WITHOUT ANY WARRANTY; without even the implied warranty of
012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
013 * GNU Affero General Public License for more details.
014 *
015 * You should have received a copy of the GNU Affero General Public License
016 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
017 */
018
019package org.jpos.q2;
020
021
022/**
023 * An interface describing a Q2 service MBean.
024 *
025 * @author <a href="mailto:apr@cs.com.uy">Alejandro P. Revilla</a>
026 * @author <a href="mailto:taherkordy@dpi2.dpi.net.ir">Alireza Taherkordi</a>
027 * @version $Revision$ $Date$
028 * @see QPersist
029 */
030public interface QBean {
031
032    // State
033    /** QBean is stopped. */
034    int STOPPED    = 0;
035    /** QBean is in the process of stopping. */
036    int STOPPING   = 1;
037    /** QBean is in the process of starting. */
038    int STARTING   = 2;
039    /** QBean is running. */
040    int STARTED    = 3;
041    /** QBean has failed. */
042    int FAILED     = 4;
043    /** QBean has been destroyed. */
044    int DESTROYED  = 5;
045
046    /** Human-readable names for each QBean state, indexed by state constant. */
047    String stateString[] = {
048        "Stopped", "Stopping", "Starting", "Started", "Failed", "Destroyed"
049    };
050
051    /**
052     * init the service
053     * @throws Exception on error
054     */
055    void init () throws Exception;
056
057    /**
058     * start the service
059     * @throws Exception on error
060     */
061    void start () throws Exception;
062
063    /**
064     * stop the service
065     * @throws Exception on error
066     */
067    void stop () throws Exception;
068
069    /**
070     * destroy the service
071     * @throws Exception on error
072     */
073    void destroy () throws Exception;
074
075    /**
076     * Returns the current state of this QBean.
077     * @return state (STARTING, STARTED, FAILED, DESTROYED ...)
078     */
079    int getState ();
080
081    /**
082     * Returns the current state as a human-readable string.
083     * @return state (STARTING, STARTED, FAILED, DESTROYED ...)
084     */
085    default String getStateAsString () {
086        return getState() >= 0 ? stateString[getState()] : "Unknown";
087    }
088}