eventLoopGroup = Optional.empty();
14 |
15 | public RaftProtoRpcModule(NettyReplica localEndpoint) {
16 | this.localEndpoint = localEndpoint;
17 | }
18 |
19 | @Override
20 | protected void configure() {
21 | final NioEventLoopGroup eventLoop = initializeEventLoop();
22 |
23 | install(new RpcModule(localEndpoint.address(), eventLoop));
24 |
25 | expose(RpcServer.class);
26 | expose(RaftClientProvider.class);
27 | }
28 |
29 | private NioEventLoopGroup initializeEventLoop() {
30 | final NioEventLoopGroup eventLoop;
31 |
32 | if (eventLoopGroup.isPresent()) {
33 | eventLoop = eventLoopGroup.get();
34 | } else {
35 | eventLoop = new NioEventLoopGroup(1);
36 | Runtime.getRuntime().addShutdownHook(
37 | new Thread(eventLoop::shutdownGracefully)
38 | );
39 | }
40 | return eventLoop;
41 | }
42 |
43 | }
44 |
--------------------------------------------------------------------------------
/barge-rpc-proto/src/main/java/org/robotninjas/barge/RaftService.java:
--------------------------------------------------------------------------------
1 | package org.robotninjas.barge;
2 |
3 | import java.util.concurrent.CompletableFuture;
4 |
5 | /**
6 | * An instance of a set of replica managed through Raft protocol.
7 | *
8 | * A {@link RaftService} instance is constructed by specific builders depending on: Communication protocol used,
9 | * persistent storage, network characteristics...
10 | *
11 | */
12 | public interface RaftService {
13 |
14 | /**
15 | * Asynchronously executes an operation on the state machine managed by barge.
16 | *
17 | * When the result becomes available, the operation is guaranteed to have been committed to the Raft
18 | * cluster in such a way that it is permanent and will be seen, eventually, by all present and
19 | * future members of the cluster.
20 | *
21 | *
22 | * @param operation an arbitrary operation to be sent to the state machine managed by Raft.
23 | * @return the result of executing the operation, wrapped in a {@link CompletableFuture}, that can be retrieved
24 | * at a later point in time.
25 | * @throws org.robotninjas.barge.RaftException
26 | */
27 | CompletableFuture