MetaServer.java :  » Web-Server » jo » com » tagtraum » metaserver » Java Open Source

Java Open Source » Web Server » jo 
jo » com » tagtraum » metaserver » MetaServer.java
/*
License $Id: MetaServer.java,v 1.5 2005/03/15 20:09:44 hendriks73 Exp $

Copyright (c) 2001-2005 tagtraum industries.

LGPL
====

jo! is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.

jo! 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
Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

For LGPL see <http://www.fsf.org/copyleft/lesser.txt>


Sun license
===========

This release contains software by Sun Microsystems. Therefore
the following conditions have to be met, too. They apply to the
files

 - lib/mail.jar
 - lib/activation.jar
 - lib/jsse.jar
 - lib/jcert.jar
 - lib/jaxp.jar
 - lib/crimson.jar
 - lib/servlet.jar
 - lib/jnet.jar
 - lib/jaas.jar
 - lib/jaasmod.jar

contained in this release.

a. Licensee may not modify the Java Platform
   Interface (JPI, identified as classes contained within the javax
   package or any subpackages of the javax package), by creating additional
   classes within the JPI or otherwise causing the addition to or modification
   of the classes in the JPI.  In the event that Licensee creates any
   Java-related API and distribute such API to others for applet or
   application development, you must promptly publish broadly, an accurate
   specification for such API for free use by all developers of Java-based
   software.

b. Software is confidential copyrighted information of Sun and
   title to all copies is retained by Sun and/or its licensors.  Licensee
   shall not modify, decompile, disassemble, decrypt, extract, or otherwise
   reverse engineer Software.  Software may not be leased, assigned, or
   sublicensed, in whole or in part.  Software is not designed or intended
   for use in on-line control of aircraft, air traffic, aircraft navigation
   or aircraft communications; or in the design, construction, operation or
   maintenance of any nuclear facility.  Licensee warrants that it will not
   use or redistribute the Software for such purposes.

c. Software is provided "AS IS," without a warranty
   of any kind. ALL EXPRESS OR IMPLIED REPRESENTATIONS AND WARRANTIES,
   INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
   PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED.

d. This License is effective until terminated.  Licensee may
   terminate this License at any time by destroying all copies of Software.
   This License will terminate immediately without notice from Sun if Licensee
   fails to comply with any provision of this License.  Upon such termination,
   Licensee must destroy all copies of Software.

e. Software, including technical data, is subject to U.S.
   export control laws, including the U.S.  Export Administration Act and its
   associated regulations, and may be subject to export or import regulations
   in other countries.  Licensee agrees to comply strictly with all such
   regulations and acknowledges that it has the responsibility to obtain
   licenses to export, re-export, or import Software.  Software may not be
   downloaded, or otherwise exported or re-exported (i) into, or to a national
   or resident of, Cuba, Iraq, Iran, North Korea, Libya, Sudan, Syria or any
   country to which the U.S. has embargoed goods; or (ii) to anyone on the
   U.S. Treasury Department's list of Specially Designated Nations or the U.S.
   Commerce Department's Table of Denial Orders.


Feedback
========

We encourage your feedback and suggestions and want to use your feedback to
improve the Software. Send all such feedback to:
<feedback@tagtraum.com>

For more information on tagtraum industries and jo!
please see <http://www.tagtraum.com/>.


*/
package com.tagtraum.metaserver;

import com.tagtraum.framework.server.I_BasicService;
import com.tagtraum.framework.server.ServerException;
import com.tagtraum.framework.server.Service;
import com.tagtraum.framework.util.BuildException;
import com.tagtraum.framework.util.I_Builder;

import java.net.InetAddress;
import java.util.Enumeration;
import java.util.Hashtable;
import java.util.Vector;

/**
 * Realisiert einen sehr simplen Meta-Service fr Services, die
 * {@link I_BasicService} implementieren.
 * Dieser Admin-Service ist <b>nicht sicher</b>. Er schtzt
 * nicht sicher gegen unbefugten Zugriff.<p>
 * Fr den Betrieb des AdminServices sind zwei
 * Konfigurationsdateien erforderlich. Zum einen ist dies die
 * bliche <code>server.cfg</code>, die jedoch um den Parameter
 * <code>VALID_ADDRESSES</code> erweitert ist. Eine typische
 * <code>server.cfg</code> sieht etwa so aus:
 * <xmp>
 * {
 * PORT = 9090
 * BINDADDRESS = "localhost"
 * BACKLOG = 50
 * MAXHANDLERTHREADS = 1
 * MINHANDLERTHREADS = 1
 * HANDLERCLASSNAME = "com.tagtraum.framework.server.AdminHandler"
 * VALID_ADDRESSES = ("localhost","127.0.0.1")
 * MAJORVERSION = 0
 * MINORVERSION = 1
 * }
 * </xmp>
 * Darber hinaus ist noch eine Datei <code>services.cfg</code>
 * ntig. In ihr wird definiert, welche Services vom AdminService
 * aus gestartet werden knnen und ob sie automatisch gestartet
 * werden. Eine <code>services.cfg</code>-Datei sieht folgendermaen
 * aus:
 * <xmp>
 * {
 * jo = {
 * Class = "com.tagtraum.jo.JoServletService";
 * AutoStart = true;
 * }
 * EchoService = {
 * Class = "com.tagtraum.Examples.Server.EchoService";
 * AutoStart = true;
 * }
 * }
 * </xmp>
 *
 * @author   Hendrik Schreiber
 * @version 1.1beta1 $Id: MetaServer.java,v 1.5 2005/03/15 20:09:44 hendriks73 Exp $
 * @see MetaClient
 */
