Mercurial > hg > Members > tatsuki > Alice
changeset 39:3155337e754e
add logger
line wrap: on
line diff
--- a/src/alice/codesegment/CodeSegment.java Fri Jan 20 19:15:38 2012 +0900 +++ b/src/alice/codesegment/CodeSegment.java Fri Jan 27 16:57:26 2012 +0900 @@ -5,7 +5,7 @@ public abstract class CodeSegment implements Runnable { public InputDataSegment ids = new InputDataSegment(this); - public OutputDataSegment ods = new OutputDataSegment(); + public OutputDataSegment ods = new OutputDataSegment(this); public void execute() { ids.receive();
--- a/src/alice/codesegment/CodeSegmentManager.java Fri Jan 20 19:15:38 2012 +0900 +++ b/src/alice/codesegment/CodeSegmentManager.java Fri Jan 27 16:57:26 2012 +0900 @@ -4,6 +4,8 @@ import java.util.concurrent.ThreadPoolExecutor; import java.util.concurrent.TimeUnit; +import org.apache.log4j.Logger; + public class CodeSegmentManager { private static CodeSegmentManager instance = new CodeSegmentManager(); public LinkedBlockingQueue<CodeSegment> readyQueue = new LinkedBlockingQueue<CodeSegment>(); @@ -12,6 +14,7 @@ Integer.MAX_VALUE, TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>()); + private Logger log = Logger.getLogger(CodeSegmentManager.class); private CodeSegmentManager() { Runnable prepareThread = new Runnable() { @@ -22,6 +25,7 @@ try { CodeSegment cs = readyQueue.take(); codeSegmentExecutor.execute(cs); + log.debug(cs.getClass().getName()); } catch (InterruptedException e) { e.printStackTrace(); }
--- a/src/alice/codesegment/OutputDataSegment.java Fri Jan 20 19:15:38 2012 +0900 +++ b/src/alice/codesegment/OutputDataSegment.java Fri Jan 27 16:57:26 2012 +0900 @@ -10,6 +10,12 @@ public class OutputDataSegment { + CodeSegment cs; + + public OutputDataSegment(CodeSegment codeSegment) { + this.cs = codeSegment; + } + public void put(String managerKey, String key, Value val) { DataSegment.get(managerKey).put(key, val); }
--- a/src/alice/daemon/AliceDaemon.java Fri Jan 20 19:15:38 2012 +0900 +++ b/src/alice/daemon/AliceDaemon.java Fri Jan 27 16:57:26 2012 +0900 @@ -1,18 +1,44 @@ package alice.daemon; +import java.io.FileWriter; import java.io.IOException; import java.net.InetAddress; import java.net.InetSocketAddress; import java.net.ServerSocket; import java.nio.channels.ServerSocketChannel; +import org.apache.log4j.Logger; +import org.apache.log4j.PatternLayout; +import org.apache.log4j.WriterAppender; + public class AliceDaemon { private Config conf; private AcceptThread acceptThread; + private Logger log = Logger.getLogger(AliceDaemon.class); public AliceDaemon(Config conf) { this.conf = conf; + setLogger(); + } + + private void setLogger() { + Logger root = Logger.getRootLogger(); + if (conf.level != null) + root.setLevel(conf.level); + if (conf.logFile == null) + return; + PatternLayout layout = new PatternLayout(); + layout.setConversionPattern("%d %-5p %c - %m [%t] (%F:%L)%n"); + try { + FileWriter writer = new FileWriter(conf.logFile); + WriterAppender writerAppender = new WriterAppender(layout, writer); + root.removeAllAppenders(); + root.addAppender(writerAppender); + } catch (IOException e) { + e.printStackTrace(); + } + log.info("configurated"); } public void listen() {
--- a/src/alice/daemon/Config.java Fri Jan 20 19:15:38 2012 +0900 +++ b/src/alice/daemon/Config.java Fri Jan 27 16:57:26 2012 +0900 @@ -1,16 +1,35 @@ package alice.daemon; +import org.apache.log4j.Level; + public class Config { public int localPort = 10000; + public String logFile = null; + public Level level = null; public Config(String[] args) { for (int i = 0; i< args.length; i++) { if ("-p".equals(args[i])) { localPort = Integer.parseInt(args[++i]); - return; + } else if ("-log".equals(args[i])) { + logFile = args[++i]; + } else if ("-level".equals(args[i])) { + String levelStr = args[++i]; + if (levelStr.equals("fatal")) { + level = Level.FATAL; + } else if (levelStr.equals("error")) { + level = Level.ERROR; + } else if (levelStr.equals("warn")) { + level = Level.WARN; + } else if (levelStr.equals("info")) { + level = Level.INFO; + } else if (levelStr.equals("debug")) { + level = Level.DEBUG; + } } } + } }
--- a/src/alice/daemon/Connection.java Fri Jan 20 19:15:38 2012 +0900 +++ b/src/alice/daemon/Connection.java Fri Jan 27 16:57:26 2012 +0900 @@ -23,5 +23,10 @@ e.printStackTrace(); } } + + public String getInfoString() { + return socket.getInetAddress().getHostName() + + ":" + socket.getPort(); + } }
--- a/src/alice/datasegment/Command.java Fri Jan 20 19:15:38 2012 +0900 +++ b/src/alice/datasegment/Command.java Fri Jan 27 16:57:26 2012 +0900 @@ -29,4 +29,12 @@ this.reverseKey = reverseKey; } + public String getCommandString() { + String csName = "null"; + if (cs != null) { + csName = cs.toString(); + } + return this.type + " \"" + key + "\" " + val + " index=" + index + " cs=" + csName; + } + }
--- a/src/alice/datasegment/DataSegmentManager.java Fri Jan 20 19:15:38 2012 +0900 +++ b/src/alice/datasegment/DataSegmentManager.java Fri Jan 27 16:57:26 2012 +0900 @@ -4,6 +4,7 @@ import java.util.concurrent.LinkedBlockingQueue; import java.util.concurrent.atomic.AtomicInteger; +import org.apache.log4j.Logger; import org.msgpack.type.Value; import alice.codesegment.CodeSegment; @@ -15,7 +16,7 @@ public LinkedBlockingQueue<Command> replyQueue = new LinkedBlockingQueue<Command>(); protected AtomicInteger seq = new AtomicInteger(1); protected Runnable replyThread = new Runnable() { - + Logger logger = Logger.getLogger("reply"); @Override public void run() { while (true) { @@ -23,6 +24,7 @@ Command reply = replyQueue.take(); Command cmd = seqHash.get(reply.seq); cmd.cs.ids.reply(cmd.receiver, new DataSegmentValue(reply.index, reply.val, reply.reverseKey)); + logger.debug(reply.getCommandString() + " " + cmd.getCommandString()); } catch (InterruptedException e) { e.printStackTrace(); }
--- a/src/alice/datasegment/LocalDataSegmentManager.java Fri Jan 20 19:15:38 2012 +0900 +++ b/src/alice/datasegment/LocalDataSegmentManager.java Fri Jan 27 16:57:26 2012 +0900 @@ -1,5 +1,6 @@ package alice.datasegment; +import org.apache.log4j.Logger; import org.msgpack.type.Value; import alice.codesegment.CodeSegment; @@ -9,6 +10,8 @@ public String reverseKey = "local"; + private Logger logger = Logger.getLogger("local"); + public LocalDataSegmentManager() { new Thread(replyThread, "LocalDataSegmentManager").start(); } @@ -29,13 +32,17 @@ @Override public void put(String key, Value val) { DataSegmentKey dataSegmentKey = getDataSegmentKey(key); - dataSegmentKey.addCommand(new Command(CommandType.PUT, null, null, val, 0, 0, replyQueue, null, reverseKey)); + Command cmd = new Command(CommandType.PUT, null, null, val, 0, 0, replyQueue, null, reverseKey); + dataSegmentKey.addCommand(cmd); + logger.debug("\"" + key + "\" " + cmd.getCommandString()); } @Override public void update(String key, Value val) { DataSegmentKey dataSegmentKey = getDataSegmentKey(key); - dataSegmentKey.addCommand(new Command(CommandType.UPDATE, null, null, val, 0, 0, replyQueue, null, reverseKey)); + Command cmd = new Command(CommandType.UPDATE, null, null, val, 0, 0, replyQueue, null, reverseKey); + dataSegmentKey.addCommand(cmd); + logger.debug("\"" + key + "\" " + cmd.getCommandString()); } @Override @@ -45,6 +52,7 @@ Command cmd = new Command(CommandType.TAKE, receiver, null, null, index, seq, replyQueue, cs, null); seqHash.put(seq, cmd); dataSegmentKey.addCommand(cmd); + logger.debug("\"" + key + "\" " + cmd.getCommandString()); } @Override @@ -54,12 +62,15 @@ Command cmd = new Command(CommandType.PEEK, receiver, null, null, index, seq, replyQueue, cs, null); seqHash.put(seq, cmd); dataSegmentKey.addCommand(cmd); + logger.debug("\"" + key + "\" " + cmd.getCommandString()); } @Override public void remove(String key) { DataSegmentKey dataSegmentKey = getDataSegmentKey(key); - dataSegmentKey.addCommand(new Command(CommandType.REMOVE, null, null, null, 0, 0, replyQueue, null, null)); + Command cmd = new Command(CommandType.REMOVE, null, null, null, 0, 0, replyQueue, null, null); + dataSegmentKey.addCommand(cmd); + logger.debug("\"" + key + "\" " + cmd.getCommandString()); } @Override public void finish() {
--- a/src/alice/datasegment/RemoteDataSegmentManager.java Fri Jan 20 19:15:38 2012 +0900 +++ b/src/alice/datasegment/RemoteDataSegmentManager.java Fri Jan 27 16:57:26 2012 +0900 @@ -15,9 +15,10 @@ public class RemoteDataSegmentManager extends DataSegmentManager { Connection connection; - Logger logger = Logger.getLogger(RemoteDataSegmentManager.class); + Logger logger; public RemoteDataSegmentManager(String connectionKey, final String reverseKey, final String hostName, final int port) { + logger = Logger.getLogger(connectionKey); connection = new Connection(); final RemoteDataSegmentManager manager = this; new Thread(replyThread, "RemoteDataSegmentManager-" + connectionKey).start(); @@ -29,9 +30,7 @@ SocketChannel sc = SocketChannel.open(new InetSocketAddress(hostName, port)); connection.socket = sc.socket(); connect = false; - logger.info("Connect to " - + connection.socket.getInetAddress().getHostName() - + ":" + connection.socket.getPort()); + logger.info("Connect to " + connection.getInfoString()); } catch (IOException e) { try { Thread.sleep(500); @@ -48,12 +47,16 @@ @Override public void put(String key, Value val) { - connection.sendCommand(new Command(CommandType.PUT, null, key, val, 0, 0, null, null, null)); + Command cmd = new Command(CommandType.PUT, null, key, val, 0, 0, null, null, null); + connection.sendCommand(cmd); + logger.debug("\"" + key + "\" " + cmd.getCommandString()); } @Override public void update(String key, Value val) { - connection.sendCommand(new Command(CommandType.UPDATE, null, key, val, 0, 0, null, null, null)); + Command cmd = new Command(CommandType.UPDATE, null, key, val, 0, 0, null, null, null); + connection.sendCommand(cmd); + logger.debug("\"" + key + "\" " + cmd.getCommandString()); } @Override @@ -61,7 +64,8 @@ int seq = this.seq.getAndIncrement(); Command cmd = new Command(CommandType.TAKE, receiver, key, null, index, seq, replyQueue, cs, null); seqHash.put(seq, cmd); - connection.sendCommand(cmd); + connection.sendCommand(cmd); + logger.debug("\"" + key + "\" " + cmd.getCommandString()); } @Override @@ -70,15 +74,19 @@ Command cmd = new Command(CommandType.PEEK, receiver, key, null, index, seq, replyQueue, cs, null); seqHash.put(seq, cmd); connection.sendCommand(cmd); + logger.debug("\"" + key + "\" " + cmd.getCommandString()); } @Override public void remove(String key) { - connection.sendCommand(new Command(CommandType.REMOVE, null, key, null, 0, 0, null, null, null)); + Command cmd = new Command(CommandType.REMOVE, null, key, null, 0, 0, null, null, null); + connection.sendCommand(cmd); + logger.debug("\"" + key + "\" " + cmd.getCommandString()); } public void finish() { - connection.sendCommand(new Command(CommandType.FINISH, null, null, null, 0, 0, null, null, null)); + Command cmd = new Command(CommandType.FINISH, null, null, null, 0, 0, null, null, null); + connection.sendCommand(cmd); } }
--- a/src/alice/test/codesegment/local/StartCodeSegment.java Fri Jan 20 19:15:38 2012 +0900 +++ b/src/alice/test/codesegment/local/StartCodeSegment.java Fri Jan 27 16:57:26 2012 +0900 @@ -1,8 +1,5 @@ package alice.test.codesegment.local; -import org.msgpack.type.Value; -import org.msgpack.type.ValueFactory; - import alice.codesegment.CodeSegment; public class StartCodeSegment extends CodeSegment { @@ -15,8 +12,7 @@ cs.arg1.setKey("local", "key1"); System.out.println("create TestCodeSegment"); - Value val = ValueFactory.createRawValue("String data"); - ods.update("local", "key1", val); + ods.update("local", "key1", "String data"); } }
--- a/src/alice/test/topology/fish/DistributedFish.java Fri Jan 20 19:15:38 2012 +0900 +++ b/src/alice/test/topology/fish/DistributedFish.java Fri Jan 27 16:57:26 2012 +0900 @@ -6,7 +6,7 @@ public static void main(String[] args) { FishConfig conf = new FishConfig(args); - TopologyNode node = new TopologyNode(conf, StartFish.class); + new TopologyNode(conf, StartFish.class); }
--- a/src/alice/test/topology/ring/FirstRingMessagePassing.java Fri Jan 20 19:15:38 2012 +0900 +++ b/src/alice/test/topology/ring/FirstRingMessagePassing.java Fri Jan 27 16:57:26 2012 +0900 @@ -1,5 +1,8 @@ package alice.test.topology.ring; +import java.net.InetAddress; +import java.net.UnknownHostException; + import org.msgpack.type.ValueFactory; import alice.codesegment.CodeSegment; @@ -13,6 +16,13 @@ @Override public void run() { int counter = this.counter.asInteger(); + + try { + System.out.print("[" + InetAddress.getLocalHost().getHostName() + "] "); + } catch (UnknownHostException e) { + e.printStackTrace(); + } + System.out.println(++counter); ods.put("right", "counter", counter);
--- a/src/alice/test/topology/ring/RingTopology.java Fri Jan 20 19:15:38 2012 +0900 +++ b/src/alice/test/topology/ring/RingTopology.java Fri Jan 27 16:57:26 2012 +0900 @@ -6,7 +6,7 @@ public static void main(String[] args) { RingTopologyConfig conf = new RingTopologyConfig(args); - TopologyNode node = new TopologyNode(conf, StartRing.class); + new TopologyNode(conf, StartRing.class); } }
--- a/src/alice/topology/node/ConfigurationFinish.java Fri Jan 20 19:15:38 2012 +0900 +++ b/src/alice/topology/node/ConfigurationFinish.java Fri Jan 27 16:57:26 2012 +0900 @@ -28,7 +28,7 @@ } ConfigurationFinish cs3 = new ConfigurationFinish(clazz); - cs3.reverseCount.setKey("local", "reverseCount"); + cs3.reverseCount.setKey("local", "reverseCount", this.reverseCount.index); cs3.configNodeNum.setKey("local", "configNodeNum"); }
--- a/src/alice/topology/node/TopologyNode.java Fri Jan 20 19:15:38 2012 +0900 +++ b/src/alice/topology/node/TopologyNode.java Fri Jan 27 16:57:26 2012 +0900 @@ -12,7 +12,7 @@ public static void main(String[] args) { TopologyNodeConfig conf = new TopologyNodeConfig(args); - TopologyNode node = new TopologyNode(conf, null); + new TopologyNode(conf, null); } }