Created
March 2, 2018 22:25
-
-
Save johnou/4270a1110f14a7f0f09d9a6b99b4312f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import io.atomix.cluster.Node; | |
import io.atomix.core.Atomix; | |
import io.atomix.messaging.Endpoint; | |
import org.apache.logging.log4j.LogManager; | |
import org.apache.logging.log4j.Logger; | |
import java.io.File; | |
import java.util.concurrent.CompletableFuture; | |
public class Bootstrap3 { | |
private static final Logger logger = LogManager.getLogger(Bootstrap3.class); | |
public static void main(String[] args) throws InterruptedException { | |
Node[] bootstrapNodes = new Node[] {Node.builder("server1") | |
.withType(Node.Type.DATA) | |
.withEndpoint(Endpoint.from("127.0.0.1", 5001)) | |
.build(), | |
}; | |
Atomix atomix1 = createAtomicNode("server1", 5001, bootstrapNodes); | |
CompletableFuture.allOf(atomix1.start()).whenCompleteAsync((aVoid, throwable) -> { | |
}).join(); | |
Atomix atomix2 = createAtomicNode("server2", 5002, bootstrapNodes); | |
CompletableFuture.allOf(atomix2.start()).whenCompleteAsync((aVoid, throwable) -> { | |
}).join(); | |
CompletableFuture.allOf(atomix2.stop()).whenCompleteAsync((aVoid, throwable) -> { | |
}).join(); | |
CompletableFuture.allOf(atomix1.stop()).whenCompleteAsync((aVoid, throwable) -> { | |
}).join(); | |
Atomix atomix3 = createAtomicNode("server1", 5001, bootstrapNodes); | |
CompletableFuture.allOf(atomix3.start()).whenCompleteAsync((aVoid, throwable) -> { | |
// fails with | |
/* | |
2018-03-02T23:23:54,851 WARN [raft-server-core-partition-1] (io.atomix.protocols.raft.roles.FollowerRole) RaftServer{core-partition-1}{role=FOLLOWER} - Unknown nodeId: server2 [] | |
2018-03-02T23:24:02,029 WARN [raft-server-core-partition-1] (io.atomix.protocols.raft.roles.FollowerRole) RaftServer{core-partition-1}{role=FOLLOWER} - Unknown nodeId: server2 [] | |
2018-03-02T23:24:07,491 WARN [raft-server-core-partition-1] (io.atomix.protocols.raft.roles.FollowerRole) RaftServer{core-partition-1}{role=FOLLOWER} - Unknown nodeId: server2 [] | |
2018-03-02T23:24:14,720 WARN [raft-server-core-partition-1] (io.atomix.protocols.raft.roles.FollowerRole) RaftServer{core-partition-1}{role=FOLLOWER} - Unknown nodeId: server2 [] | |
2018-03-02T23:24:20,865 WARN [raft-server-core-partition-1] (io.atomix.protocols.raft.roles.FollowerRole) RaftServer{core-partition-1}{role=FOLLOWER} - Unknown nodeId: server2 [] | |
2018-03-02T23:24:26,571 WARN [raft-server-core-partition-1] (io.atomix.protocols.raft.roles.FollowerRole) RaftServer{core-partition-1}{role=FOLLOWER} - Unknown nodeId: server2 [] | |
2018-03-02T23:24:32,768 WARN [raft-server-core-partition-1] (io.atomix.protocols.raft.roles.FollowerRole) RaftServer{core-partition-1}{role=FOLLOWER} - Unknown nodeId: server2 [] | |
*/ | |
}).join(); | |
CompletableFuture.allOf(atomix3.stop()).whenCompleteAsync((aVoid, throwable) -> { | |
}).join(); | |
} | |
private static Atomix createAtomicNode(String nodeId, int port, Node[] bootstrapNodes) { | |
Atomix.Builder builder = Atomix.builder(); | |
builder.withLocalNode(Node.builder(nodeId) | |
.withType(Node.Type.DATA) | |
.withEndpoint(Endpoint.from("127.0.0.1", port)) | |
.build()); | |
return builder.withDataDirectory(new File(System.getProperty("user.dir"), "data/" + nodeId)).withBootstrapNodes(bootstrapNodes).build(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment