Package com.rimfaxe.webserver.seda

Source Code of com.rimfaxe.webserver.seda.ServerHandlerManager

/*
* ServerHandlerManager.java
*
*
* Copyright (c) 2003 Rimfaxe ApS  (www.rimfaxe.com). 
* All rights reserved.
*
* This package is written by Lars Andersen <lars@rimfaxe.com>
* and licensed by Rimfaxe ApS.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
*    notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
*    notice, this list of conditions and the following disclaimer in
*    the documentation and/or other materials provided with the
*    distribution.
*
* 3. The end-user documentation included with the redistribution, if
*    any, must include the following acknowlegement:
*       "This product includes software developed by Rimfaxe ApS
          (www.rimfaxe.com)"
*    Alternately, this acknowlegement may appear in the software itself,
*    if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "Rimfaxe", "Rimfaxe Software", "Lars Andersen" and
*    "Rimfaxe WebServer" must not be used to endorse or promote products
*    derived from this software without prior written permission. For written
*    permission, please contact info@rimfaxe.com
*
* 5. Products derived from this software may not be called "Rimfaxe"
*    nor may "Rimfaxe" appear in their names without prior written
*    permission of the Rimfaxe ApS.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
*/

package com.rimfaxe.webserver.seda;

import java.util.*;
import com.rimfaxe.webserver.Configuration;

/**
*
* @author  Lars Andersen
*/
public class ServerHandlerManager
{
   
  protected Hashtable handlers = null;
 
 
  /** Creates a new instance of ServerHandlerManager */
  public ServerHandlerManager(Configuration conf)
  {
    conf.initialize();
    this.handlers    = new Hashtable(7);
   
    Enumeration enum = conf.getVHostPortList();
    while (enum.hasMoreElements())
    {
      com.rimfaxe.webserver.ServerPort serverport = (com.rimfaxe.webserver.ServerPort) enum.nextElement();
      launchServerHandler(serverport,conf)
    }
   
    Enumeration e = handlers.keys();
    Server s;
    while (e.hasMoreElements())
    {
      String id = (String) e.nextElement();
      s = lookupServerHandler(id);
 
      try
      {
  s.startup();
      }
      catch (Exception ex)
      {
  System.out.println("Unknown error while starting "+id+": "+ex.getMessage());
  s.shutdown();
  removeServerHandler(s);
     
    }
   
    System.out.println("\n");
    System.out.println("===============================================================");
    System.out.println(""+conf.getBanner()+"\n");
   
    e = handlers.keys();
    while (e.hasMoreElements())
    {
      String id = (String) e.nextElement();
      s = lookupServerHandler(id);
 
      try
      {
  s.emitTraces();
      }
      catch (Exception ex)
      {
      } 
    }
    System.out.println("");
    System.out.println("visit http://www.rimfaxe.com for more info");
    System.out.println("===============================================================");
    System.out.println("\n");
  }
 
  public void removeServerHandler(Server server)
  {
     handlers.remove(server.getIdentifier());
  }
 
  public Server lookupServerHandler(String id)
  {
  return (Server) handlers.get(id);
  }
 
  public void launchServerHandler(com.rimfaxe.webserver.ServerPort serverport, com.rimfaxe.webserver.Configuration conf)
  {
    Server server = null;
    // This is a fresh new server handler:
    try
    {
      server  = new Server();
      server.initialize(this, serverport.getDesc(), serverport, conf);
      serverport.addDaemon(server);
    }
    catch (Exception ex)
    {
      System.out.println("Generic Exception");
      return;
    }
 

    handlers.put(serverport.getDesc(), server);
  }
 
  public static void startup()
  {
    Configuration configuration = com.rimfaxe.webserver.ObjectStore.getConfiguration();
    new ServerHandlerManager(configuration);     
  }
 
}
TOP

Related Classes of com.rimfaxe.webserver.seda.ServerHandlerManager

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.