@Override public void stop() { logger.info("Netcat UDP Source stopping..."); logger.info("Metrics:{}", counterGroup); if (nettyChannel != null) { nettyChannel.close(); try { nettyChannel.getCloseFuture().await(60, TimeUnit.SECONDS); } catch (InterruptedException e) { logger.warn("netty server stop interrupted", e); } finally { nettyChannel = null; } } super.stop(); }
ChannelFuture connectCheck = bootstrap.connect(new InetSocketAddress(address, port)); try { connectCheck.await(); } catch (InterruptedException e) { connectCheck.cancel();
requestFuture.await();
@Override public void stop() { logger.info("Syslog TCP Source stopping..."); logger.info("Metrics: {}", sourceCounter); if (nettyChannel != null) { nettyChannel.close(); try { nettyChannel.getCloseFuture().await(60, TimeUnit.SECONDS); } catch (InterruptedException e) { logger.warn("netty server stop interrupted", e); } finally { nettyChannel = null; } } sourceCounter.stop(); super.stop(); }
requestFuture.await();
@Override public void writeBuffers(List<ByteBuffer> buffers) throws IOException { ChannelFuture writeFuture; stateLock.readLock().lock(); try { writeFuture = writeDataPack( new NettyDataPack(serialGenerator.incrementAndGet(), buffers)); } finally { stateLock.readLock().unlock(); } if (!writeFuture.isDone()) { try { writeFuture.await(); } catch (InterruptedException e) { Thread.currentThread().interrupt(); // Reset interrupt flag throw new IOException("Interrupted while writing Netty data pack", e); } } if (!writeFuture.isSuccess()) { throw new IOException("Error writing buffers", writeFuture.getCause()); } }
@Override public void stop() { logger.info("Syslog UDP Source stopping..."); logger.info("Metrics: {}", sourceCounter); if (nettyChannel != null) { nettyChannel.close(); try { nettyChannel.getCloseFuture().await(60, TimeUnit.SECONDS); } catch (InterruptedException e) { logger.warn("netty server stop interrupted", e); } finally { nettyChannel = null; } } sourceCounter.stop(); super.stop(); }
@Override public void send(Object message, boolean sent) throws RemotingException { super.send(message, sent); boolean success = true; int timeout = 0; try { ChannelFuture future = channel.write(message); if (sent) { timeout = getUrl().getPositiveParameter(Constants.TIMEOUT_KEY, Constants.DEFAULT_TIMEOUT); success = future.await(timeout); } Throwable cause = future.getCause(); if (cause != null) { throw cause; } } catch (Throwable e) { throw new RemotingException(this, "Failed to send message " + message + " to " + getRemoteAddress() + ", cause: " + e.getMessage(), e); } if (!success) { throw new RemotingException(this, "Failed to send message " + message + " to " + getRemoteAddress() + "in timeout(" + timeout + "ms) limit"); } }
if (awaitCompletion && (closeFuture != null)) { try { closeFuture.await(connectTimeoutMillis); } catch (InterruptedException e) {
@Override public void send(Object message, boolean sent) throws RemotingException { super.send(message, sent); boolean success = true; int timeout = 0; try { ChannelFuture future = channel.write(message); if (sent) { timeout = getUrl().getPositiveParameter(Constants.TIMEOUT_KEY, Constants.DEFAULT_TIMEOUT); success = future.await(timeout); } Throwable cause = future.getCause(); if (cause != null) { throw cause; } } catch (Throwable e) { throw new RemotingException(this, "Failed to send message " + message + " to " + getRemoteAddress() + ", cause: " + e.getMessage(), e); } if (!success) { throw new RemotingException(this, "Failed to send message " + message + " to " + getRemoteAddress() + "in timeout(" + timeout + "ms) limit"); } }
channelFuture.await(connectTimeoutMillis); } catch (InterruptedException e) {
private boolean decodePackHeader(ChannelHandlerContext ctx, Channel channel, ChannelBuffer buffer) throws Exception { if (buffer.readableBytes()<8) { return false; } int serial = buffer.readInt(); int listSize = buffer.readInt(); // Sanity check to reduce likelihood of invalid requests being honored. // Only allow 10% of available memory to go towards this list (too much!) if (listSize * SIZEOF_REF > 0.1 * maxMem) { channel.close().await(); throw new AvroRuntimeException("Excessively large list allocation " + "request detected: " + listSize + " items! Connection closed."); } this.listSize = listSize; dataPack = new NettyDataPack(serial, new ArrayList<>(listSize)); return true; }
@Override public WebServer call() throws Exception { if (channel != null) { channel.close(); } if (connectionTrackingHandler != null) { connectionTrackingHandler.closeAllConnections(); connectionTrackingHandler = null; } if (bootstrap != null) { bootstrap.releaseExternalResources(); } // shut down all services & give them a chance to terminate for (ExecutorService executorService : executorServices) { shutdownAndAwaitTermination(executorService); } bootstrap = null; if (channel != null) { channel.getCloseFuture().await(); } return NettyWebServer.this; } });
@Override public Boolean get() throws InterruptedException, ExecutionException { future.await(); return future.isSuccess(); }
public void join() throws InterruptedException { if (serverChannel != null) { serverChannel.getCloseFuture().await(); } } }
public void disconnect() throws Exception { ChannelFuture closeFuture = channel.close(); try { closeFuture.await(idleTimeout); } catch (InterruptedException e) { LOGGER.info("Disconnecting timeout."); throw e; } releaseExternalResources(); }
public void sendPdu(Pdu pdu) throws Exception { logger.info("Sending on channel 0x" + HexUtil.toHexString(channel.getId()) + " PDU: {}", pdu); ChannelBuffer writeBuffer = this.transcoder.encode(pdu); channel.write(writeBuffer).await(); }
public void sendPdu(Pdu pdu) throws Exception { logger.info("Sending on channel 0x" + HexUtil.toHexString(channel.getId()) + " PDU: {}", pdu); ChannelBuffer writeBuffer = this.transcoder.encode(pdu); channel.write(writeBuffer).await(); }
@Override protected void doShutdown(long timeout, TimeUnit unit) throws InterruptedException { datagramChannel.close().await(timeout, unit); bootstrap.releaseExternalResources(); }
@Test public void testSendAfterServerChannelClosed() throws InterruptedException { startRepeatingPublisher(); Channel serverChannel = buildServerChannel(); connect(firstTcpClientManager, serverChannel); assertTrue(serverChannel.close().await(1, TimeUnit.SECONDS)); outgoingMessageQueue.add(expectedMessage); }