use of com.qlangtech.tis.rpc.server.IncrStatusClient in project tis by qlangtech.
the class StatusRpcClient method connect2RemoteIncrStatusServer.
private AssembleSvcCompsite connect2RemoteIncrStatusServer(String incrStateCollectAddress, AssembleSvcCompsiteCallback rpcCallback) {
InetSocketAddress address;
Matcher matcher = ADDRESS_PATTERN.matcher(incrStateCollectAddress);
if (matcher.matches()) {
address = new InetSocketAddress(matcher.group(1), Integer.parseInt(matcher.group(2)));
} else {
// setDoReport(false);
throw new IllegalStateException("incrStatusRpcServer:" + incrStateCollectAddress + " is not match the pattern:" + ADDRESS_PATTERN);
}
info("status server address:" + address);
AssembleSvcCompsite oldRpc = rpcCallback.getOld();
try {
if (oldRpc != null) {
// RPC.stopProxy(oldRpc);
oldRpc.close();
}
final ManagedChannel channel = ManagedChannelBuilder.forTarget(incrStateCollectAddress).usePlaintext().build();
IncrStatusClient newRpc = new IncrStatusClient(channel);
LogCollectorClient logCollectorClient = new LogCollectorClient(channel);
// IncrStatusUmbilicalProtocol newRpc = RPC.getProxy(IncrStatusUmbilicalProtocol.class, IncrStatusUmbilicalProtocol.versionID, address, new Configuration());
info("successful connect to " + address + ",pingResult:" + newRpc.ping());
return rpcCallback.process(oldRpc, new AssembleSvcCompsite(newRpc, logCollectorClient) {
@Override
public void close() {
try {
channel.shutdownNow().awaitTermination(2, TimeUnit.MINUTES);
} catch (InterruptedException e) {
logger.error(e.getMessage(), e);
}
}
});
} catch (Exception e) {
error(e.getMessage(), e);
// setDoReport(false);
rpcCallback.errorOccur(oldRpc, e);
}
return null;
}
Aggregations