Package org.robotninjas.barge.log

Examples of org.robotninjas.barge.log.RaftLog


  }

  @Override
  public void init(@Nonnull final RaftStateContext ctx) {

    final RaftLog log = getLog();

    log.currentTerm(log.currentTerm() + 1);
    log.votedFor(Optional.of(log.self()));

    LOGGER.debug("Election starting for term {}", log.currentTerm());

    List<ListenableFuture<RequestVoteResponse>> responses = Lists.newArrayList();
    // Request votes from peers
    for (Replica replica : log.members()) {
      responses.add(sendVoteRequest(ctx, replica));
    }
    // We always vote for ourselves
    responses.add(Futures.immediateFuture(RequestVoteResponse.newBuilder().setVoteGranted(true).build()));
View Full Code Here


  }

  @VisibleForTesting
  ListenableFuture<RequestVoteResponse> sendVoteRequest(RaftStateContext ctx, Replica replica) {

    RaftLog log = getLog();
    RequestVote request =
      RequestVote.newBuilder()
        .setTerm(log.currentTerm())
        .setCandidateId(log.self().toString())
        .setLastLogIndex(log.lastLogIndex())
        .setLastLogTerm(log.lastLogTerm())
        .build();

    ListenableFuture<RequestVoteResponse> response = client.requestVote(replica, request);
    Futures.addCallback(response, checkTerm(ctx));
View Full Code Here

    super(START, log);
  }

  @Override
  public void init(@Nonnull RaftStateContext ctx) {
    RaftLog log = getLog();

    MDC.put("state", Raft.StateType.START.name());
    MDC.put("term", Long.toString(log.currentTerm()));
    MDC.put("self", log.self().toString());
    log.load();
    ctx.setState(this, FOLLOWER);
  }
View Full Code Here

TOP

Related Classes of org.robotninjas.barge.log.RaftLog

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.