85
|
1 package alice.jungle.persistence;
|
|
2
|
|
3 import java.io.IOException;
|
|
4 import java.io.OutputStream;
|
|
5
|
|
6 import org.msgpack.MessagePack;
|
|
7
|
|
8 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.persistent.ChangeList;
|
|
9 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.persistent.ChangeListWriter;
|
|
10 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.persistent.Result;
|
|
11 import alice.jungle.operations.NetworkTreeOperationLog;
|
|
12
|
|
13 public class PersistentChangeListWriter implements ChangeListWriter {
|
|
14
|
|
15 MessagePack msgpack = NetworkJournal.getMessagePack();
|
|
16 OutputStream out;
|
|
17
|
|
18 public PersistentChangeListWriter(OutputStream _out) {
|
|
19 out = _out;
|
|
20 }
|
|
21
|
|
22 @Override
|
|
23 public Result write(ChangeList _operations)
|
|
24 {
|
|
25 NetworkTreeOperationLog log = new NetworkTreeOperationLog(_operations);
|
|
26 try {
|
|
27 msgpack.write(out, log);
|
|
28 out.flush();
|
|
29 } catch (IOException e) {
|
|
30 return null;
|
|
31 }
|
|
32 return Result.SUCCESS;
|
|
33 }
|
|
34
|
|
35 public Result write(PersistentChangeSet cs)
|
|
36 {
|
86
|
37 NetworkTreeOperationLog log = new NetworkTreeOperationLog(cs.uuid(), cs.getTreeName(),cs.getChangeList());
|
85
|
38 try {
|
|
39 msgpack.write(out, log);
|
|
40 out.flush();
|
|
41 } catch (IOException e) {
|
|
42 return null;
|
|
43 }
|
|
44 return Result.SUCCESS;
|
|
45 }
|
|
46
|
|
47 }
|