Mercurial > hg > Database > jungle-network
comparison src/jungle/test/datasegment/store/operations/DefaultNodeOperationContainer.java @ 3:3770d2be3e73
modified DfaultNodePathContainer
author | one |
---|---|
date | Mon, 10 Jun 2013 01:18:45 +0900 |
parents | 20498c88a70d |
children |
comparison
equal
deleted
inserted
replaced
2:20498c88a70d | 3:3770d2be3e73 |
---|---|
11 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.operations.PutAttributeOperation; | 11 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.operations.PutAttributeOperation; |
12 | 12 |
13 import org.msgpack.MessagePack; | 13 import org.msgpack.MessagePack; |
14 import org.msgpack.annotation.Message; | 14 import org.msgpack.annotation.Message; |
15 import org.msgpack.template.OrdinalEnumTemplate; | 15 import org.msgpack.template.OrdinalEnumTemplate; |
16 import org.msgpack.template.Template; | |
17 import org.msgpack.type.Value; | 16 import org.msgpack.type.Value; |
18 | 17 |
19 @Message | 18 @Message |
20 public class DefaultNodeOperationContainer { | 19 public class DefaultNodeOperationContainer { |
21 | 20 |
22 public int pos; | 21 public int pos; |
23 public String key; | 22 public String key; |
24 public Value value; | 23 public Value value; |
25 public Value commandValue; | 24 public Value commandValue; |
26 | 25 |
26 public static void main(String[] args) throws IOException { | |
27 String key = "hoge"; | |
28 ByteBuffer b = ByteBuffer.wrap("messagepack value".getBytes()); | |
29 PutAttributeOperation op = new PutAttributeOperation(key, b); | |
30 DefaultNodeOperationContainer container = new DefaultNodeOperationContainer(); | |
31 container.unconvert(op); | |
32 NodeOperation convertedOp = container.convert(); | |
33 System.out.println("pos : "+convertedOp.getPosition()); | |
34 System.out.println("Command : "+convertedOp.getCommand()); | |
35 System.out.println("key : "+convertedOp.getKey()); | |
36 System.out.println("value : "+new String(convertedOp.getValue().array())); | |
37 | |
38 } | |
27 | 39 |
28 public DefaultNodeOperationContainer() { | 40 public DefaultNodeOperationContainer() { |
29 | 41 |
30 } | 42 } |
31 | 43 |
34 pos = op.getPosition(); | 46 pos = op.getPosition(); |
35 key = op.getKey(); | 47 key = op.getKey(); |
36 value = null; | 48 value = null; |
37 if (op.getValue() != null) { | 49 if (op.getValue() != null) { |
38 ByteBuffer b = op.getValue(); | 50 ByteBuffer b = op.getValue(); |
39 Value v = msgpack.unconvert(b); | 51 byte[] bytes = b.array(); |
52 Value v = msgpack.unconvert(bytes); | |
40 value = v; | 53 value = v; |
41 } | 54 } |
42 Command c = op.getCommand(); | 55 Command c = op.getCommand(); |
43 msgpack.register(c.getClass(), new OrdinalEnumTemplate(c.getClass())); | 56 msgpack.register(Command.class, new OrdinalEnumTemplate(Command.class)); |
44 Value cValue = msgpack.unconvert(c); | 57 Value cValue = msgpack.unconvert(c); |
45 commandValue = cValue; | 58 commandValue = cValue; |
46 } | 59 } |
47 | 60 |
48 public NodeOperation convert() throws IOException{ | 61 public NodeOperation convert() throws IOException{ |
49 MessagePack msgpack = new MessagePack(); | 62 MessagePack msgpack = new MessagePack(); |
63 msgpack.register(Command.class, new OrdinalEnumTemplate(Command.class)); | |
50 Command c = msgpack.convert(commandValue, Command.class); | 64 Command c = msgpack.convert(commandValue, Command.class); |
51 ByteBuffer b = null; | 65 ByteBuffer b = null; |
52 if (value != null) { | 66 if (value != null) { |
53 b = msgpack.convert(value, ByteBuffer.class); | 67 b = ByteBuffer.wrap(msgpack.convert(value, byte[].class)); |
54 } | 68 } |
55 if (c == Command.PUT_ATTRIBUTE) { | 69 if (c == Command.PUT_ATTRIBUTE) { |
56 return new PutAttributeOperation(key, b); | 70 return new PutAttributeOperation(key, b); |
57 } else if (c == Command.APPEND_CHILD) { | 71 } else if (c == Command.APPEND_CHILD) { |
58 return new AppendChildAtOperation(pos); | 72 return new AppendChildAtOperation(pos); |
62 return new DeleteAttributeOperation(key); | 76 return new DeleteAttributeOperation(key); |
63 } | 77 } |
64 return null; | 78 return null; |
65 } | 79 } |
66 | 80 |
67 | |
68 } | 81 } |