Search in sources :

Example 1 with LogCollectorClient

use of com.qlangtech.tis.rpc.grpc.log.LogCollectorClient 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;
}
Also used : Matcher(java.util.regex.Matcher) InetSocketAddress(java.net.InetSocketAddress) ManagedChannel(io.grpc.ManagedChannel) IncrStatusClient(com.qlangtech.tis.rpc.server.IncrStatusClient) LogCollectorClient(com.qlangtech.tis.rpc.grpc.log.LogCollectorClient) KeeperException(org.apache.zookeeper.KeeperException) IOException(java.io.IOException)

Aggregations

LogCollectorClient (com.qlangtech.tis.rpc.grpc.log.LogCollectorClient)1 IncrStatusClient (com.qlangtech.tis.rpc.server.IncrStatusClient)1 ManagedChannel (io.grpc.ManagedChannel)1 IOException (java.io.IOException)1 InetSocketAddress (java.net.InetSocketAddress)1 Matcher (java.util.regex.Matcher)1 KeeperException (org.apache.zookeeper.KeeperException)1