public boolean isConnected() { Channel channel = getChannel(); return channel != null && channel.isActive(); }
public SocketAddress getRemoteAddress() { Channel channel = getChannel(); return channel == null ? null : channel.remoteAddress(); }
public SocketAddress getRemoteAddress() { Channel channel = getChannel(); return channel == null ? null : channel.remoteAddress(); }
public boolean isConnected() { Channel channel = getChannel(); return channel != null && channel.isActive(); }
public SocketAddress getRemoteAddress() { Channel channel = getChannel(); return channel == null ? null : channel.remoteAddress(); }
public boolean isConnected() { Channel channel = getChannel(); return channel != null && channel.isOpen() && channel.isActive(); }
@Override public void close() { Channel channel = getChannel(); if (channel != null && channel.isOpen()) { LOG.debug("Proxy will be disconnected from remote " + channel.remoteAddress()); /* channelInactive receives event and then client terminates all the requests */ channel.close().syncUninterruptibly(); } }
@Override public void close() { Channel channel = getChannel(); if (channel != null && channel.isOpen()) { LOG.debug("Proxy will be disconnected from remote " + channel.remoteAddress()); channel.close().awaitUninterruptibly(); } } }
@Override public void close() { Channel channel = getChannel(); if (channel != null && channel.isOpen()) { LOG.debug("Proxy will be disconnected from remote " + channel.remoteAddress()); /* channelInactive receives event and then client terminates all the requests */ channel.close().syncUninterruptibly(); } }
if(getChannel().eventLoop().isShuttingDown()) { LOG.warn("RPC is shutting down"); return; ChannelPromise promise = getChannel().newPromise(); promise.addListener(new GenericFutureListener<ChannelFuture>() { getChannel().writeAndFlush(rpcRequest, promise);
if(getChannel().eventLoop().isShuttingDown()) { LOG.warn("RPC is shutting down"); return; ChannelPromise promise = getChannel().newPromise(); promise.addListener(new GenericFutureListener<ChannelFuture>() { getChannel().writeAndFlush(rpcRequest, promise);
private void doReconnect(final InetSocketAddress address, ChannelFuture future, int retries) throws ConnectException { for (; ; ) { if (maxRetryNum > retries) { retries++; if(getChannel().eventLoop().isShuttingDown()) { LOG.warn("RPC is shutting down"); return; } LOG.warn(getErrorMessage(ExceptionUtils.getMessage(future.cause())) + "\nTry to reconnect : " + getKey().addr); try { Thread.sleep(RpcConstants.DEFAULT_PAUSE); } catch (InterruptedException e) { } this.channelFuture = doConnect(address).awaitUninterruptibly(); if (this.channelFuture.isDone() && this.channelFuture.isSuccess()) { break; } } else { LOG.error("Max retry count has been exceeded. attempts=" + retries + " caused by: " + future.cause()); throw makeConnectException(address, future); } } }
private void doReconnect(final InetSocketAddress address, ChannelFuture future, int retries) throws ConnectException { for (; ; ) { if (maxRetryNum > retries) { retries++; if(getChannel().eventLoop().isShuttingDown()) { LOG.warn("RPC is shutting down"); return; } LOG.warn(getErrorMessage(ExceptionUtils.getMessage(future.cause())) + "\nTry to reconnect : " + getKey().addr); try { Thread.sleep(RpcConstants.DEFAULT_PAUSE); } catch (InterruptedException e) { } this.channelFuture = doConnect(address).awaitUninterruptibly(); if (this.channelFuture.isDone() && this.channelFuture.isSuccess()) { break; } } else { LOG.error("Max retry count has been exceeded. attempts=" + retries + " caused by: " + future.cause()); throw makeConnectException(address, future); } } }
/** * Connect a {@link NettyClientBase} to the remote {@link NettyServerBase}, and returns rpc client by protocol. * This client will be shared per protocol and address. Client is removed in shared map when a client is closed * @param addr * @param protocolClass * @param asyncMode * @return * @throws NoSuchMethodException * @throws ClassNotFoundException * @throws ConnectTimeoutException */ public NettyClientBase getClient(InetSocketAddress addr, Class<?> protocolClass, boolean asyncMode) throws NoSuchMethodException, ClassNotFoundException, ConnectTimeoutException { RpcConnectionKey key = new RpcConnectionKey(addr, protocolClass, asyncMode); NettyClientBase client; synchronized (clients) { client = clients.get(key); if (client == null) { clients.put(key, client = makeClient(key)); } } if (!client.isConnected()) { client.connect(); client.getChannel().closeFuture().addListener(new ConnectionCloseFutureListener(key)); } assert client.isConnected(); return client; }
@Override public void operationComplete(final ChannelFuture future) throws Exception { if (future.isSuccess()) { getHandler().registerCallback(rpcRequest.getId(), callback); } else { if (!future.channel().isActive() && retry < maxRetryNum) { /* schedule the current request for the retry */ LOG.warn(future.cause() + " Try to reconnect :" + getKey().addr); final EventLoop loop = future.channel().eventLoop(); loop.schedule(new Runnable() { @Override public void run() { doConnect(getKey().addr).addListener(new GenericFutureListener<ChannelFuture>() { @Override public void operationComplete(ChannelFuture future) throws Exception { invoke(rpcRequest, callback, retry + 1); } }); } }, RpcConstants.DEFAULT_PAUSE, TimeUnit.MILLISECONDS); } else { /* Max retry count has been exceeded or internal failure */ getHandler().registerCallback(rpcRequest.getId(), callback); getHandler().exceptionCaught(getChannel().pipeline().lastContext(), new RecoverableException(rpcRequest.getId(), future.cause())); } } } });
@Override public void operationComplete(final ChannelFuture future) throws Exception { if (future.isSuccess()) { getHandler().registerCallback(rpcRequest.getId(), callback); } else { if (!future.channel().isActive() && retry < maxRetryNum) { /* schedule the current request for the retry */ LOG.warn(future.cause() + " Try to reconnect :" + getKey().addr); final EventLoop loop = future.channel().eventLoop(); loop.schedule(new Runnable() { @Override public void run() { doConnect(getKey().addr).addListener(new GenericFutureListener<ChannelFuture>() { @Override public void operationComplete(ChannelFuture future) throws Exception { invoke(rpcRequest, callback, retry + 1); } }); } }, RpcConstants.DEFAULT_PAUSE, TimeUnit.MILLISECONDS); } else { /* Max retry count has been exceeded or internal failure */ getHandler().registerCallback(rpcRequest.getId(), callback); getHandler().exceptionCaught(getChannel().pipeline().lastContext(), new RecoverableException(rpcRequest.getId(), future.cause())); } } } });
@Test public void testClientRPCInterference() throws Exception { TajoClient client = cluster.newTajoClient(); TajoClient client2 = cluster.newTajoClient(); NettyClientBase rpcClient = Whitebox.getInternalState(client, NettyClientBase.class); assertNotNull(rpcClient); NettyClientBase rpcClient2 = Whitebox.getInternalState(client2, NettyClientBase.class); assertNotNull(rpcClient); assertNotEquals(rpcClient.getChannel().eventLoop(), rpcClient2.getChannel().eventLoop()); client.close(); client2.close(); rpcClient.getChannel().eventLoop().terminationFuture().sync(); assertTrue(rpcClient.getChannel().eventLoop().isTerminated()); rpcClient2.getChannel().eventLoop().terminationFuture().sync(); assertTrue(rpcClient2.getChannel().eventLoop().isTerminated()); }