本文整理匯總了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();
}