comparison src/main/java/app/bbs/BulletinBoardJungleManager.java @ 148:7d248be1d3e4

Modified renewTime
author Nobuyasu
date Tue, 28 Jan 2014 10:53:01 +0900
parents 202ea963ec20
children 06cddf529325
comparison
equal deleted inserted replaced
147:202ea963ec20 148:7d248be1d3e4
63 } 63 }
64 } 64 }
65 Either<Error, JungleTreeEditor> either = null; 65 Either<Error, JungleTreeEditor> either = null;
66 JungleTree tree = jungle.getTreeByName(treeName); 66 JungleTree tree = jungle.getTreeByName(treeName);
67 67
68 long timestamp = new Date().getTime();
69 ByteBuffer tBuffer = ByteBuffer.allocate(16);
70 DefaultNodePath root = new DefaultNodePath();
71 tBuffer.putLong(timestamp);
68 do { 72 do {
69 JungleTreeEditor editor = tree.getLocalTreeEditor(); 73 JungleTreeEditor editor = tree.getLocalTreeEditor();
70 /* 74 /*
71 * Merge. 75 * Merge.
72 */ 76 */
73 int pos = calculatePosition(tree.getRootNode(), netLog.getTimeStamp()); 77 int pos = calculatePosition(tree.getRootNode(), netLog.getTimeStamp());
74 either = JungleUpdater.edit(editor, netLog, pos); 78 either = JungleUpdater.edit(editor, netLog, pos);
75 if(either.isA()) { 79 if(either.isA()) {
76 throw new IllegalStateException(); 80 throw new IllegalStateException();
77 } 81 }
78
79 editor = either.b(); 82 editor = either.b();
80 either = editor.success();
81 }while(either.isA());
82
83 renewBoardTimeStamp(tree);
84 requestCounter.incrementAndGet();
85 return either;
86 }
87
88 private static void renewBoardTimeStamp(JungleTree tree) {
89 JungleTreeEditor editor = tree.getLocalTreeEditor();
90 DefaultNodePath root = new DefaultNodePath();
91 long timestamp = new Date().getTime();
92 ByteBuffer tBuffer = ByteBuffer.allocate(16);
93 tBuffer.putLong(timestamp);
94
95 Either<Error, JungleTreeEditor> either = null;
96 do {
97 either = editor.putAttribute(root, "renewtime", tBuffer); 83 either = editor.putAttribute(root, "renewtime", tBuffer);
98 if(either.isA()) { 84 if(either.isA()) {
99 throw new IllegalStateException(); 85 throw new IllegalStateException();
100 } 86 }
101 editor = either.b(); 87 editor = either.b();
102 either = editor.success(); 88 either = editor.success();
103 }while(either.isA()); 89 }while(either.isA());
90 requestIncrementAndGet();
91 return either;
104 } 92 }
105 93
106 private static int calculatePosition(Node node, long newNodeTimeStamp) { 94 private static int calculatePosition(Node node, long newNodeTimeStamp) {
107 int count = 0; 95 int count = 0;
108 long childTimeStamp = 0; 96 long childTimeStamp = 0;