[Java-link-svn] SF.net SVN: java-link: [28] branches/private_welterde0/server/src/main/java /org/jl
Status: Pre-Alpha
Brought to you by:
welterde0
|
From: <wel...@us...> - 2006-11-25 17:21:45
|
Revision: 28
http://svn.sourceforge.net/java-link/?rev=28&view=rev
Author: welterde0
Date: 2006-11-25 09:21:41 -0800 (Sat, 25 Nov 2006)
Log Message:
-----------
startedreimplemention of NET::NetworkManager and Core of Server
Modified Paths:
--------------
branches/private_welterde0/server/src/main/java/org/jlink/server/Core.java
branches/private_welterde0/server/src/main/java/org/jlink/server/Main.java
Added Paths:
-----------
branches/private_welterde0/server/src/main/java/org/jlink/server/net/NetworkManager.java
Modified: branches/private_welterde0/server/src/main/java/org/jlink/server/Core.java
===================================================================
--- branches/private_welterde0/server/src/main/java/org/jlink/server/Core.java 2006-11-25 17:18:30 UTC (rev 27)
+++ branches/private_welterde0/server/src/main/java/org/jlink/server/Core.java 2006-11-25 17:21:41 UTC (rev 28)
@@ -30,6 +30,8 @@
//import::own::server::libdb
import org.jlink.server.libdb.StorageManager;
import org.jlink.server.libdb.StorageManagerJMX;
+//import::own::server::net
+import org.jlink.server.net.NetworkManager;
//import::sys
//import::sys::commons-configuration
import org.apache.commons.configuration.Configuration;
@@ -51,53 +53,99 @@
log.info("initing Core");
if(conf == null)
throw new NullPointerException("the config may not be null");
- //init StorageManager
+
+ // <editor-fold defaultstate="collapsed" desc=" init StorageManager ">
{
- try {
- log.info("creating StorageManager");
- Configuration comp_conf = conf.subset("server.db");
- this.app_storage = new StorageManager();
- this.app_storage.init(comp_conf);
- this.jmx_storage = new StorageManagerJMX(this.app_storage);
- JMXAgent.getDefault().register("org.jlink.server.libdb:type=StorageManagerJMX", this.jmx_storage);
- log.debug("done");
- } catch(Exception exc) {
- log.error("creation failed, ignoring(wish me luck)", exc);
- //TODO: split problems into StorageManger and JMX
- }
- }
+ try {
+ log.info("initalizing StorageManager");
+ //create subset for the StorageManager
+ Configuration comp_conf = conf.subset("server.db");
+ //create an instance of the StorageManager
+ this.app_storage = new StorageManager();
+ //init him, with the config
+ this.app_storage.init(comp_conf);
+ //create the JMX wrapper for the StorageManager
+ this.jmx_storage = new StorageManagerJMX(this.app_storage);
+ //register the JMX wrapper
+ JMXAgent.getDefault().register("org.jlink.server.libdb:type=StorageManagerJMX", this.jmx_storage);
+ log.debug("StorageManager initalized");
+ } catch(Exception exc) {
+ log.error("creation failed, ignoring(wish me luck)", exc);
+ //TODO: split problems into StorageManger and JMX
+ }
+ }
+ // </editor-fold>
+
+ // <editor-fold defaultstate="collapsed" desc=" init NetworkManager ">
+ {
+ try {
+ log.info("initalizing NetworkManager");
+ //create subset for the NetworkManager
+ Configuration comp_conf = conf.subset("server.net");
+ //create an instance of the NetworkManager
+ this.app_network = new NetworkManager();
+ //init it, with the subset of the config
+ this.app_network.init(comp_conf);
+ //create the JMX wrapper for the NetworkManager
+ //TODO: do this
+ //register the JMX wrapper
+ //TODO: register the JMX wrapper
+ log.info("NetworkManager initalized");
+ } catch(Exception exc) {
+ log.error("initalizing failed", exc);
+ //TODO: seperate problems into NetworkManager and NetworkManagerJMX
+ }
+
+
+ }
+ // </editor-fold>
+
+
+
}
public void start() {
log.info("starting core...");
+ //simply start the Thread
this.thread.start();
log.debug("core started");
}
public void run() {
- log.debug("waiting for lock to run");
+ log.debug("waiting for lock");
+ //synchronize, so only one Thread can run here
synchronized(runLock) {
log.debug("got lock");
+ //loop forever
while(true) {
+ //ok, not forever
if(this.doStop)
break;
try {
+ //wait 10ms => it wont eat up all CPU power
Thread.sleep(10);
+
+ //catch everything
} catch(Exception exc) {
log.error("unknown Exception cought", exc);
} catch(Error err) {
+
log.error("unknown Error caught", err);
+ throw err;
} finally {
-
+ //do cleanup stuff(stop other parts)
+ //TODO: call cleanup method
}
}
}
}
public void stop() {
+ //set internal stop flag, so the Thread will gently shutdown
this.doStop = true;
}
public void shutdown() {
+ //before shutting down, call stop
stop();
}
@@ -119,6 +167,8 @@
//Composite stuff
public StorageManager app_storage = null;
- public StorageManagerJMX jmx_storage = null;
+ public StorageManagerJMX jmx_storage = null;
+ public NetworkManager app_network = null;
+
}
Modified: branches/private_welterde0/server/src/main/java/org/jlink/server/Main.java
===================================================================
--- branches/private_welterde0/server/src/main/java/org/jlink/server/Main.java 2006-11-25 17:18:30 UTC (rev 27)
+++ branches/private_welterde0/server/src/main/java/org/jlink/server/Main.java 2006-11-25 17:21:41 UTC (rev 28)
@@ -189,7 +189,7 @@
}
}
public static void confReload() {
- log.info("hit unimplemented method");
+ log.info("hit unimplemented method");
//TODO: write this
}
Added: branches/private_welterde0/server/src/main/java/org/jlink/server/net/NetworkManager.java
===================================================================
--- branches/private_welterde0/server/src/main/java/org/jlink/server/net/NetworkManager.java (rev 0)
+++ branches/private_welterde0/server/src/main/java/org/jlink/server/net/NetworkManager.java 2006-11-25 17:21:41 UTC (rev 28)
@@ -0,0 +1,133 @@
+/*
+ * NetworkManager.java
+ *
+ * Created on 29. Oktober 2006, 14:15
+ *
+ * JLink: An Introversion Uplink Clone with multiplayer support.
+ * Copyright (C) 2006 Tassilo Schweyer
+ *
+ * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+package org.jlink.server.net;
+
+//import
+//import::own
+//import::sys
+import org.apache.log4j.Logger;
+import org.apache.commons.configuration.Configuration;
+
+/**
+ *
+ * @author welterde
+ */
+public class NetworkManager implements Runnable {
+
+ /** Creates a new instance of NetworkManager */
+ public NetworkManager() {
+ log.trace("NetworkManager created");
+ }
+
+
+ public void init(Configuration conf) {
+ //bypass, so it isnt inited multiple times
+ if(this.valid)
+ return;
+ log.debug("initing NetworkManager");
+ //process the config
+ if(conf == null)
+ throw new NullPointerException("no, the configuration may not be null");
+ this.config = conf;
+
+ //set the status variable, so we know that the NM is valid
+ this.valid = true;
+ }
+
+ public void start() {
+ //bypass, so we dont start it multiple times
+ if(this.running)
+ return;
+ log.debug("starting NetworkManager");
+ }
+
+ public void run() {
+ //bypass, so we have only one instance
+ if(this.running)
+ return;
+ //TODO: add check for not gracefully stopped threads
+ //TODO: add check, if the calling thread is the right thread
+ log.debug("running NetworkManager");
+
+ //set the status variable, so we know that we're running
+ this.running = true;
+
+ //TODO: business code
+
+ //set the status variable, so we know that we're not running anymore
+ this.running = false;
+
+ }
+
+ public void join() throws InterruptedException {
+ //bypass, so we dont want to wait for an stopped thread
+ if(!this.running)
+ return;
+ log.debug("joining NetworkManager");
+ this.thread.join();
+ }
+
+ public void stop() {
+ //bypass, so we dont want to stop an stopped thread
+ if(!this.running)
+ return;
+ log.debug("stopping NetworkManager");
+ }
+
+ public void destroy() {
+ //bypass, so we dont destroy something destroid
+ if(!this.valid)
+ return;
+ log.debug("destroying NetworkManager");
+
+ //check first if the thread is running, if so stop him
+ if(this.running) {
+ this.stop();
+ try {
+ this.join();
+ } catch(InterruptedException exc) {
+ //this should never happen
+ log.fatal("interrupted", exc);
+ }
+ }
+
+ //process the config
+ this.config = null;
+
+ //set the status variable, so we know that the NM is not valid anymore
+ this.valid = false;
+ }
+
+
+
+ private Logger log = Logger.getLogger(NetworkManager.class);
+
+ private Configuration config = null;
+
+ private Thread thread = null;
+
+ //Status
+ private boolean valid = false;
+ private boolean running = false;
+}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|