Mercurial > hg > Members > nobuyasu > jungle-network
comparison src/main/java/alice/jungle/datasegment/container/DefaultTreeOperationLogContainer.java @ 105:f9e29a52efd3
Move some files
author | one |
---|---|
date | Tue, 26 Nov 2013 06:43:10 +0900 |
parents | src/alice/jungle/datasegment/store/container/DefaultTreeOperationLogContainer.java@2c7b3f2b2ee1 |
children |
comparison
equal
deleted
inserted
replaced
104:03bf62bb699e | 105:f9e29a52efd3 |
---|---|
1 package alice.jungle.datasegment.container; | |
2 | |
3 import java.io.IOException; | |
4 import java.util.LinkedList; | |
5 import java.util.List; | |
6 | |
7 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.NodePath; | |
8 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.logger.DefaultTreeOperationLog; | |
9 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.operations.DefaultTreeOperation; | |
10 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.operations.NodeOperation; | |
11 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.operations.TreeOperation; | |
12 | |
13 import org.msgpack.MessagePack; | |
14 import org.msgpack.annotation.Message; | |
15 import org.msgpack.template.ListTemplate; | |
16 import org.msgpack.template.ValueTemplate; | |
17 import org.msgpack.type.Value; | |
18 | |
19 import alice.codesegment.SingletonMessage; | |
20 | |
21 @Message | |
22 public class DefaultTreeOperationLogContainer { | |
23 | |
24 Value logValue; | |
25 String treeName; | |
26 String uuid; | |
27 String updaterName; | |
28 String revision; | |
29 long timestamp; | |
30 | |
31 public DefaultTreeOperationLogContainer() { | |
32 logValue = null; | |
33 treeName = ""; | |
34 uuid = ""; | |
35 updaterName = ""; | |
36 revision = ""; | |
37 timestamp = Long.MAX_VALUE; | |
38 } | |
39 | |
40 public void setTreeName(String _treeName) { | |
41 treeName = _treeName; | |
42 } | |
43 | |
44 public String getTreeName() { | |
45 return treeName; | |
46 } | |
47 | |
48 public void setUUID(String _uuid) { | |
49 uuid = _uuid; | |
50 } | |
51 | |
52 public String getUUID() { | |
53 return uuid; | |
54 } | |
55 | |
56 public void setUpdaterName(String _updaterName) { | |
57 updaterName = _updaterName; | |
58 } | |
59 | |
60 public String getServerName() { | |
61 return updaterName; | |
62 } | |
63 | |
64 public void setRevision(String _revision) { | |
65 revision = _revision; | |
66 } | |
67 | |
68 public String getRevision() { | |
69 return revision; | |
70 } | |
71 | |
72 public void setTimeStamp(long t) { | |
73 timestamp = t; | |
74 } | |
75 | |
76 public long getTimeStamp() { | |
77 return timestamp; | |
78 } | |
79 | |
80 public void unconvert(Iterable<TreeOperation> _log) throws IOException { | |
81 MessagePack msgpack = SingletonMessage.getInstance(); | |
82 List<Value> list = new LinkedList<Value>(); | |
83 for(TreeOperation op : _log) { | |
84 NodeOperation nOp = op.getNodeOperation(); | |
85 NodePath nodePath = op.getNodePath(); | |
86 DefaultTreeOperation treeOp = new DefaultTreeOperation(nodePath, nOp); | |
87 DefaultTreeOperationContainer container = new DefaultTreeOperationContainer(); | |
88 container.unconvert(treeOp); | |
89 Value v = msgpack.unconvert(container); | |
90 list.add(v); | |
91 } | |
92 Value listValue = msgpack.unconvert(list); | |
93 logValue = listValue; | |
94 } | |
95 | |
96 public DefaultTreeOperationLog convert() throws IOException { | |
97 MessagePack msgpack = SingletonMessage.getInstance(); | |
98 msgpack.register(List.class, new ListTemplate(ValueTemplate.getInstance())); | |
99 List<Value> listValue = msgpack.convert(logValue, List.class); | |
100 List<TreeOperation> logList = new LinkedList<TreeOperation>(); | |
101 for(Value v: listValue) { | |
102 DefaultTreeOperationContainer container = msgpack.convert(v, DefaultTreeOperationContainer.class); | |
103 logList.add(container.convert()); | |
104 } | |
105 DefaultTreeOperationLog log = new DefaultTreeOperationLog(logList, logList.size()); | |
106 return log; | |
107 } | |
108 | |
109 public String getHashLogString() { | |
110 return treeName + revision + updaterName; | |
111 } | |
112 | |
113 | |
114 } |