public void testChannelRecovery() throws IOException, InterruptedException { Channel ch1 = connection.createChannel(); Channel ch2 = connection.createChannel(); assertTrue(ch1.isOpen()); assertTrue(ch2.isOpen()); closeAndWaitForRecovery(); expectChannelRecovery(ch1); expectChannelRecovery(ch2); }
public void stop() throws IOException { if (channel != null && channel.isOpen()) { channel.close(); } if (connection != null && connection.isOpen()) { connection.close(); } }
@Override public void fireChannelUnregistered() { head.fireChannelUnregistered(); // Free all buffers if channel is closed and unregistered. if (!channel.isOpen()) { head.invokeFreeInboundBuffer(); } }
private void sendHttpResponse(Channel channel, HttpRequest request, HttpResponse response) { if (!channel.isOpen()) { return; } // response的内容已在各Listener中填充 response.headers().set(Names.CONTENT_LENGTH, response.getContent().readableBytes()); response.headers().set(Names.SERVER, "NAVI/1.1.4(UNIX)"); if (!HttpHeaders.isKeepAlive(request) || response.getStatus() != HttpResponseStatus.OK || ServerConfigure.isChannelClose()) { response.headers().set(Names.CONNECTION, "close"); channel.setAttachment(WRITING); ChannelFuture f = channel.write(response); f.addListener(ChannelFutureListener.CLOSE); f.addListener( new ChannelFutureListener() { public void operationComplete(ChannelFuture f) throws Exception { if (!f.isSuccess()) { log.error(f.getCause().getMessage(), f.getCause()); } } }); } else { if (request.getProtocolVersion() == HttpVersion.HTTP_1_0) { response.headers().add(Names.CONNECTION, "Keep-Alive"); } channel.setAttachment(WRITING); ChannelFuture f = channel.write(response); f.addListener(ChannelFutureListener.CLOSE_ON_FAILURE); f.addListener( new ChannelFutureListener() { public void operationComplete(ChannelFuture f) throws Exception { if (!f.isSuccess()) { log.error(f.getCause().getMessage(), f.getCause()); } } }); } }
public void close() { try { if (channel != null && channel.isOpen()) { if (consumerTag != null) channel.basicCancel(consumerTag); channel.close(); } } catch (Exception e) { logger.debug("error closing channel and/or cancelling consumer", e); } try { logger.info("closing connection to rabbitmq: " + connection); connection.close(); } catch (Exception e) { logger.debug("error closing connection", e); } consumer = null; consumerTag = null; channel = null; connection = null; }
public boolean isConnected() { return connection != null && connection.isOpen() && channel != null && channel.isOpen(); }
private void expectChannelRecovery(Channel ch) throws InterruptedException { assertTrue(ch.isOpen()); }