From 8c958b95a3b01c1b1b392723e2b35c7575e3a45e Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Mon, 3 May 2010 07:13:40 +0000 Subject: --- nbproject/project.properties | 3 ++ src/net/sourceforge/opentracking/Server.java | 53 ++++++++++++++++++++-- .../protocol/gps103/Gps103ProtocolDecoder.java | 1 - .../protocol/xexun/XexunFrameDecoder.java | 3 -- 4 files changed, 51 insertions(+), 9 deletions(-) diff --git a/nbproject/project.properties b/nbproject/project.properties index a3dfebbd8..0fa69139c 100644 --- a/nbproject/project.properties +++ b/nbproject/project.properties @@ -1,3 +1,5 @@ +application.title=tracker-server +application.vendor=user build.classes.dir=${build.dir}/classes build.classes.excludes=**/*.java,**/*.form # This directory is removed when the project is cleaned: @@ -18,6 +20,7 @@ debug.test.classpath=\ dist.dir=dist dist.jar=${dist.dir}/tracker-server.jar dist.javadoc.dir=${dist.dir}/javadoc +endorsed.classpath= excludes= file.reference.netty-3.1.5.GA.jar=C:\\WorkJava\\netty-3.1.5.GA\\jar\\netty-3.1.5.GA.jar includes=** diff --git a/src/net/sourceforge/opentracking/Server.java b/src/net/sourceforge/opentracking/Server.java index d9b182d11..acee30037 100644 --- a/src/net/sourceforge/opentracking/Server.java +++ b/src/net/sourceforge/opentracking/Server.java @@ -26,10 +26,16 @@ import java.sql.DriverManager; import java.sql.Connection; import java.sql.ResultSet; import java.sql.SQLException; +import java.util.logging.Logger; +import java.util.logging.FileHandler; +import java.util.logging.Formatter; +import java.util.logging.Level; +import java.util.logging.LogRecord; import net.sourceforge.opentracking.helper.NamedParameterStatement; import org.jboss.netty.handler.codec.string.StringDecoder; import org.jboss.netty.handler.codec.frame.DelimiterBasedFrameDecoder; import org.jboss.netty.buffer.ChannelBuffers; +import org.jboss.netty.handler.logging.LoggingHandler; import net.sourceforge.opentracking.protocol.xexun.XexunFrameDecoder; import net.sourceforge.opentracking.protocol.xexun.XexunProtocolDecoder; import net.sourceforge.opentracking.protocol.gps103.Gps103ProtocolDecoder; @@ -44,8 +50,11 @@ public class Server implements DataManager { */ private List serverList; + private boolean loggerEnable; + public Server() { serverList = new LinkedList(); + loggerEnable = false; } /** @@ -58,13 +67,11 @@ public class Server implements DataManager { Properties properties = new Properties(); if (arguments.length > 0) { properties.loadFromXML(new FileInputStream(arguments[0])); - }/* else { - properties.loadFromXML( - new FileInputStream("/home/user/NetBeansProjects/tracker-server/dev/configuration2.xml")); - }*/ - //properties.loadFromXML(Server.class.getResourceAsStream("/configuration.xml")); + } initDatabase(properties); + initLogger(properties); + initXexunServer(properties); initGps103Server(properties); } @@ -162,6 +169,36 @@ public class Server implements DataManager { insertPosition.executeUpdate(); } + /** + * Init logger + */ + public void initLogger(Properties properties) throws IOException { + + loggerEnable = Boolean.valueOf(properties.getProperty("logger.enable")); + + if (loggerEnable) { + + Logger logger = Logger.getLogger("logger"); + String fileName = properties.getProperty("logger.file"); + if (fileName != null) { + + FileHandler file = new FileHandler(fileName, true); + + file.setFormatter(new Formatter() { + private final String LINE_SEPARATOR = + System.getProperty("line.separator", "\n"); + + public String format(LogRecord record) { + return record.getMessage().concat(LINE_SEPARATOR); + } + }); + + logger.setLevel(Level.ALL); + logger.addHandler(file); + } + } + } + /** * Init Xexun server */ @@ -173,6 +210,9 @@ public class Server implements DataManager { TrackerServer server = new TrackerServer( Integer.valueOf(properties.getProperty("xexun.port"))); + if (loggerEnable) { + server.getPipeline().addLast("logger", new LoggingHandler("logger")); + } server.getPipeline().addLast("frameDecoder", new XexunFrameDecoder()); server.getPipeline().addLast("stringDecoder", new StringDecoder()); server.getPipeline().addLast("objectDecoder", new XexunProtocolDecoder(this)); @@ -194,6 +234,9 @@ public class Server implements DataManager { TrackerServer server = new TrackerServer( Integer.valueOf(properties.getProperty("gps103.port"))); + if (loggerEnable) { + server.getPipeline().addLast("logger", new LoggingHandler("logger")); + } byte delimiter[] = { (byte) ';' }; server.getPipeline().addLast("frameDecoder", new DelimiterBasedFrameDecoder(1024, ChannelBuffers.wrappedBuffer(delimiter))); diff --git a/src/net/sourceforge/opentracking/protocol/gps103/Gps103ProtocolDecoder.java b/src/net/sourceforge/opentracking/protocol/gps103/Gps103ProtocolDecoder.java index bcce3531c..0b9b1c5bf 100644 --- a/src/net/sourceforge/opentracking/protocol/gps103/Gps103ProtocolDecoder.java +++ b/src/net/sourceforge/opentracking/protocol/gps103/Gps103ProtocolDecoder.java @@ -72,7 +72,6 @@ public class Gps103ProtocolDecoder extends OneToOneDecoder { // Parse message String sentence = (String) msg; - System.out.println("message: " + sentence); Matcher parser = pattern.matcher(sentence); if (!parser.matches()) { return null; diff --git a/src/net/sourceforge/opentracking/protocol/xexun/XexunFrameDecoder.java b/src/net/sourceforge/opentracking/protocol/xexun/XexunFrameDecoder.java index d864b10ba..8c4c4eb70 100644 --- a/src/net/sourceforge/opentracking/protocol/xexun/XexunFrameDecoder.java +++ b/src/net/sourceforge/opentracking/protocol/xexun/XexunFrameDecoder.java @@ -52,9 +52,6 @@ public class XexunFrameDecoder extends FrameDecoder { Channel channel, ChannelBuffer buf) throws Exception { - System.out.println("read: " + buf.readableBytes()); - System.out.println("buffer: " + buf.toString("UTF-8")); - // Check minimum length int length = buf.readableBytes(); if (length < 100) { -- cgit v1.2.3