[jetrix-cvs] SF.net SVN: jetrix:[785] jetrix/trunk
Brought to you by:
smanux
From: <sm...@us...> - 2009-02-12 16:11:45
|
Revision: 785 http://jetrix.svn.sourceforge.net/jetrix/?rev=785&view=rev Author: smanux Date: 2009-02-12 16:11:42 +0000 (Thu, 12 Feb 2009) Log Message: ----------- Added a --conf startup parameter to specify the path of the server configuration file (conf/server.xml by default) The path of the channels configuration file (channels.xml) is now defined in the server configuration file Modified Paths: -------------- jetrix/trunk/build.xml jetrix/trunk/src/bin/jetrix jetrix/trunk/src/etc/conf/server.xml jetrix/trunk/src/etc/tetrinet-server.dtd jetrix/trunk/src/java/net/jetrix/Launcher.java jetrix/trunk/src/java/net/jetrix/Server.java jetrix/trunk/src/java/net/jetrix/config/ChannelsRuleSet.java jetrix/trunk/src/java/net/jetrix/config/ServerConfig.java jetrix/trunk/src/java/net/jetrix/config/ServerRuleSet.java jetrix/trunk/src/test/net/jetrix/config/ServerConfigTest.java Modified: jetrix/trunk/build.xml =================================================================== --- jetrix/trunk/build.xml 2009-02-12 15:56:40 UTC (rev 784) +++ jetrix/trunk/build.xml 2009-02-12 16:11:42 UTC (rev 785) @@ -339,6 +339,8 @@ <target name="run" depends="deploy"> <java dir="${deploy}/jetrix-${version}" jar="${deploy}/jetrix-${version}/lib/jetrix-launcher-${version}.jar" fork="true"> <sysproperty key="jetrix.debug" value="true"/> + <arg value="--conf"/> + <arg value="conf/server.xml"/> </java> </target> Modified: jetrix/trunk/src/bin/jetrix =================================================================== --- jetrix/trunk/src/bin/jetrix 2009-02-12 15:56:40 UTC (rev 784) +++ jetrix/trunk/src/bin/jetrix 2009-02-12 16:11:42 UTC (rev 785) @@ -92,7 +92,9 @@ else - echo "Usage: jetrix.sh ( commands ... )" + echo "Jetrix TetriNET Server" + echo "" + echo "Usage: jetrix ( commands ... )" echo "commands:" echo " run Start Jetrix in the current window" echo " start Start Jetrix in a separate window" Modified: jetrix/trunk/src/etc/conf/server.xml =================================================================== --- jetrix/trunk/src/etc/conf/server.xml 2009-02-12 15:56:40 UTC (rev 784) +++ jetrix/trunk/src/etc/conf/server.xml 2009-02-12 16:11:42 UTC (rev 785) @@ -33,6 +33,9 @@ <!-- Error Log, where errors are logged to --> <error-log path="log/error%g.log" /> + <!-- Path to the channels descriptor file (relative to the current configuration file) --> + <channels path="channels.xml"/> + <!-- Client listeners --> <listeners> <listener class="net.jetrix.listeners.TetrinetListener"/> Modified: jetrix/trunk/src/etc/tetrinet-server.dtd =================================================================== --- jetrix/trunk/src/etc/tetrinet-server.dtd 2009-02-12 15:56:40 UTC (rev 784) +++ jetrix/trunk/src/etc/tetrinet-server.dtd 2009-02-12 16:11:42 UTC (rev 785) @@ -1,6 +1,6 @@ <!-- Jetrix TetriNET Server -Copyright (C) 2001-2005 Emmanuel Bourg +Copyright (C) 2001-2009 Emmanuel Bourg This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License @@ -23,7 +23,7 @@ <!ELEMENT tetrinet-server (name?, language?, timeout?, max-channels?, max-players?, max-connections?, op-password, admin-password, access-log, - error-log, listeners, services?, commands, ban?, datasource?)> + error-log, channels?, listeners, services?, commands, ban?, datasource?)> <!ATTLIST tetrinet-server host CDATA #IMPLIED> <!ELEMENT name (#PCDATA)> @@ -41,6 +41,9 @@ <!ELEMENT error-log EMPTY> <!ATTLIST error-log path CDATA #REQUIRED> +<!ELEMENT channels EMPTY> +<!ATTLIST channels path CDATA #REQUIRED> + <!ELEMENT commands (command*)> <!ELEMENT command EMPTY> <!ATTLIST command class CDATA #REQUIRED> Modified: jetrix/trunk/src/java/net/jetrix/Launcher.java =================================================================== --- jetrix/trunk/src/java/net/jetrix/Launcher.java 2009-02-12 15:56:40 UTC (rev 784) +++ jetrix/trunk/src/java/net/jetrix/Launcher.java 2009-02-12 16:11:42 UTC (rev 785) @@ -81,7 +81,7 @@ /** * Unpack the pack200 files in the specified directory * - * @param directory + * @param directory the directory containing the files to be unpacked */ private static void unpack(File directory) throws IOException { @@ -111,7 +111,7 @@ * Build a classloader including the jar and zip files in the specified * directories. The directories are also included in the classpath. * - * @param directories + * @param directories the directories containing the jars to be mounted in the classpath */ private static ClassLoader createClassLoader(File... directories) throws Exception { @@ -122,12 +122,12 @@ // add the jar and zip files in the directory to the classpath File[] files = directory.listFiles(); - for (int i = 0; i < files.length; i++) + for (File file : files) { - String filename = files[i].getAbsolutePath(); + String filename = file.getAbsolutePath(); if (filename.endsWith(".jar") || filename.endsWith(".zip")) { - urls.add(files[i].toURI().toURL()); + urls.add(file.toURI().toURL()); } } Modified: jetrix/trunk/src/java/net/jetrix/Server.java =================================================================== --- jetrix/trunk/src/java/net/jetrix/Server.java 2009-02-12 15:56:40 UTC (rev 784) +++ jetrix/trunk/src/java/net/jetrix/Server.java 2009-02-12 16:11:42 UTC (rev 785) @@ -1,6 +1,6 @@ /** * Jetrix TetriNET Server - * Copyright (C) 2001-2004 Emmanuel Bourg + * Copyright (C) 2001-2009 Emmanuel Bourg * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -19,6 +19,8 @@ package net.jetrix; +import java.io.*; +import java.util.*; import java.util.concurrent.*; import java.util.logging.*; @@ -30,7 +32,7 @@ import net.jetrix.listeners.ShutdownListener; /** - * Main class, starts server components. + * Main class, starts the server components and handle the server level messages. * * @author Emmanuel Bourg * @version $Revision$, $Date$ @@ -39,19 +41,18 @@ { private static Server instance; + private Logger log = Logger.getLogger("net.jetrix"); + + private File configFile; private ServerConfig config; - private BlockingQueue<Message> queue; + private BlockingQueue<Message> queue = new LinkedBlockingQueue<Message>(); private ChannelManager channelManager; - private Logger log = Logger.getLogger("net.jetrix"); private Client console; private Server() { - // spawn the server message queue - queue = new LinkedBlockingQueue<Message>(); - // add the stop hook - Runtime.getRuntime().addShutdownHook(new Thread() + Runtime.getRuntime().addShutdownHook(new Thread("StopHook") { public void run() { @@ -61,8 +62,6 @@ } } }); - - config = new ServerConfig(); } /** @@ -84,7 +83,8 @@ private void init() { // read the server configuration - config.load(); + config = new ServerConfig(); + config.load(configFile); config.setRunning(true); // prepare the loggers @@ -286,14 +286,37 @@ } /** + * Set the server configuration file. + */ + public void setConfigFile(File configFile) + { + this.configFile = configFile; + } + + /** * Server entry point. * * @param args start parameters */ public static void main(String[] args) { - System.out.println("Jetrix TetriNET Server " + ServerConfig.VERSION + ", Copyright (C) 2001-2008 Emmanuel Bourg\n"); + System.out.println("Jetrix TetriNET Server " + ServerConfig.VERSION + ", Copyright (C) 2001-2009 Emmanuel Bourg\n"); + Server server = Server.getInstance(); + + List<String> params = Arrays.asList(args); + + // read the path of the server configuration file + int p = params.indexOf("--conf"); + if (p != -1 && p + 1 < params.size()) + { + server.setConfigFile(new File(params.get(p + 1))); + } + else + { + server.setConfigFile(new File("conf/server.xml")); + } + server.start(); } Modified: jetrix/trunk/src/java/net/jetrix/config/ChannelsRuleSet.java =================================================================== --- jetrix/trunk/src/java/net/jetrix/config/ChannelsRuleSet.java 2009-02-12 15:56:40 UTC (rev 784) +++ jetrix/trunk/src/java/net/jetrix/config/ChannelsRuleSet.java 2009-02-12 16:11:42 UTC (rev 785) @@ -29,7 +29,7 @@ * @author Emmanuel Bourg * @version $Revision$, $Date$ */ -public class ChannelsRuleSet extends RuleSetBase +class ChannelsRuleSet extends RuleSetBase { public void addRuleInstances(Digester digester) Modified: jetrix/trunk/src/java/net/jetrix/config/ServerConfig.java =================================================================== --- jetrix/trunk/src/java/net/jetrix/config/ServerConfig.java 2009-02-12 15:56:40 UTC (rev 784) +++ jetrix/trunk/src/java/net/jetrix/config/ServerConfig.java 2009-02-12 16:11:42 UTC (rev 785) @@ -43,8 +43,15 @@ */ public class ServerConfig { + private static Logger log = Logger.getLogger("net.jetrix"); + public static final String ENCODING = "ISO-8859-1"; + public static final String VERSION = "@version@"; + + public static final int STATUS_OPENED = 0; + public static final int STATUS_LOCKED = 1; + private String name; private InetAddress host; private int timeout; @@ -55,17 +62,18 @@ private String adminPassword; private String accesslogPath; private String errorlogPath; + private String channelsFile = "channels.xml"; private String motd; private Locale locale; // private List bans; - private List<ChannelConfig> channels; - private List<FilterConfig> globalFilters; - private List<Listener> listeners; - private List<Service> services; + private List<ChannelConfig> channels = new ArrayList<ChannelConfig>(); + private List<FilterConfig> globalFilters = new ArrayList<FilterConfig>(); + private List<Listener> listeners = new ArrayList<Listener>(); + private List<Service> services = new ArrayList<Service>(); private boolean running; private int status; - private Statistics statistics; + private Statistics statistics = new Statistics(); // datasource configuration private DataSourceConfig datasourceConfig; @@ -73,66 +81,54 @@ private URL serverConfigURL; private URL channelsConfigURL; - public static final int STATUS_OPENED = 0; - public static final int STATUS_LOCKED = 1; - - public static final String VERSION = "@version@"; - - private static Logger log = Logger.getLogger("net.jetrix"); - /** - * Constructor declaration + * Load the configuration */ - public ServerConfig() + public void load(File file) { - channels = new ArrayList<ChannelConfig>(); - globalFilters = new ArrayList<FilterConfig>(); - listeners = new ArrayList<Listener>(); - services = new ArrayList<Service>(); - statistics = new Statistics(); + try + { + load(file.toURI().toURL()); + } + catch (MalformedURLException e) + { + log.log(Level.SEVERE, "Unable to load the configuration", e); + } } /** * Load the configuration. */ - public void load() + public void load(URL serverConfigURL) { + this.serverConfigURL = serverConfigURL; + try { + // parse the server configuration Digester digester = new Digester(); - - // register the Jetrix server configuration file DTD - URL url = findResource("tetrinet-server.dtd"); - digester.register("-//LFJR//Jetrix TetriNET Server//EN", url.toString()); - - // register the Jetrix channels configuration file DTD - url = findResource("tetrinet-channels.dtd"); - digester.register("-//LFJR//Jetrix Channels//EN", url.toString()); - - // enable the document validation + digester.register("-//LFJR//Jetrix TetriNET Server//EN", findResource("tetrinet-server.dtd").toString()); digester.setValidating(true); - - // add the rule sets digester.addRuleSet(new ServerRuleSet()); - digester.addRuleSet(new ChannelsRuleSet()); - - // parse the server configuration digester.push(this); - serverConfigURL = findResource("conf/server.xml"); Reader reader = new InputStreamReader(serverConfigURL.openStream(), ENCODING); digester.parse(new InputSource(reader)); reader.close(); // parse the channel configuration + digester = new Digester(); + digester.register("-//LFJR//Jetrix Channels//EN", findResource("tetrinet-channels.dtd").toString()); + digester.setValidating(true); + digester.addRuleSet(new ChannelsRuleSet()); digester.push(this); - channelsConfigURL = findResource("conf/channels.xml"); + channelsConfigURL = new URL(serverConfigURL, channelsFile); reader = new InputStreamReader(channelsConfigURL.openStream(), ENCODING); digester.parse(new InputSource(reader)); reader.close(); } catch (Exception e) { - log.log(Level.SEVERE, e.getMessage(), e); + log.log(Level.SEVERE, "Unable to load the configuration", e); } } @@ -191,6 +187,9 @@ out.println(" <!-- Error Log, where errors are logged to -->"); out.println(" <error-log path=\"" + getErrorLogPath() + "\" />"); out.println(); + out.println(" <!-- Path to the channels descriptor file (relative to the current configuration file) -->"); + out.println(" <channels path=\"" + getChannelsFile() + "\"/>"); + out.println(); out.println(" <!-- Client listeners -->"); out.println(" <listeners>"); for (Listener listener : getListeners()) @@ -248,7 +247,7 @@ { Command command = commands.next(); String hidden = command.isHidden() ? " hidden=\"true\"" : ""; - Command command2 = (Command) command.getClass().newInstance(); + Command command2 = command.getClass().newInstance(); String level = command2.getAccessLevel() != command.getAccessLevel() ? " access-level=\"" + command.getAccessLevel() + "\"" : ""; out.println(" <command class=\"" + command.getClass().getName() + "\"" + hidden + level + "/>"); } @@ -667,7 +666,7 @@ if (url == null) { File file = new File(name); - url = file.toURL(); + url = file.toURI().toURL(); } return url; @@ -808,6 +807,16 @@ this.errorlogPath = errorlogPath; } + public String getChannelsFile() + { + return channelsFile; + } + + public void setChannelsFile(String channelsFile) + { + this.channelsFile = channelsFile; + } + public String getMessageOfTheDay() { return motd; Modified: jetrix/trunk/src/java/net/jetrix/config/ServerRuleSet.java =================================================================== --- jetrix/trunk/src/java/net/jetrix/config/ServerRuleSet.java 2009-02-12 15:56:40 UTC (rev 784) +++ jetrix/trunk/src/java/net/jetrix/config/ServerRuleSet.java 2009-02-12 16:11:42 UTC (rev 785) @@ -28,7 +28,7 @@ * @author Emmanuel Bourg * @version $Revision$, $Date$ */ -public class ServerRuleSet extends RuleSetBase +class ServerRuleSet extends RuleSetBase { public void addRuleInstances(Digester digester) @@ -48,6 +48,8 @@ digester.addCallParam("tetrinet-server/access-log", 0, "path"); digester.addCallMethod("tetrinet-server/error-log", "setErrorLogPath", 1); digester.addCallParam("tetrinet-server/error-log", 0, "path"); + digester.addCallMethod("tetrinet-server/channels", "setChannelsFile", 1); + digester.addCallParam("tetrinet-server/channels", 0, "path"); // command definitions digester.addObjectCreate("*/command", null, "class"); Modified: jetrix/trunk/src/test/net/jetrix/config/ServerConfigTest.java =================================================================== --- jetrix/trunk/src/test/net/jetrix/config/ServerConfigTest.java 2009-02-12 15:56:40 UTC (rev 784) +++ jetrix/trunk/src/test/net/jetrix/config/ServerConfigTest.java 2009-02-12 16:11:42 UTC (rev 785) @@ -19,6 +19,8 @@ package net.jetrix.config; +import java.net.URL; + import junit.framework.*; import net.jetrix.ChannelManager; @@ -30,12 +32,14 @@ */ public class ServerConfigTest extends TestCase { + private URL serverConfigURL = getClass().getResource("/conf/server.xml"); + public void testGetInstance() { try { ServerConfig config = new ServerConfig(); - config.load(); + config.load(serverConfigURL); } catch (Throwable e) { @@ -47,7 +51,7 @@ { // load... ServerConfig config = new ServerConfig(); - config.load(); + config.load(serverConfigURL); // create the channels for (ChannelConfig cc : config.getChannels()) @@ -61,7 +65,7 @@ // and load again ! ServerConfig config2 = new ServerConfig(); - config2.load(); + config2.load(serverConfigURL); } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |