Search in sources :

Example 76 with Endpoint

use of com.alipay.sofa.jraft.util.Endpoint in project sofa-jraft by sofastack.

the class ConnectionRefreshTest method simulation.

@Ignore
@Test
public void simulation() throws InterruptedException {
    ProtobufMsgFactory.load();
    final RpcServer server = RpcFactoryHelper.rpcFactory().createRpcServer(new Endpoint("127.0.0.1", 19991));
    server.registerProcessor(new PingRequestProcessor());
    server.init(null);
    final Endpoint target = new Endpoint("my.test.host1.com", 19991);
    final RpcClient client = RpcFactoryHelper.rpcFactory().createRpcClient();
    client.init(null);
    final RpcRequests.PingRequest req = // 
    RpcRequests.PingRequest.newBuilder().setSendTimestamp(// 
    System.currentTimeMillis()).build();
    for (int i = 0; i < 1000; i++) {
        try {
            final Object resp = client.invokeSync(target, req, 3000);
            System.out.println(resp);
        } catch (final Exception e) {
            e.printStackTrace();
        }
        Thread.sleep(1000);
    }
}
Also used : Endpoint(com.alipay.sofa.jraft.util.Endpoint) PingRequestProcessor(com.alipay.sofa.jraft.rpc.impl.PingRequestProcessor) Endpoint(com.alipay.sofa.jraft.util.Endpoint) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 77 with Endpoint

use of com.alipay.sofa.jraft.util.Endpoint in project sofa-jraft by sofastack.

the class TestUtils method generatePriorityPeers.

public static List<PeerId> generatePriorityPeers(final int n, List<Integer> priorities) {
    List<PeerId> ret = new ArrayList<>();
    for (int i = 0; i < n; i++) {
        Endpoint endpoint = new Endpoint(getMyIp(), INIT_PORT + i);
        PeerId peerId = new PeerId(endpoint, 0, priorities.get(i));
        ret.add(peerId);
    }
    return ret;
}
Also used : Endpoint(com.alipay.sofa.jraft.util.Endpoint) ArrayList(java.util.ArrayList) Endpoint(com.alipay.sofa.jraft.util.Endpoint) PeerId(com.alipay.sofa.jraft.entity.PeerId)

Example 78 with Endpoint

use of com.alipay.sofa.jraft.util.Endpoint in project mmqtt by MrHKing.

the class JRaftServer method invokeToLeader.

private void invokeToLeader(final String group, final Message request, final int timeoutMillis, FailoverClosure closure) {
    try {
        final Endpoint leaderIp = Optional.ofNullable(getLeader(group)).orElseThrow(() -> new NoLeaderException(group)).getEndpoint();
        cliClientService.getRpcClient().invokeAsync(leaderIp, request, new InvokeCallback() {

            @Override
            public void complete(Object o, Throwable ex) {
                if (Objects.nonNull(ex)) {
                    closure.setThrowable(ex);
                    closure.run(new Status(RaftError.UNKNOWN, ex.getMessage()));
                    return;
                }
                closure.setResponse((Response) o);
                closure.run(Status.OK());
            }

            @Override
            public Executor executor() {
                return RaftExecutor.getRaftCliServiceExecutor();
            }
        }, timeoutMillis);
    } catch (Exception e) {
        closure.setThrowable(e);
        closure.run(new Status(RaftError.UNKNOWN, e.toString()));
    }
}
Also used : Response(org.monkey.mmq.core.entity.Response) InvokeCallback(com.alipay.sofa.jraft.rpc.InvokeCallback) Executor(java.util.concurrent.Executor) Endpoint(com.alipay.sofa.jraft.util.Endpoint)

Example 79 with Endpoint

use of com.alipay.sofa.jraft.util.Endpoint in project jdchain-core by blockchain-jd-com.

the class ParticipantManagerService4Raft method waitConsensusNodeStarted.

private boolean waitConsensusNodeStarted(ParticipantContext context, NetworkAddress changeConsensusNodeAddress) {
    CliClientServiceImpl rpcClient = createRpcClient(context);
    Endpoint changeNode = new Endpoint(changeConsensusNodeAddress.getHost(), changeConsensusNodeAddress.getPort());
    int i = 0;
    while (i <= MAX_RETRY_TIMES) {
        i++;
        try {
            Thread.sleep(SLEEP_MS);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        if (rpcClient.connect(changeNode)) {
            return true;
        }
    }
    return false;
}
Also used : Endpoint(com.alipay.sofa.jraft.util.Endpoint) CliClientServiceImpl(com.alipay.sofa.jraft.rpc.impl.cli.CliClientServiceImpl) Endpoint(com.alipay.sofa.jraft.util.Endpoint)

Example 80 with Endpoint

use of com.alipay.sofa.jraft.util.Endpoint in project jdchain-core by blockchain-jd-com.

the class ParticipantManagerService4Raft method invoke.

private RpcResponse invoke(ParticipantContext context, Endpoint endpoint, Object request) {
    RpcResponse response = null;
    try {
        RpcClient client = createRpcClient(context).getRpcClient();
        int timeoutMs = (int) context.getProperty(RPC_QUEST_TIMEOUT_MS);
        response = (RpcResponse) client.invokeSync(endpoint, request, timeoutMs);
    } catch (Exception e) {
        LOGGER.error(e.getMessage(), e);
        response = RpcResponse.fail(-1, e.getMessage());
    }
    return response;
}
Also used : Endpoint(com.alipay.sofa.jraft.util.Endpoint) RpcClient(com.alipay.sofa.jraft.rpc.RpcClient)

Aggregations

Endpoint (com.alipay.sofa.jraft.util.Endpoint)80 Test (org.junit.Test)34 PeerId (com.alipay.sofa.jraft.entity.PeerId)28 Node (com.alipay.sofa.jraft.Node)23 NodeOptions (com.alipay.sofa.jraft.option.NodeOptions)18 Configuration (com.alipay.sofa.jraft.conf.Configuration)12 CountDownLatch (java.util.concurrent.CountDownLatch)11 Status (com.alipay.sofa.jraft.Status)8 File (java.io.File)7 ByteBuffer (java.nio.ByteBuffer)7 RaftOptions (com.alipay.sofa.jraft.option.RaftOptions)6 Region (com.alipay.sofa.jraft.rhea.metadata.Region)6 PlacementDriverClient (com.alipay.sofa.jraft.rhea.client.pd.PlacementDriverClient)5 RheaKVStoreOptions (com.alipay.sofa.jraft.rhea.options.RheaKVStoreOptions)5 RpcResponseClosure (com.alipay.sofa.jraft.rpc.RpcResponseClosure)5 RpcServer (com.alipay.sofa.jraft.rpc.RpcServer)5 FutureImpl (com.alipay.sofa.jraft.rpc.impl.FutureImpl)5 SnapshotReader (com.alipay.sofa.jraft.storage.snapshot.SnapshotReader)5 Message (com.google.protobuf.Message)5 RaftGroupService (com.alipay.sofa.jraft.RaftGroupService)4