protected InstallRequest buildInstallRequest(RaftMemberContext member, Snapshot snapshot) {
    if (member.getNextSnapshotIndex() != snapshot.index()) {
      member.setNextSnapshotIndex(snapshot.index());
      member.setNextSnapshotOffset(0);
    }

    InstallRequest request;
    synchronized (snapshot) {
      // Open a new snapshot reader.
      try (SnapshotReader reader = snapshot.openReader()) {
        // Skip to the next batch of bytes according to the snapshot chunk size and current offset.
        reader.skip(member.getNextSnapshotOffset() * MAX_BATCH_SIZE);
        byte[] data = new byte[Math.min(MAX_BATCH_SIZE, reader.remaining())];
        reader.read(data);

        // Create the install request, indicating whether this is the last chunk of data based on the number
        // of bytes remaining in the buffer.
        DefaultRaftMember leader = raft.getLeader();
        request = InstallRequest.builder()
            .withTerm(raft.getTerm())
            .withLeader(leader != null ? leader.memberId() : null)
            .withIndex(snapshot.index())
            .withTimestamp(snapshot.timestamp().unixTimestamp())
            .withVersion(snapshot.version())
            .withOffset(member.getNextSnapshotOffset())
            .withData(data)
            .withComplete(!reader.hasRemaining())
            .build();
      }
    }

    return request;
  }
protected InstallRequest buildInstallRequest ( RaftMemberContext member , Snapshot snapshot ) { if ( member . getNextSnapshotIndex ( ) != snapshot . index ( ) ) { member . setNextSnapshotIndex ( snapshot . index ( ) ) ; member . setNextSnapshotOffset ( 0 ) ; } InstallRequest request ; synchronized ( snapshot ) { try ( SnapshotReader reader = snapshot . openReader ( ) ) { reader . skip ( member . getNextSnapshotOffset ( ) * MAX_BATCH_SIZE ) ; byte [ ] data = new byte [ Math . min ( MAX_BATCH_SIZE , reader . remaining ( ) ) ] ; reader . read ( data ) ; DefaultRaftMember leader = raft . getLeader ( ) ; request = InstallRequest . builder ( ) . withTerm ( raft . getTerm ( ) ) . withLeader ( leader != null ? leader . memberId ( ) : null ) . withIndex ( snapshot . index ( ) ) . withTimestamp ( snapshot . timestamp ( ) . unixTimestamp ( ) ) . withVersion ( snapshot . version ( ) ) . withOffset ( member . getNextSnapshotOffset ( ) ) . withData ( data ) . withComplete ( ! reader . hasRemaining ( ) ) . build ( ) ; } } return request ; }
Builds an install request for the given member.