Mercurial > hg > Members > nobuyasu > jungle-network
view src/alice/jungle/codesegment/LogUpdateCodeSegment.java @ 43:12d87bb4b84d
modified LogUpdateCodeSegment
author | one |
---|---|
date | Fri, 12 Jul 2013 09:13:54 +0900 |
parents | 4419ac56cbfd |
children | fd3643699f83 |
line wrap: on
line source
package alice.jungle.codesegment; import java.io.IOException; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.JungleTree; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.JungleTreeEditor; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.logger.DefaultTreeOperationLog; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Either; import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Error; import jungle.test.bbs.JungleManager; import alice.codesegment.CodeSegment; import alice.datasegment.CommandType; import alice.datasegment.Receiver; import alice.jungle.datasegment.store.operations.DefaultTreeOperationLogContainer; public class LogUpdateCodeSegment extends CodeSegment { public Receiver arg1 = ids.create(CommandType.PEEK); private final String rh; private final String key; public LogUpdateCodeSegment(String _rh, String _key) { rh = _rh; key = _key; } public void run() { System.out.println("--LogUpdateCodeSegment--"); int index = arg1.index; DefaultTreeOperationLogContainer container = arg1.asClass(DefaultTreeOperationLogContainer.class); if(!updaterIsMe(container)) { LogUpdateCodeSegment updateCS = new LogUpdateCodeSegment(rh, key); updateCS.arg1.setKey(rh, key, index+1); return; } DefaultTreeOperationLog log = null; try { log = container.convert(); } catch (IOException e) { e.printStackTrace(); } //JungleManager jm = new JungleManager(); JungleTree tree = JungleManager.getJungle().getTreeByName("boards"); JungleTreeEditor editor = tree.getTreeEditor(); Either<Error, JungleTreeEditor> either = JungleManager.edit(editor, log); if(either.isA()) { throw new IllegalStateException(); } editor = either.b(); editor.success(); LogUpdateCodeSegment updateCS = new LogUpdateCodeSegment(rh, key); updateCS.arg1.setKey(rh, key, index+1); } private boolean updaterIsMe(DefaultTreeOperationLogContainer container) { return true; } }