Mercurial > hg > Members > nobuyasu > jungle-network
view src/jungle/test/codesegment/practice/TestCodeSegment.java @ 9:49c0eaa4dce2
add StartCodeSegment.java
author | one |
---|---|
date | Tue, 11 Jun 2013 14:09:42 +0900 |
parents | 20498c88a70d |
children | 5376ac62ac08 |
line wrap: on
line source
package jungle.test.codesegment.practice; import java.io.IOException; import java.nio.ByteBuffer; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.Command; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.NodePath; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.logger.TreeOperationLog; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.operations.NodeOperation; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.operations.TreeOperation; import jungle.test.datasegment.store.operations.DefaultTreeOperationLogContainer; import alice.codesegment.CodeSegment; import alice.datasegment.CommandType; import alice.datasegment.Receiver; import org.msgpack.MessagePack; import org.msgpack.type.Value; public class TestCodeSegment extends CodeSegment { // create input datasegment arg1 Receiver arg1 = ids.create(CommandType.PEEK); @Override public void run() { System.out.println("type = " + arg1.type); System.out.println("index = " + arg1.index); System.out.println("data = " + arg1.getVal()); System.out.println(((Value)arg1.getVal()).getType()); MessagePack msgpack = new MessagePack(); Value logContainerValue = (Value) arg1.getVal(); DefaultTreeOperationLogContainer convertedLogContainer; TreeOperationLog convertedLog = null; try { convertedLogContainer = msgpack.convert(logContainerValue, DefaultTreeOperationLogContainer.class); convertedLog = convertedLogContainer.convert(); } catch (IOException e) { e.printStackTrace(); } for (TreeOperation treeOp : convertedLog) { NodePath path = treeOp.getNodePath(); NodeOperation nodeOp = treeOp.getNodeOperation(); Command c = nodeOp.getCommand(); String str = ""; switch (c) { case PUT_ATTRIBUTE: String k = nodeOp.getKey(); ByteBuffer value = nodeOp.getValue(); if (value.limit() < 100) { str = String.format("key:%s,value:%s", k, new String(value.array())); } else { str = String.format("key:%s,value:%d", k, value.limit()); } break; case DELETE_ATTRIBUTE: str = String.format("key:%s", nodeOp.getKey()); break; case APPEND_CHILD: str = String.format("pos:%d", nodeOp.getPosition()); break; case DELETE_CHILD: str = String.format("pos:%d", nodeOp.getPosition()); break; } System.out.println(String.format("[%s:%s]", c, str)); System.out.println("path:"); for (int i: path ) { System.out.println(i); } } System.exit(0); /* TestCodeSegment cs = new TestCodeSegment(); cs.arg1.setKey("key1", arg1.index); // DataSegment.get("local").update ods.update("local", "key1", "String data"); */ } }