当前位置: 首页>>代码示例>>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;未经允许,请勿转载。