本文整理汇总了Java中journal.io.api.JournalBuilder类的典型用法代码示例。如果您正苦于以下问题:Java JournalBuilder类的具体用法?Java JournalBuilder怎么用?Java JournalBuilder使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
JournalBuilder类属于journal.io.api包,在下文中一共展示了JournalBuilder类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createJournal
import journal.io.api.JournalBuilder; //导入依赖的package包/类
private Journal createJournal(final String path) {
try {
log.info("Creating journal event store [path={}]", path);
return JournalBuilder.of(writeableFolder(path)).open();
} catch (final IOException e) {
throw new IllegalStateException("Unable to create event store", e);
}
}
示例2: main
import journal.io.api.JournalBuilder; //导入依赖的package包/类
public static void main(String... args) throws IOException {
Journal journal = JournalBuilder.of(new File(args[0])).open();
long term = 0;
long index = 0;
long committed = 0;
List<String> membership = Collections.emptyList();
Optional<String> lastVotedFor = Optional.absent();
Type lastEntryType = Type.EMPTY;
for (Location loc : journal.redo()) {
byte[] rawEntry = journal.read(loc, Journal.ReadType.ASYNC);
JournalEntry entry = JournalEntry.parseFrom(rawEntry);
if (entry.hasAppend()) {
Append a = entry.getAppend();
index = a.getIndex();
term = a.getEntry().getTerm();
lastEntryType = Type.APPEND;
} else if (entry.hasCommit()) {
Commit c = entry.getCommit();
committed = c.getIndex();
lastEntryType = Type.COMMIT;
} else if (entry.hasMembership()) {
Membership m = entry.getMembership();
membership = m.getMembersList();
lastEntryType = Type.MEMBERSHIP;
} else if (entry.hasSnapshot()) {
Snapshot s = entry.getSnapshot();
index = s.getLastIncludedIndex();
term = s.getLastIncludedTerm();
lastEntryType = Type.SNAPSHOT;
} else if (entry.hasTerm()) {
Term t = entry.getTerm();
term = t.getTerm();
lastEntryType = Type.TERM;
} else if (entry.hasVote()) {
Vote v = entry.getVote();
lastVotedFor = Optional.fromNullable(v.getVotedFor());
lastEntryType = Type.VOTE;
System.out.println("Vote: " + lastVotedFor.orNull());
}
System.out.println(lastEntryType.toString() + " " + "term: " + term + ", index: " + index + ", committed: " + committed);
}
journal.close();
}