changeset 64:7aaadd08288c

add getLocal method to DataSegment
author kazz
date Thu, 09 Feb 2012 19:20:24 +0900
parents 498d1d2524d3
children ca42a2c8ac22
files src/alice/daemon/IncomingTcpConnection.java src/alice/datasegment/DataSegment.java src/alice/datasegment/LocalDataSegmentManager.java
diffstat 3 files changed, 16 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/src/alice/daemon/IncomingTcpConnection.java	Thu Feb 09 18:53:11 2012 +0900
+++ b/src/alice/daemon/IncomingTcpConnection.java	Thu Feb 09 19:20:24 2012 +0900
@@ -40,24 +40,22 @@
 			try {
 				CommandMessage msg = unpacker.read(CommandMessage.class);
 				CommandType type = CommandType.getCommandTypeFromId(msg.type);
-				LocalDataSegmentManager lmanager = (LocalDataSegmentManager)DataSegment.get("local");
-				DataSegmentKey dsKey = lmanager.getDataSegmentKey(msg.key);
 				switch (type) {
 				case UPDATE:
-					dsKey.addCommand(new Command(type, null, null, msg.val, 0, 0, null, null, reverseKey));
+					getDataSegmentKey(msg).addCommand(new Command(type, null, null, msg.val, 0, 0, null, null, reverseKey));
 					break;
 				case PUT:
-					dsKey.addCommand(new Command(type, null, null, msg.val, 0, 0, null, null, reverseKey));
+					getDataSegmentKey(msg).addCommand(new Command(type, null, null, msg.val, 0, 0, null, null, reverseKey));
 					break;
 				case PEEK:
 					//Command(CommandType cmdType, String argKey, Value val, int index, int seq, BlockingQueue<Command> replyQueue, CodeSegment cs) {
-					dsKey.addCommand(new Command(type, null, null, null, msg.index, msg.seq, connection.sendQueue, null, null));
+					getDataSegmentKey(msg).addCommand(new Command(type, null, null, null, msg.index, msg.seq, connection.sendQueue, null, null));
 					break;
 				case TAKE:
-					dsKey.addCommand(new Command(type, null, null, null, msg.index, msg.seq, connection.sendQueue, null, null));
+					getDataSegmentKey(msg).addCommand(new Command(type, null, null, null, msg.index, msg.seq, connection.sendQueue, null, null));
 					break;	
 				case REMOVE:
-					dsKey.addCommand(new Command(type, null, null, null, 0, 0, null, null, null));
+					getDataSegmentKey(msg).addCommand(new Command(type, null, null, null, 0, 0, null, null, null));
 					break;
 				case REPLY:
 					try {
@@ -88,5 +86,8 @@
 			}
 		}
 	}
-	
+	private DataSegmentKey getDataSegmentKey(CommandMessage msg) {
+		LocalDataSegmentManager lmanager = DataSegment.getLocal();
+		return lmanager.getDataSegmentKey(msg.key);
+	}
 }
--- a/src/alice/datasegment/DataSegment.java	Thu Feb 09 18:53:11 2012 +0900
+++ b/src/alice/datasegment/DataSegment.java	Thu Feb 09 19:20:24 2012 +0900
@@ -7,16 +7,21 @@
 public class DataSegment {
 	
 	private static DataSegment dataSegment = new DataSegment();
+	private LocalDataSegmentManager local = new LocalDataSegmentManager();
 	private ConcurrentHashMap<String, DataSegmentManager> dataSegmentManageres = new ConcurrentHashMap<String, DataSegmentManager>();
 	private ConcurrentHashMap<String, IncomingTcpConnection> acceptHash = new ConcurrentHashMap<String, IncomingTcpConnection>();
 	
 	private DataSegment() {
-		dataSegmentManageres.put("local", new LocalDataSegmentManager());
+		dataSegmentManageres.put("local", local);
 	}
 	
 	public static DataSegmentManager get(String key) {
 		return dataSegment.dataSegmentManageres.get(key);
 	}
+
+	public static LocalDataSegmentManager getLocal() {
+		return dataSegment.local;
+	}
 	
 	public static void regist(String key, DataSegmentManager manager) {
 		dataSegment.dataSegmentManageres.put(key, manager);
--- a/src/alice/datasegment/LocalDataSegmentManager.java	Thu Feb 09 18:53:11 2012 +0900
+++ b/src/alice/datasegment/LocalDataSegmentManager.java	Thu Feb 09 19:20:24 2012 +0900
@@ -19,7 +19,7 @@
 	}
 	
 	public DataSegmentKey getDataSegmentKey(String key) {
-		DataSegmentKey dsKey= dataSegments.get(key);
+		DataSegmentKey dsKey = dataSegments.get(key);
 		if (dsKey != null)
 			return dsKey;
 		if (key == null)