# HG changeset patch # User sugi # Date 1371463014 -32400 # Node ID 88be2824a98981b86d6c221c88cedf07bd4a5ac6 # Parent 38154e695025aa544fcd6bcca0a678022f80f741 no use Queue diff -r 38154e695025 -r 88be2824a989 .hgignore --- a/.hgignore Tue Jun 11 16:58:35 2013 +0900 +++ b/.hgignore Mon Jun 17 18:56:54 2013 +0900 @@ -2,4 +2,6 @@ syntax: regexp ^classes$ syntax: regexp -^Alice\.jar$ \ No newline at end of file +^Alice\.jar$ +syntax: regexp +^src/alice/datasegment/MyLinkedBlockingQueue\.java$ \ No newline at end of file diff -r 38154e695025 -r 88be2824a989 src/alice/daemon/CommandMessage.java --- a/src/alice/daemon/CommandMessage.java Tue Jun 11 16:58:35 2013 +0900 +++ b/src/alice/daemon/CommandMessage.java Mon Jun 17 18:56:54 2013 +0900 @@ -10,14 +10,16 @@ public int seq; public String key; public Value val; + public boolean flag; public CommandMessage() {} - public CommandMessage(int type, int index, int seq, String key, Value val) { + public CommandMessage(int type, int index, int seq, String key, Value val, boolean flag) { this.type = type; this.index = index; this.seq = seq; this.key = key; this.val = val; + this.flag = flag; } } diff -r 38154e695025 -r 88be2824a989 src/alice/daemon/IncomingTcpConnection.java --- a/src/alice/daemon/IncomingTcpConnection.java Tue Jun 11 16:58:35 2013 +0900 +++ b/src/alice/daemon/IncomingTcpConnection.java Mon Jun 17 18:56:54 2013 +0900 @@ -49,10 +49,10 @@ getDataSegmentKey(msg).runCommand(new Command(type, null, null, msg.val, 0, 0, null, null, reverseKey)); break; case PEEK: - getDataSegmentKey(msg).runCommand(new Command(type, null, null, null, msg.index, msg.seq, connection.sendQueue, null, null)); + getDataSegmentKey(msg).runCommand(new Command(type, null, null, null, msg.index, msg.seq, connection, null, null, msg.flag)); break; case TAKE: - getDataSegmentKey(msg).runCommand(new Command(type, null, null, null, msg.index, msg.seq, connection.sendQueue, null, null)); + getDataSegmentKey(msg).runCommand(new Command(type, null, null, null, msg.index, msg.seq, connection, null, null, msg.flag)); break; case REMOVE: getDataSegmentKey(msg).runCommand(new Command(type, null, null, null, 0, 0, null, null, null)); diff -r 38154e695025 -r 88be2824a989 src/alice/datasegment/Command.java --- a/src/alice/datasegment/Command.java Tue Jun 11 16:58:35 2013 +0900 +++ b/src/alice/datasegment/Command.java Mon Jun 17 18:56:54 2013 +0900 @@ -7,6 +7,7 @@ import alice.codesegment.CodeSegment; import alice.codesegment.SingletonMessage; import alice.daemon.CommandMessage; +import alice.daemon.Connection; public class Command { public CommandType type; @@ -15,10 +16,12 @@ public Value val; public int index; public int seq; + public Connection connection; // for remote public BlockingQueue replyQueue; public CodeSegment cs; public String reverseKey; public Object obj; + public boolean flag; public Command(CommandType cmdType, Receiver receiver, String key, Value val, int index, int seq, BlockingQueue replyQueue, CodeSegment cs, String reverseKey) { this.type = cmdType; @@ -30,7 +33,22 @@ this.replyQueue = replyQueue; this.cs = cs; this.reverseKey = reverseKey; + this.flag = false; } + + public Command(CommandType cmdType, Receiver receiver, String key, Value val, int index, int seq, Connection connection, CodeSegment cs, String reverseKey, boolean flag) { + this.type = cmdType; + this.receiver = receiver; + this.key = key; + this.val = val; + this.index = index; + this.seq = seq; + this.connection = connection; + this.cs = cs; + this.reverseKey = reverseKey; + this.flag = flag; + } + public Command(CommandType cmdType, Receiver receiver, String key, Object obj, int index, int seq, BlockingQueue replyQueue, CodeSegment cs, String reverseKey) { this.type = cmdType; this.receiver = receiver; @@ -41,6 +59,7 @@ this.replyQueue = replyQueue; this.cs = cs; this.reverseKey = reverseKey; + this.flag = false; } public Command(CommandType cmdType, Receiver receiver, String key, Value val, Object obj, int index, int seq, BlockingQueue replyQueue, CodeSegment cs, String reverseKey) { @@ -54,6 +73,7 @@ this.replyQueue = replyQueue; this.cs = cs; this.reverseKey = reverseKey; + this.flag = false; } public String getCommandString() { @@ -71,7 +91,7 @@ e.printStackTrace(); } } - return new CommandMessage(type.id, index, seq, key, val); + return new CommandMessage(type.id, index, seq, key, val, flag); } } diff -r 38154e695025 -r 88be2824a989 src/alice/datasegment/DataSegmentKey.java --- a/src/alice/datasegment/DataSegmentKey.java Tue Jun 11 16:58:35 2013 +0900 +++ b/src/alice/datasegment/DataSegmentKey.java Mon Jun 17 18:56:54 2013 +0900 @@ -88,7 +88,14 @@ cmd = null; // someone has been holding instance. } else { try { - cmd.replyQueue.put(new Command(CommandType.REPLY, null, null, data.val, data.obj, data.index, cmd.seq, null, null, data.from)); + if (!cmd.flag){ + cmd.connection.sendQueue.put(new Command(CommandType.REPLY, null, null, data.val, data.obj, data.index, cmd.seq, null, null, data.from)); + } + else { + cmd.connection.write(new Command(CommandType.REPLY, null, null, data.val, data.obj, data.index, cmd.seq, null, null, data.from)); + cmd = null; + } + } catch (InterruptedException e) { e.printStackTrace(); }