當前位置: 首頁>>代碼示例>>Java>>正文


Java JournalBuilder類代碼示例

本文整理匯總了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);
    }
}
 
開發者ID:wassgren,項目名稱:NoMQ,代碼行數:9,代碼來源:JournalEventStore.java

示例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();

  }
 
開發者ID:mgodave,項目名稱:barge,代碼行數:65,代碼來源:LogTool.java


注:本文中的journal.io.api.JournalBuilder類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。