changeset 205:28469b1671e7 working

repair flip API
author sugi
date Tue, 26 Mar 2013 01:45:05 +0900
parents c6a99216707a
children 5016c7e18c76
files src/alice/codesegment/InputDataSegment.java src/alice/datasegment/Command.java src/alice/datasegment/DataSegmentManager.java src/alice/datasegment/LocalDataSegmentManager.java src/alice/datasegment/Receiver.java src/alice/test/codesegment/api/FlipTest.java
diffstat 6 files changed, 44 insertions(+), 54 deletions(-) [+]
line wrap: on
line diff
--- a/src/alice/codesegment/InputDataSegment.java	Mon Mar 25 18:49:01 2013 +0900
+++ b/src/alice/codesegment/InputDataSegment.java	Tue Mar 26 01:45:05 2013 +0900
@@ -2,8 +2,6 @@
 
 import java.util.concurrent.atomic.AtomicInteger;
 
-import org.msgpack.type.Value;
-
 import alice.datasegment.Command;
 import alice.datasegment.CommandType;
 import alice.datasegment.DataSegment;
@@ -21,8 +19,6 @@
 	public CodeSegment cs;
 	private AtomicInteger count = new AtomicInteger(1); // 1 for no input data segments
 	private AtomicInteger keyCount = new AtomicInteger(0); // number of DataSegments
-
-	private Command cmd;
 	
 	public InputDataSegment(CodeSegment cs) {
 		this.cs = cs;
@@ -60,16 +56,16 @@
 		DataSegment.getLocal().take(receiver, key, index, cs);
 	}
 	
-	public void flip(CommandType type, String key, Value val,Object obj) {
-		cmd.setElement(type, key, val, obj);
+	public void flip(Command cmd) {
 		DataSegment.getLocal().flip(cmd);
 	}
 
-	public void reply(Receiver receiver, DataSegmentValue val) {
+	public void reply(Receiver receiver, DataSegmentValue val, Command reply) {
 		receiver.index = val.index;
 		receiver.val = val.val;
 		receiver.from = val.from;
 		receiver.obj = val.obj;
+		receiver.setCommand(reply);
 		receive();
 	}
 
@@ -98,15 +94,4 @@
 	public Receiver create(CommandType type) {
 		return new Receiver(this, type);
 	}
-	
-	public void setCommand(Command cmd) {
-		this.cmd = cmd;
-	}
-
-	public void reply(Receiver receiver, int index, Value val, Object obj,
-			String reverseKey) {
-		// TODO Auto-generated method stub
-		
-	}
-
 }
--- a/src/alice/datasegment/Command.java	Mon Mar 25 18:49:01 2013 +0900
+++ b/src/alice/datasegment/Command.java	Tue Mar 26 01:45:05 2013 +0900
@@ -67,6 +67,8 @@
 		this.key = key;
 		this.val = val;
 		this.obj = obj;
+		this.index = 0;
+		this.seq = 0;
 		this.replyQueue = null;
 		this.cs = null;
 		this.reverseKey = "local";
--- a/src/alice/datasegment/DataSegmentManager.java	Mon Mar 25 18:49:01 2013 +0900
+++ b/src/alice/datasegment/DataSegmentManager.java	Tue Mar 26 01:45:05 2013 +0900
@@ -28,8 +28,7 @@
 						continue;
 					}
 					seqHash.remove(reply.seq);
