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);
}
}
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;
}
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()));
}
}
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;
}
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;
}
Aggregations