public class MetaServer extends Service {

    /**
     * Source-Version
     */
    public static String vcid = "$Id: MetaServer.java,v 1.5 2005/03/15 20:09:44 hendriks73 Exp $";

    /**
     * Liste mit "erlaubten" Adressen
     */
    protected Vector myValidAddresses = new Vector();

    /**
     * Service-Hashtable
     */
    protected Hashtable myServices;

    /**
     * Builder-Hashtable
     */
    protected Hashtable myBuilder;

    /**
     * Constructor.
     *
     *
     * @see
     */
    public MetaServer() {
        super();

        myServices = new Hashtable();
        myBuilder = new Hashtable();
    }

    /**
     * berprft, ob ein Client mit einer bestimmten
     * IP-Adresse das Recht hat den AdminService in Anspruch
     * zu nehmen.
     *
     * @param aAddress Adresse des Clients
     */
    public boolean isValidAddress(InetAddress aAddress) {
        return myValidAddresses.contains(aAddress);
    }

    /**
     * Adds an Inetaddress to the list of priviliged
     * addresses.
     *
     * @param aAddress priviliges address
     */
    public void addValidAddress(InetAddress aAddress) {
        myValidAddresses.add(aAddress);
    }

    /**
     * Method.
     *
     *
     * @param aName
     *
     * @see
     */
    public void setName(String aName) {
        myServices.remove(aName);
        super.setName(aName);
        myServices.put(aName, this);
    }

    /**
     * Stoppt zunchst alle vom AdminSevices verwalteten Services und
     * dann den AdminService.
     *
     * @exception ServerException falls beim Stoppen etwas schiefgeht.
     */
    public synchronized void stop() throws ServerException {
        stopAllServices();
        super.stop();
    }

    /**
     * Startet den angegebenen Service.
     *
     * @param name Name des zu startenden Services
     * @exception ServerException falls beim Starten etwas schiefgeht.
     */
    public synchronized void startService(String name) throws ServerException, BuildException {
        I_BasicService aService = (I_BasicService)myServices.get(name);

        if (aService != null) {
            throw new ServerException("Service " + name + " is already running.");
        } else {
            I_Builder theBuilder = (I_Builder)myBuilder.get(name);

            if (theBuilder == null) {
                throw new ServerException("Service " + name + " does not exist.");
            }

            I_BasicService theService = (I_BasicService)theBuilder.build();

            theService.start();
            myServices.put(theBuilder.getName(), theService);
        }
    }

    /**
     * Stoppt einen Service.
     *
     * @param name Name des zu stoppenden Services
     * @exception ServerException falls beim Stoppen etwas schiefgeht.
     */
    public synchronized void stopService(String name) throws ServerException {
        I_BasicService aService = (I_BasicService)myServices.get(name);

        if (aService != null) {
            if (!aService.isAlive()) {
                throw new ServerException("Service " + name + " is not running.");
            }

            aService.stop();
            myServices.remove(name);
        } else {
            throw new ServerException("Service " + name + " does not exist.");
        }
    }

    /**
     * Stoppt alle Services.
     *
     * @exception ServerException falls beim Stoppen etwas schiefgeht.
     */
    protected void stopAllServices() throws ServerException {
        Enumeration e = myServices.elements();

        while (e.hasMoreElements()) {
            I_BasicService aService = (I_BasicService)e.nextElement();

            if (aService != this && aService.isAlive()) {
                aService.stop();
            }
        }

        myServices.clear();
    }

    /**
     * Method.
     *
     *
     * @param aBuilder
     *
     * @see
     */
    public synchronized void addBuilder(I_Builder aBuilder) {
        myBuilder.put(aBuilder.getName(), aBuilder);
    }

    /**
     * Method.
     *
     *
     * @param aName
     *
     * @see
     */
    public synchronized void removeBuilder(String aName) {
        myBuilder.remove(aName);
    }


}

java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.