comparison src/jungle/test/codesegment/practice/StartCodeSegment.java @ 9:49c0eaa4dce2

add StartCodeSegment.java
author one
date Tue, 11 Jun 2013 14:09:42 +0900
parents 20498c88a70d
children 5376ac62ac08
comparison
equal deleted inserted replaced
8:ee93e16d5a3f 9:49c0eaa4dce2
1 package jungle.test.codesegment.practice; 1 package jungle.test.codesegment.practice;
2 2
3 import java.io.IOException;
4 import java.nio.ByteBuffer;
5 import java.util.LinkedList;
6 import java.util.List;
7
8 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.DefaultNodePath;
9 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.logger.DefaultTreeOperationLog;
10 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.operations.AppendChildAtOperation;
11 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.operations.DefaultTreeOperation;
12 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.operations.DeleteAttributeOperation;
13 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.operations.DeleteChildAtOperation;
14 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.operations.PutAttributeOperation;
15 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.operations.TreeOperation;
16 import jungle.test.datasegment.store.operations.DefaultTreeOperationLogContainer;
3 import alice.codesegment.CodeSegment; 17 import alice.codesegment.CodeSegment;
4 18
5 public class StartCodeSegment extends CodeSegment { 19 public class StartCodeSegment extends CodeSegment {
6 20
7 @Override 21 @Override
8 public void run() { 22 public void run() {
9 System.out.println("run StartCodeSegment"); 23 System.out.println("run StartCodeSegment");
10 24
11 TestCodeSegment cs = new TestCodeSegment(); 25 TestCodeSegment cs = new TestCodeSegment();
12 cs.arg1.setKey("key1"); // unbound datasegment key1 is created and connect to cs. 26 cs.arg1.setKey("log");
13 // cs is waiting for local.key1
14 System.out.println("create TestCodeSegment"); 27 System.out.println("create TestCodeSegment");
28
29 String key = "hoge";
30 ByteBuffer b = ByteBuffer.wrap("messagepack value".getBytes());
31 DefaultNodePath nodePath1 = new DefaultNodePath();
32 nodePath1 = nodePath1.add(1);
33 DefaultNodePath nodePath2 = nodePath1.add(2);
34 AppendChildAtOperation appendChildOp = new AppendChildAtOperation(1);
35 PutAttributeOperation putOp = new PutAttributeOperation(key, b);
36 DeleteAttributeOperation deleteOp = new DeleteAttributeOperation("hoge");
37 DeleteChildAtOperation deleteChild = new DeleteChildAtOperation(2);
38 List<TreeOperation> list = new LinkedList<TreeOperation>();
39 list.add(new DefaultTreeOperation(nodePath1, appendChildOp));
40 list.add(new DefaultTreeOperation(nodePath2, appendChildOp));
41 list.add(new DefaultTreeOperation(nodePath2, putOp));
42 list.add(new DefaultTreeOperation(nodePath2, deleteOp));
43 list.add(new DefaultTreeOperation(nodePath1, deleteChild));
44 DefaultTreeOperationLog log = new DefaultTreeOperationLog(list, list.size());
15 45
16 ods.update("local", "key1", "String data"); // bind string data to datasegment local.key1 46 DefaultTreeOperationLogContainer logContainer = new DefaultTreeOperationLogContainer();
17 // this startup TestCodeSegment. 47 try {
48 logContainer.unconvert(log);
49 ods.update("local", "log", logContainer);
50 } catch (IOException e) {
51 e.printStackTrace();
52 }
18 } 53 }
19 54
20 } 55 }