package com.dbxml.db.server;

/*
 * dbXML - Native XML Database
 * Copyright (C) 1999-2004  The dbXML Group, L.L.C.
 *
 * This program 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.
 *
 * This program 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 this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 *
 * $Id: Service.java,v 1.2 2004/02/12 00:17:57 bradford Exp $
 */

/**
 * Services are implemented to provide a daemon process for various
 * purposes.  The most general implementation of a Service is to
 * provide a Socket based service, but Services can be written
 * to function in just about any capacity.
 *
 * @see com.dbxml.db.server.ServiceManager
 */

public interface Service {
   /* Active state */

   static final int STATE_STOPPED = 0;
   static final int STATE_STARTED = 1;
   static final int STATE_SUSPENDED = 2;

   /* Result values */

   static final int RESULT_OK = 0;
   static final int RESULT_BUSY = 1;
   static final int RESULT_FAILED = 2;
   static final int RESULT_INVALID = 3;

   /* Methods */

   /**
    * getName returns the name of this Service.
    *
    * @return The Service name
    */
   String getName();

   /**
    * setServerInstance sets the Server instance for this Service.
    *
    * @param server The Server instance
    */
   void setServerInstance(Server server);

   /**
    * status returns the current operational status of this Service.  This
    * value can either be STATE_STOPPED, STATE_STARTED, or STATE_SUSPENDED.
    *
    * @return The Service's status
    */
   int status();

   /**
    * statusMessage returns a textual message about the Service's
    * operational state.
    *
    * @return The Service's status as a text message
    */
   String statusMessage();

   /**
    * initialize will initialize the Service based on its current
    * configuration.  RESULT_INVALID will be returned if the Service's
    * configuration is invalid.
    *
    * @return The initialization status
    */
   int initialize();

   /**
    * start will attempt to start the Service.  Depending on whether the
    * Service was happy about being started or not, a value of RESULT_OK
    * should be returned.
    *
    * @return The result of the start attempt
    */
   int start();

   /**
    * stop will attempt to stop the Service.  Depending on whether the
    * Service was happy about being stopped or not, a value of RESULT_OK
    * should be returned.
    *
    * @return The result of the stop attempt
    */
   int stop();

   /**
    * suspend suspends execution of the Service.  It basically puts it into
    * a paused state until it is resumed or started again.  Depending on
    * whether the Service was happy about being suspended or not, a value of
    * RESULT_OK should be returned.
    *
    * @return The result of the suspend attempt
    */
   int suspend();

   /**
    * resume resumes exection of a suspended Service.  It will also start a
    * stopped Service.  Depending on whether the Service was happy about
    * being resumed or not, a value of RESULT_OK should be returned.
    *
    * @return The result of the resume attempt
    */
   int resume();

   /**
    * uninitialize will uninitialize the Service based on its current
    * configuration and will clean up any existing resources for that
    * configuration.  RESULT_INVALID will be returned if the Service's
    * configuration is invalid.
    *
    * @return The uninitialization status
    */
   int uninitialize();

   /**
    * dispose prepares the Service for garbage collection.  Any
    * references that the object might be maintaining should be
    * cleared when this method is called.
    */
   void dispose();
}
