use of io.scalecube.cluster.gossip.GossipProtocolImpl in project scalecube by scalecube.
the class ClusterImpl method join0.
public CompletableFuture<Cluster> join0() {
CompletableFuture<Transport> transportFuture = Transport.bind(config.getTransportConfig());
CompletableFuture<Void> clusterFuture = transportFuture.thenCompose(boundTransport -> {
transport = boundTransport;
messageObservable = transport.listen().filter(// filter out system gossips
msg -> !SYSTEM_MESSAGES.contains(msg.qualifier()));
membership = new MembershipProtocolImpl(transport, config);
gossip = new GossipProtocolImpl(transport, membership, config);
failureDetector = new FailureDetectorImpl(transport, membership, config);
membership.setFailureDetector(failureDetector);
membership.setGossipProtocol(gossip);
Member localMember = membership.member();
onMemberAdded(localMember);
membership.listen().filter(MembershipEvent::isAdded).map(MembershipEvent::member).subscribe(this::onMemberAdded, this::onError);
membership.listen().filter(MembershipEvent::isRemoved).map(MembershipEvent::member).subscribe(this::onMemberRemoved, this::onError);
membership.listen().filter(MembershipEvent::isUpdated).map(MembershipEvent::member).subscribe(this::onMemberUpdated, this::onError);
failureDetector.start();
gossip.start();
gossipObservable = gossip.listen().filter(// filter out system gossips
msg -> !SYSTEM_GOSSIPS.contains(msg.qualifier()));
return membership.start();
});
return clusterFuture.thenApply(aVoid -> ClusterImpl.this);
}
use of io.scalecube.cluster.gossip.GossipProtocolImpl in project scalecube by scalecube.
the class MembershipProtocolTest method createMembership.
private MembershipProtocolImpl createMembership(Transport transport, ClusterConfig config) {
// Create components
MembershipProtocolImpl membership = new MembershipProtocolImpl(transport, config);
FailureDetectorImpl failureDetector = new FailureDetectorImpl(transport, membership, config);
GossipProtocolImpl gossipProtocol = new GossipProtocolImpl(transport, membership, config);
membership.setGossipProtocol(gossipProtocol);
membership.setFailureDetector(failureDetector);
try {
failureDetector.start();
gossipProtocol.start();
membership.start().get();
} catch (Exception ex) {
Throwables.propagate(ex);
}
return membership;
}
Aggregations