Skip to content

Instantly share code, notes, and snippets.

@mgodave
Last active December 31, 2015 01:29
Show Gist options
  • Save mgodave/7914212 to your computer and use it in GitHub Desktop.
Save mgodave/7914212 to your computer and use it in GitHub Desktop.
public class Test implements StateMachine {
@Override
public void applyOperation(@Nonnull ByteBuffer entry) {
System.out.println(entry.getLong());
}
public static void main(String... args) throws Exception {
ClusterConfig config = ClusterConfig.from(
Replica.fromString("localhost:10000"), // local
Replica.fromString("localhost:10001"), // remote
Replica.fromString("localhost:10002") // remote
);
File logDir = new File(args[0]);
logDir.mkdir();
RaftService raft =
RaftService.newBuilder(config)
.logDir(logDir)
.timeout(300)
.build(new Test());
raft.startAsync().awaitRunning();
for (int i = 0; i < 10; i++) {
raft.commit(new byte[] {'O', '_', 'o'}).get();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment