use of io.scalecube.cluster.membership.MembershipEvent 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);
}
Aggregations