/*
* $Id: Main1.html,v 1.5 2003/08/26 17:04:38 suhrin Exp $
*
* Copyright (c) 1999-2003 Gnome Ltd. All Rights Reserved.
*
* This software is the confidential and proprietary information of
* Gnome Ltd. You shall not disclose such Confidential
* Information and shall use it only in accordance with the terms
* of the license agreement you entered into with Gnome Ltd.
*/
package SK.gnome.dwarf.sample;
import java.net.URL;
import java.util.Properties;
import SK.gnome.dwarf.main.*;
import SK.gnome.dwarf.main.cmd.*;
import SK.gnome.dwarf.log.*;
import SK.gnome.dwarf.tcpip.*;
/**
* Main server application instantiated and configured programatically.
*/
public class Main1
{
/**
* The main executive method.
*
* @param args the arguments (ignored)
* @throws Exception if an error occurs
*/
public static void main(String[] args) throws Exception
{
// main server
MainServer mainServer = new MainServer("Sample Server");
mainServer.setLogFacility("server");
// server console
Console console = new Console("Console");
console.addService(new HelpCmd("?"));
console.addService(new HelpCmd("help"));
console.addService(new LSCmd("ls"));
console.addService(new CSCmd("cs"));
console.addService(new ReportCmd("report"));
console.addService(new DebugCmd("debug"));
console.addService(new TraceCmd("trace"));
mainServer.addService(console);
// log server
LogServer logServer = new LogServer("Log Server");
logServer.setLogFacility("log");
// screen logger
StreamLogger logger = new SystemLogger("Console Logger");
logger.setLevels("trace*");
logger.setFacilities("all");
logger.setDateTimeFormat("HH:mm:ss.SSS");
logger.setExtendedInfo(true);
logger.setMarkInterval(5);
logServer.addService(logger);
// file logger
logger = new FileLogger("File Logger");
logger.setLevels("info*");
logger.setFacilities("all");
logger.setExtendedInfo(true);
((FileLogger)logger).setFile(new java.io.File("log/server.log"));
logServer.addService(logger);
mainServer.addService(logServer);
// TCP server
QuoteServer quoteServer = new QuoteServer("Quote Server");
quoteServer.setLogFacility("rfc865_quote");
quoteServer.setHandlerClass(QuoteHandler.class);
quoteServer.setMinHandlers(1);
quoteServer.setMaxHandlers(3);
// source of quote strings
Properties quotes = new Properties();
quotes.load(new URL("file:conf/samples/dwarf/quote/quotes.properties").openStream());
quoteServer.setQuotes(quotes);
// TCP listener
TCPListener listener = new TCPListener("Quote Listener");
listener.setPort(17);
quoteServer.addService(listener);
mainServer.addService(quoteServer);
// initial debugging and tracing
Log.setDebug("tcp");
Log.setTrace("tcp");
// initialize the main server
mainServer.init(null);
// start the main server
mainServer.start();
}
}
|