コード例 #1
0
  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);
  }
コード例 #2
0
ファイル: Consumer.java プロジェクト: BT5ZH/graylog2-server
  public void stop() throws IOException {
    if (channel != null && channel.isOpen()) {
      channel.close();
    }

    if (connection != null && connection.isOpen()) {
      connection.close();
    }
  }
コード例 #3
0
  @Override
  public void fireChannelUnregistered() {
    head.fireChannelUnregistered();

    // Free all buffers if channel is closed and unregistered.
    if (!channel.isOpen()) {
      head.invokeFreeInboundBuffer();
    }
  }
コード例 #4
0
  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());
              }
            }
          });
    }
  }
コード例 #5
0
 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;
 }
コード例 #6
0
ファイル: Consumer.java プロジェクト: BT5ZH/graylog2-server
 public boolean isConnected() {
   return connection != null && connection.isOpen() && channel != null && channel.isOpen();
 }
コード例 #7
0
 private void expectChannelRecovery(Channel ch) throws InterruptedException {
   assertTrue(ch.isOpen());
 }