-					cmd.cs.ids.reply(cmd.receiver, new DataSegmentValue(reply.index, reply.val, reply.obj, reply.reverseKey));
-					cmd.cs.ids.setCommand(cmd);
+					cmd.cs.ids.reply(cmd.receiver, new DataSegmentValue(reply.index, reply.val, reply.obj, reply.reverseKey), reply);
 					if (logger.isDebugEnabled())
 						logger.debug(reply.getCommandString() + " " + cmd.getCommandString());
 				} catch (InterruptedException e) {
--- a/src/alice/datasegment/LocalDataSegmentManager.java	Mon Mar 25 18:49:01 2013 +0900
+++ b/src/alice/datasegment/LocalDataSegmentManager.java	Tue Mar 26 01:45:05 2013 +0900
@@ -135,6 +135,15 @@
 	public void close() {
 		
 	}
+	
+	
+	public void flip(String key, Object val,CommandType type) {
+		DataSegmentKey dataSegmentKey = getDataSegmentKey(key);
+		Command cmd = new Command(type, null, key, val, 0, 0, null, null, reverseKey);
+		addCommand(dataSegmentKey, cmd);
+		if (logger.isDebugEnabled())
+			logger.debug(cmd.getCommandString());
+	}
 
 	public void flip(Command cmd){
 		DataSegmentKey dataSegmentKey = getDataSegmentKey(cmd.key);
--- a/src/alice/datasegment/Receiver.java	Mon Mar 25 18:49:01 2013 +0900
+++ b/src/alice/datasegment/Receiver.java	Tue Mar 26 01:45:05 2013 +0900
@@ -25,6 +25,7 @@
 	
 	public String managerKey; // for debugging
 	public String key; 		  // for debugging
+	private Command cmd;      // for flip
 	
 	public Receiver(InputDataSegment ids, CommandType type) {
 		this.ids = ids;
@@ -32,32 +33,32 @@
 		ids.regist();
 	}
 	
+	public void setCommand(Command cmd) {
+		this.cmd = cmd;
+		
+	}
+	
 	public void flip(CommandType type, String key, int val){
-		ids.flip(type, key, ValueFactory.createIntegerValue(val), null);
+		flip(type, key, ValueFactory.createIntegerValue(val));
 	}
 	
 	public void flip(CommandType type, String key, String val){
-		ids.flip(type, key, ValueFactory.createRawValue(val), null);
+		flip(type, key, ValueFactory.createRawValue(val));
 	}
 	
 	public void flip(CommandType type, String key, byte[] val){
-		ids.flip(type, key, ValueFactory.createRawValue(val, true), null);
+		flip(type, key, ValueFactory.createRawValue(val, true));
 	}
 	
-	public <T> void flip(CommandType type, String key, T val, Boolean covertFlag){
-		if (covertFlag){ 
-			try {
-				ids.flip(type, key, SingletonMessage.getInstance().unconvert(val), null);
-			} catch (IOException e) {
-				e.printStackTrace();
-			}
-		} else {
-			ids.flip(type, key, null, val);
-		}
+	public void flip(CommandType type, String key, Object obj, Boolean covertFlag){
+		cmd.setElement(type, key, null, obj);
+		ids.flip(cmd);
 	}
 	
+	
 	public void flip(CommandType type, String key, Value val){
-		ids.flip(type, key, val, null);
+		cmd.setElement(type, key, val, null);
+		ids.flip(cmd);
 	}
 	
 	public void setKey(String managerKey, String key) {
--- a/src/alice/test/codesegment/api/FlipTest.java	Mon Mar 25 18:49:01 2013 +0900
+++ b/src/alice/test/codesegment/api/FlipTest.java	Tue Mar 26 01:45:05 2013 +0900
@@ -21,27 +21,21 @@
 
 	@Override
 	public void run() {
-		if (flag){
-			System.out.println(System.currentTimeMillis() - t );
-			//System.out.println(" "+arg1.obj+" "+arg1.index);
-			//if (count >= 100) 
-			System.exit(0);
-			//flag = false;
-			//count++;
-			//new FlipCodeSegment(Long.toString(t)).execute();
-		} else {
-			t = System.currentTimeMillis();
-			
-			for (int i = 0;i<100000;i++){
-				
-				Integer num = i;
-				arg1.flip(CommandType.UPDATE, arg1.key, num);
-				//ods.update(arg1.key, num, false);
-			}
+
+		System.out.println(arg1.obj);
+
 
-			flag = true;
-			new FlipTest(arg1.key,100000);
-		}
+		Integer num = (Integer) arg1.obj;
+		
+		num++;
+		//System.out.println(arg1.obj);
+		//arg1.flip(CommandType.UPDATE, arg1.key, num, false);
+		ods.update(arg1.key, num, false);
+
+		//System.out.println(arg1.obj);
+		//flag = true;
+		new FlipTest(arg1.key,arg1.index);
 	}
 
+
 }