changeset 232:496b687f3793

peek or take command from local no use Reply Thread
author sugi
date Fri, 29 Mar 2013 18:32:27 +0900
parents 783946721e0d
children bc451bb72d5a
files src/alice/datasegment/DataSegmentKey.java src/alice/datasegment/DataSegmentManager.java
diffstat 2 files changed, 21 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/src/alice/datasegment/DataSegmentKey.java	Fri Mar 29 02:23:35 2013 +0900
+++ b/src/alice/datasegment/DataSegmentKey.java	Fri Mar 29 18:32:27 2013 +0900
@@ -52,11 +52,7 @@
 			boolean waitFlag2 = true;
 			for (DataSegmentValue data : dataList) {
 				if (data.index > cmd.index) {
-					try {
-						cmd.replyQueue.put(new Command(CommandType.REPLY, null, null, data.val, data.obj, data.index, cmd.seq, null, null, data.from));
-					} catch (InterruptedException e) {
-						e.printStackTrace();
-					}
+					replyValue(cmd ,data);
 					waitFlag2 = false;
 					break;
 				}
@@ -73,11 +69,7 @@
 			for (Iterator<DataSegmentValue> iter = dataList.iterator(); iter.hasNext(); ) {
 				DataSegmentValue data = iter.next();
 				if (data.index > cmd.index) {
-					try {
-						cmd.replyQueue.put(new Command(CommandType.REPLY, null, null, data.val, data.obj, data.index, cmd.seq, null, null, data.from));
-					} catch (InterruptedException e) {
-						e.printStackTrace();
-					}
+					replyValue(cmd ,data);
 					iter.remove();
 					waitFlag = false;
 					break;
@@ -94,4 +86,18 @@
 
 	}
 	
+	public void replyValue(Command cmd, DataSegmentValue data){
+		if (cmd.cs!=null){ // if cmd has cs-instance it means Command from local.
+			cmd.cs.ids.reply(cmd.receiver, new Command(CommandType.REPLY, null, null, data.val, data.obj, data.index, 0, null, null, data.from));
+			DataSegment.getLocal().getAndRemoveCmd(cmd.seq);
+			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));
+			} catch (InterruptedException e) {
+				e.printStackTrace();
+			}
+		}
+	}
+	
 }
--- a/src/alice/datasegment/DataSegmentManager.java	Fri Mar 29 02:23:35 2013 +0900
+++ b/src/alice/datasegment/DataSegmentManager.java	Fri Mar 29 18:32:27 2013 +0900
@@ -22,12 +22,11 @@
 			while (true) {
 				try {
 					Command reply = replyQueue.take();
-					Command cmd = seqHash.get(reply.seq);
+					Command cmd = getAndRemoveCmd(reply.seq);
 					if (cmd == null) {
 						logger.warn("conflict sequence number");
 						continue;
 					}
-					seqHash.remove(reply.seq);
 					cmd.cs.ids.reply(cmd.receiver, reply);
 					if (logger.isDebugEnabled())
 						logger.debug(reply.getCommandString() + " " + cmd.getCommandString());
@@ -39,6 +38,10 @@
 		
 	};
 	
+	public Command getAndRemoveCmd(int index){
+		return seqHash.remove(index);
+	}
+	
 	public void addReplyCommand(Command cmd) {
 		try {
 			replyQueue.put(cmd);