Search in sources :

Example 1 with RaftClientService

use of com.alipay.sofa.jraft.rpc.RaftClientService in project sofa-jraft by sofastack.

the class ReplicatorGroupImpl method addReplicator.

@Override
public boolean addReplicator(final PeerId peer, final ReplicatorType replicatorType, final boolean sync) {
    Requires.requireTrue(this.commonOptions.getTerm() != 0);
    this.failureReplicators.remove(peer);
    if (this.replicatorMap.containsKey(peer)) {
        return true;
    }
    final ReplicatorOptions opts = this.commonOptions == null ? new ReplicatorOptions() : this.commonOptions.copy();
    opts.setReplicatorType(replicatorType);
    opts.setPeerId(peer);
    if (!sync) {
        final RaftClientService client = opts.getRaftRpcService();
        if (client != null && !client.checkConnection(peer.getEndpoint(), true)) {
            LOG.error("Fail to check replicator connection to peer={}, replicatorType={}.", peer, replicatorType);
            this.failureReplicators.put(peer, replicatorType);
            return false;
        }
    }
    final ThreadId rid = Replicator.start(opts, this.raftOptions);
    if (rid == null) {
        LOG.error("Fail to start replicator to peer={}, replicatorType={}.", peer, replicatorType);
        this.failureReplicators.put(peer, replicatorType);
        return false;
    }
    return this.replicatorMap.put(peer, rid) == null;
}
Also used : RaftClientService(com.alipay.sofa.jraft.rpc.RaftClientService) ThreadId(com.alipay.sofa.jraft.util.ThreadId) ReplicatorOptions(com.alipay.sofa.jraft.option.ReplicatorOptions)

Aggregations

ReplicatorOptions (com.alipay.sofa.jraft.option.ReplicatorOptions)1 RaftClientService (com.alipay.sofa.jraft.rpc.RaftClientService)1 ThreadId (com.alipay.sofa.jraft.util.ThreadId)1