/** * Intentionally make this method package-private, avoiding user directly * new an instance through this constructor. * * @param rpcConnectionKey RpcConnectionKey * @param eventLoopGroup Thread pool of netty's * @param rpcParams Rpc connection parameters (see RpcConstants) * * @throws ClassNotFoundException * @throws NoSuchMethodException */ AsyncRpcClient(EventLoopGroup eventLoopGroup, RpcConnectionKey rpcConnectionKey, Properties rpcParams) throws ClassNotFoundException, NoSuchMethodException { super(rpcConnectionKey, rpcParams); this.stubMethod = getServiceClass().getMethod("newStub", RpcChannel.class); this.rpcChannel = new ProxyRpcChannel(); this.handler = new ClientChannelInboundHandler(); final long socketTimeoutMills = Long.parseLong( rpcParams.getProperty(CLIENT_SOCKET_TIMEOUT, String.valueOf(CLIENT_SOCKET_TIMEOUT_DEFAULT))); // Enable proactive hang detection final boolean hangDetectionEnabled = Boolean.parseBoolean( rpcParams.getProperty(CLIENT_HANG_DETECTION, String.valueOf(CLIENT_HANG_DETECTION_DEFAULT))); init(new ProtoClientChannelInitializer(handler, RpcResponse.getDefaultInstance(), socketTimeoutMills, hangDetectionEnabled), eventLoopGroup); }
@Override public void operationComplete(ChannelFuture future) throws Exception { if (!future.isSuccess()) { inboundHandler.exceptionCaught(null, new ServiceException(future.cause())); } } });
/** * Intentionally make this method package-private, avoiding user directly * new an instance through this constructor. * * @param rpcConnectionKey RpcConnectionKey * @param eventLoopGroup Thread pool of netty's * @param rpcParams Rpc connection parameters (see RpcConstants) * * @throws ClassNotFoundException * @throws NoSuchMethodException */ AsyncRpcClient(EventLoopGroup eventLoopGroup, RpcConnectionKey rpcConnectionKey, Properties rpcParams) throws ClassNotFoundException, NoSuchMethodException { super(rpcConnectionKey, rpcParams); this.stubMethod = getServiceClass().getMethod("newStub", RpcChannel.class); this.rpcChannel = new ProxyRpcChannel(); this.handler = new ClientChannelInboundHandler(); final long socketTimeoutMills = Long.parseLong( rpcParams.getProperty(CLIENT_SOCKET_TIMEOUT, String.valueOf(CLIENT_SOCKET_TIMEOUT_DEFAULT))); // Enable proactive hang detection final boolean hangDetectionEnabled = Boolean.parseBoolean( rpcParams.getProperty(CLIENT_HANG_DETECTION, String.valueOf(CLIENT_HANG_DETECTION_DEFAULT))); init(new ProtoClientChannelInitializer(handler, RpcResponse.getDefaultInstance(), socketTimeoutMills, hangDetectionEnabled), eventLoopGroup); }
public void callMethod(final MethodDescriptor method, final RpcController controller, final Message param, final Message responseType, RpcCallback<Message> done) { int nextSeqId = sequence.getAndIncrement(); Message rpcRequest = buildRequest(nextSeqId, method, param); inboundHandler.registerCallback(nextSeqId, new ResponseCallback(controller, responseType, done)); ChannelPromise channelPromise = getChannel().newPromise(); channelPromise.addListener(new GenericFutureListener<ChannelFuture>() { @Override public void operationComplete(ChannelFuture future) throws Exception { if (!future.isSuccess()) { inboundHandler.exceptionCaught(null, new ServiceException(future.cause())); } } }); getChannel().writeAndFlush(rpcRequest, channelPromise); }
AsyncRpcClient(RpcConnectionKey rpcConnectionKey, int retries, int idleTimeSeconds) throws ClassNotFoundException, NoSuchMethodException { super(rpcConnectionKey, retries); stubMethod = getServiceClass().getMethod("newStub", RpcChannel.class); rpcChannel = new ProxyRpcChannel(); inboundHandler = new ClientChannelInboundHandler(); init(new ProtoChannelInitializer(inboundHandler, RpcResponse.getDefaultInstance(), idleTimeSeconds)); }