changeset 251:88be2824a989

no use Queue
author sugi
date Mon, 17 Jun 2013 18:56:54 +0900
parents 38154e695025
children b78f52865b8d
files .hgignore src/alice/daemon/CommandMessage.java src/alice/daemon/IncomingTcpConnection.java src/alice/datasegment/Command.java src/alice/datasegment/DataSegmentKey.java
diffstat 5 files changed, 37 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- 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
--- 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;
 	}
 }
--- 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));
--- 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<Command> 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<Command> 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<Command> 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<Command> 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);
 	}
 	
 }
--- 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();
 			}