Mercurial > hg > Members > nobuyasu > jungle-network
changeset 3:3770d2be3e73
modified DfaultNodePathContainer
author | one |
---|---|
date | Mon, 10 Jun 2013 01:18:45 +0900 |
parents | 20498c88a70d |
children | 2900e0b1d7e6 |
files | .classpath src/jungle/test/datasegment/store/operations/DefaultNodeOperationContainer.java src/jungle/test/datasegment/store/operations/DefaultNodePathContainer.java |
diffstat | 3 files changed, 46 insertions(+), 10 deletions(-) [+] |
line wrap: on
line diff
--- a/.classpath Sun Jun 09 13:53:16 2013 +0900 +++ b/.classpath Mon Jun 10 01:18:45 2013 +0900 @@ -4,5 +4,6 @@ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/> <classpathentry kind="lib" path="/Users/nobuyasu/workspace/Alice/Alice.jar"/> <classpathentry kind="lib" path="/Users/nobuyasu/workspace/jungle-core/target/jungle-core-0.0.1-SNAPSHOT.jar"/> + <classpathentry kind="lib" path="/Users/nobuyasu/opt/lib/functionaljava.jar"/> <classpathentry kind="output" path="bin"/> </classpath>
--- a/src/jungle/test/datasegment/store/operations/DefaultNodeOperationContainer.java Sun Jun 09 13:53:16 2013 +0900 +++ b/src/jungle/test/datasegment/store/operations/DefaultNodeOperationContainer.java Mon Jun 10 01:18:45 2013 +0900 @@ -13,7 +13,6 @@ import org.msgpack.MessagePack; import org.msgpack.annotation.Message; import org.msgpack.template.OrdinalEnumTemplate; -import org.msgpack.template.Template; import org.msgpack.type.Value; @Message @@ -24,6 +23,19 @@ public Value value; public Value commandValue; + public static void main(String[] args) throws IOException { + String key = "hoge"; + ByteBuffer b = ByteBuffer.wrap("messagepack value".getBytes()); + PutAttributeOperation op = new PutAttributeOperation(key, b); + DefaultNodeOperationContainer container = new DefaultNodeOperationContainer(); + container.unconvert(op); + NodeOperation convertedOp = container.convert(); + System.out.println("pos : "+convertedOp.getPosition()); + System.out.println("Command : "+convertedOp.getCommand()); + System.out.println("key : "+convertedOp.getKey()); + System.out.println("value : "+new String(convertedOp.getValue().array())); + + } public DefaultNodeOperationContainer() { @@ -36,21 +48,23 @@ value = null; if (op.getValue() != null) { ByteBuffer b = op.getValue(); - Value v = msgpack.unconvert(b); + byte[] bytes = b.array(); + Value v = msgpack.unconvert(bytes); value = v; } Command c = op.getCommand(); - msgpack.register(c.getClass(), new OrdinalEnumTemplate(c.getClass())); + msgpack.register(Command.class, new OrdinalEnumTemplate(Command.class)); Value cValue = msgpack.unconvert(c); commandValue = cValue; } public NodeOperation convert() throws IOException{ MessagePack msgpack = new MessagePack(); + msgpack.register(Command.class, new OrdinalEnumTemplate(Command.class)); Command c = msgpack.convert(commandValue, Command.class); ByteBuffer b = null; if (value != null) { - b = msgpack.convert(value, ByteBuffer.class); + b = ByteBuffer.wrap(msgpack.convert(value, byte[].class)); } if (c == Command.PUT_ATTRIBUTE) { return new PutAttributeOperation(key, b); @@ -64,5 +78,4 @@ return null; } - }
--- a/src/jungle/test/datasegment/store/operations/DefaultNodePathContainer.java Sun Jun 09 13:53:16 2013 +0900 +++ b/src/jungle/test/datasegment/store/operations/DefaultNodePathContainer.java Mon Jun 10 01:18:45 2013 +0900 @@ -1,13 +1,17 @@ package jungle.test.datasegment.store.operations; import java.io.IOException; -import java.util.Arrays; +import java.util.LinkedList; import java.util.List; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.NodePath; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.DefaultNodePath; import org.msgpack.MessagePack; import org.msgpack.annotation.Message; +import org.msgpack.template.IntegerTemplate; +import org.msgpack.template.ListTemplate; +import org.msgpack.template.ValueTemplate; import org.msgpack.type.Value; @Message @@ -15,24 +19,42 @@ public Value pathValue; + public static void main(String[] args) throws IOException { + DefaultNodePath p = new DefaultNodePath(); + p = p.add(1).add(2).add(3); + DefaultNodePathContainer pathContainer = new DefaultNodePathContainer(); + pathContainer.unconvert(p); + NodePath convertedPath = pathContainer.convert(); + for (int i : convertedPath) { + System.out.println(i); + } + } + public DefaultNodePathContainer() { } public void unconvert(DefaultNodePath path) throws IOException { MessagePack msgpack = new MessagePack(); - List<Integer> list = Arrays.asList(); + List<Integer> list = new LinkedList<Integer>(); for(Integer i : path) { list.add(i); } + /* Remove first Element(-1). */ + list.remove(0); + msgpack.register(List.class, new ListTemplate(IntegerTemplate.getInstance())); Value v = msgpack.unconvert(list); pathValue = v; } public DefaultNodePath convert() throws IOException { MessagePack msgpack = new MessagePack(); - return msgpack.convert(pathValue, DefaultNodePath.class); + msgpack.register(List.class, new ListTemplate(IntegerTemplate.getInstance())); + List<Integer> convertedList = (List<Integer>)msgpack.convert(pathValue, List.class); + DefaultNodePath path = new DefaultNodePath(); + for (int i: convertedList) { + path = path.add(i); + } + return path; } - - }