Search in sources :

Example 1 with GossipProtocolImpl

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);
}
Also used : PING_REQ(io.scalecube.cluster.fdetector.FailureDetectorImpl.PING_REQ) Address(io.scalecube.transport.Address) LoggerFactory(org.slf4j.LoggerFactory) SYNC(io.scalecube.cluster.membership.MembershipProtocolImpl.SYNC) CompletableFuture(java.util.concurrent.CompletableFuture) Observable(rx.Observable) ArrayList(java.util.ArrayList) ConcurrentMap(java.util.concurrent.ConcurrentMap) MEMBERSHIP_GOSSIP(io.scalecube.cluster.membership.MembershipProtocolImpl.MEMBERSHIP_GOSSIP) NetworkEmulator(io.scalecube.transport.NetworkEmulator) Map(java.util.Map) PING_ACK(io.scalecube.cluster.fdetector.FailureDetectorImpl.PING_ACK) Transport(io.scalecube.transport.Transport) GOSSIP_REQ(io.scalecube.cluster.gossip.GossipProtocolImpl.GOSSIP_REQ) Message(io.scalecube.transport.Message) Nonnull(javax.annotation.Nonnull) ImmutableSet(com.google.common.collect.ImmutableSet) Logger(org.slf4j.Logger) Collection(java.util.Collection) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) GossipProtocolImpl(io.scalecube.cluster.gossip.GossipProtocolImpl) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) PING(io.scalecube.cluster.fdetector.FailureDetectorImpl.PING) MembershipProtocolImpl(io.scalecube.cluster.membership.MembershipProtocolImpl) MembershipEvent(io.scalecube.cluster.membership.MembershipEvent) Optional(java.util.Optional) SYNC_ACK(io.scalecube.cluster.membership.MembershipProtocolImpl.SYNC_ACK) FailureDetectorImpl(io.scalecube.cluster.fdetector.FailureDetectorImpl) Collections(java.util.Collections) MembershipProtocolImpl(io.scalecube.cluster.membership.MembershipProtocolImpl) MembershipEvent(io.scalecube.cluster.membership.MembershipEvent) GossipProtocolImpl(io.scalecube.cluster.gossip.GossipProtocolImpl) FailureDetectorImpl(io.scalecube.cluster.fdetector.FailureDetectorImpl) Transport(io.scalecube.transport.Transport)

Example 2 with GossipProtocolImpl

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;
}
Also used : GossipProtocolImpl(io.scalecube.cluster.gossip.GossipProtocolImpl) FailureDetectorImpl(io.scalecube.cluster.fdetector.FailureDetectorImpl) UnknownHostException(java.net.UnknownHostException)

Aggregations

FailureDetectorImpl (io.scalecube.cluster.fdetector.FailureDetectorImpl)2 GossipProtocolImpl (io.scalecube.cluster.gossip.GossipProtocolImpl)2 Preconditions.checkNotNull (com.google.common.base.Preconditions.checkNotNull)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 PING (io.scalecube.cluster.fdetector.FailureDetectorImpl.PING)1 PING_ACK (io.scalecube.cluster.fdetector.FailureDetectorImpl.PING_ACK)1 PING_REQ (io.scalecube.cluster.fdetector.FailureDetectorImpl.PING_REQ)1 GOSSIP_REQ (io.scalecube.cluster.gossip.GossipProtocolImpl.GOSSIP_REQ)1 MembershipEvent (io.scalecube.cluster.membership.MembershipEvent)1 MembershipProtocolImpl (io.scalecube.cluster.membership.MembershipProtocolImpl)1 MEMBERSHIP_GOSSIP (io.scalecube.cluster.membership.MembershipProtocolImpl.MEMBERSHIP_GOSSIP)1 SYNC (io.scalecube.cluster.membership.MembershipProtocolImpl.SYNC)1 SYNC_ACK (io.scalecube.cluster.membership.MembershipProtocolImpl.SYNC_ACK)1 Address (io.scalecube.transport.Address)1 Message (io.scalecube.transport.Message)1 NetworkEmulator (io.scalecube.transport.NetworkEmulator)1 Transport (io.scalecube.transport.Transport)1 UnknownHostException (java.net.UnknownHostException)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1