Codota Logo
ChannelFuture.addListener
Code IndexAdd Codota to your IDE (free)

How to use
addListener
method
in
io.netty.channel.ChannelFuture

Best Java code snippets using io.netty.channel.ChannelFuture.addListener (Showing top 20 results out of 5,175)

Refine searchRefine arrow

  • ChannelHandlerContext.channel
  • ChannelHandlerContext.writeAndFlush
  • Channel.writeAndFlush
  • ChannelFuture.isDone
  • DefaultFullHttpResponse.<init>
  • Common ways to obtain ChannelFuture
private void myMethod () {
ChannelFuture c =
  • Codota IconChannelHandlerContext ctx;Object response;ctx.writeAndFlush(response)
  • Codota IconChannelHandlerContext ctx;ctx.close()
  • Codota IconChannel channel;Object request;channel.writeAndFlush(request)
  • Smart code suggestions by Codota
}
origin: apache/incubator-dubbo

  @Override
  public void handlerAdded(ChannelHandlerContext ctx) throws Exception {
    if (!acceptForeignIp) {
      if (!((InetSocketAddress) ctx.channel().remoteAddress()).getAddress().isLoopbackAddress()) {
        ByteBuf cb = Unpooled.wrappedBuffer((QosConstants.BR_STR + "Foreign Ip Not Permitted."
            + QosConstants.BR_STR).getBytes());
        ctx.writeAndFlush(cb).addListener(ChannelFutureListener.CLOSE);
      }
    }
  }
}
origin: eclipse-vertx/vert.x

private void sendServiceUnavailable(Channel ch) {
 ch.writeAndFlush(
  Unpooled.copiedBuffer("HTTP/1.1 503 Service Unavailable\r\n" +
   "Content-Length:0\r\n" +
   "\r\n", StandardCharsets.ISO_8859_1))
  .addListener(ChannelFutureListener.CLOSE);
}
origin: redisson/redisson

  @Override
  protected boolean accept(ChannelHandlerContext ctx, InetSocketAddress remoteAddress) throws Exception {
    final InetAddress remoteIp = remoteAddress.getAddress();
    if (!connected.add(remoteIp)) {
      return false;
    } else {
      ctx.channel().closeFuture().addListener(new ChannelFutureListener() {
        @Override
        public void operationComplete(ChannelFuture future) throws Exception {
          connected.remove(remoteIp);
        }
      });
      return true;
    }
  }
}
origin: lets-blade/blade

private static void sendError(ChannelHandlerContext ctx, HttpResponseStatus status) {
  var response = new DefaultFullHttpResponse(HTTP_1_1, status,
      Unpooled.copiedBuffer("Failure: " + status + "\r\n", CharsetUtil.UTF_8));
  response.headers().set(HttpConst.CONTENT_TYPE, Const.CONTENT_TYPE_TEXT);
  // Close the connection as soon as the error message is sent.
  ctx.writeAndFlush(response).addListener(ChannelFutureListener.CLOSE);
}
origin: Netflix/zuul

public final void sendHttpResponse(HttpRequest req, ChannelHandlerContext ctx, HttpResponseStatus status) {
  FullHttpResponse resp = new DefaultFullHttpResponse(HTTP_1_1, status);
  resp.headers().add("Content-Length", "0");
  final boolean closeConn = ((status != OK) || (! HttpUtil.isKeepAlive(req)));
  if (closeConn)  {
    resp.headers().add(HttpHeaderNames.CONNECTION, "Close");
  }
  final ChannelFuture cf = ctx.channel().writeAndFlush(resp);
  if (closeConn) {
    cf.addListener(ChannelFutureListener.CLOSE);
  }
}
origin: mrniko/netty-socketio

private void sendError(ChannelHandlerContext ctx) {
  HttpResponse res = new DefaultHttpResponse(HTTP_1_1, HttpResponseStatus.INTERNAL_SERVER_ERROR);
  ctx.channel().writeAndFlush(res).addListener(ChannelFutureListener.CLOSE);
}
origin: netty/netty

private void shutdownOutputDone(final ChannelFuture shutdownOutputFuture, final ChannelPromise promise) {
  ChannelFuture shutdownInputFuture = shutdownInput();
  if (shutdownInputFuture.isDone()) {
    shutdownDone(shutdownOutputFuture, shutdownInputFuture, promise);
  } else {
    shutdownInputFuture.addListener(new ChannelFutureListener() {
      @Override
      public void operationComplete(ChannelFuture shutdownInputFuture) throws Exception {
        shutdownDone(shutdownOutputFuture, shutdownInputFuture, promise);
      }
    });
  }
}
origin: Netflix/zuul

public final void sendErrorAndClose(ChannelHandlerContext ctx, int statusCode, String reasonText) {
  ctx.writeAndFlush(serverClosingConnectionMessage(statusCode, reasonText))
      .addListener(ChannelFutureListener.CLOSE);
}
origin: Netflix/zuul

@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
  int status = 500;
  final String errorMsg = "ClientResponseWriter caught exception in client connection pipeline: " +
      ChannelUtils.channelInfoForLogging(ctx.channel());
  if (cause instanceof ZuulException) {
    final ZuulException ze = (ZuulException) cause;
    status = ze.getStatusCode();
    LOG.error(errorMsg, cause);
  }
  else if (cause instanceof ReadTimeoutException) {
    LOG.error(errorMsg + ", Read timeout fired");
    status = 504;
  }
  else {
    LOG.error(errorMsg, cause);
  }
  if (isHandlingRequest && !startedSendingResponseToClient && ctx.channel().isActive()) {
    final HttpResponse httpResponse = new DefaultFullHttpResponse(HTTP_1_1, HttpResponseStatus.valueOf(status));
    ctx.writeAndFlush(httpResponse).addListener(ChannelFutureListener.CLOSE);
    startedSendingResponseToClient = true;
  }
  else {
    ctx.close();
  }
}
origin: redisson/redisson

private void writeQuery(final DnsQuery query, final boolean flush, final ChannelPromise writePromise) {
  final ChannelFuture writeFuture = flush ? parent.ch.writeAndFlush(query, writePromise) :
      parent.ch.write(query, writePromise);
  if (writeFuture.isDone()) {
    onQueryWriteCompletion(writeFuture);
  } else {
    writeFuture.addListener(new ChannelFutureListener() {
      @Override
      public void operationComplete(ChannelFuture future) {
        onQueryWriteCompletion(writeFuture);
      }
    });
  }
}
origin: apache/incubator-dubbo

  @Override
  public void handlerAdded(ChannelHandlerContext ctx) throws Exception {
    if (!acceptForeignIp) {
      if (!((InetSocketAddress) ctx.channel().remoteAddress()).getAddress().isLoopbackAddress()) {
        ByteBuf cb = Unpooled.wrappedBuffer((QosConstants.BR_STR + "Foreign Ip Not Permitted."
            + QosConstants.BR_STR).getBytes());
        ctx.writeAndFlush(cb).addListener(ChannelFutureListener.CLOSE);
      }
    }
  }
}
origin: lets-blade/blade

private static void sendError(ChannelHandlerContext ctx, HttpResponseStatus status) {
  var response = new DefaultFullHttpResponse(HTTP_1_1, status,
      Unpooled.copiedBuffer("Failure: " + status + "\r\n", CharsetUtil.UTF_8));
  response.headers().set(HttpConst.CONTENT_TYPE, Const.CONTENT_TYPE_TEXT);
  // Close the connection as soon as the error message is sent.
  ctx.writeAndFlush(response).addListener(ChannelFutureListener.CLOSE);
}
origin: Netflix/zuul

private void sendHttpResponse(ChannelHandlerContext ctx, FullHttpRequest request, HttpResponseStatus status,
               PushUserAuth userAuth) {
  final FullHttpResponse resp = new DefaultFullHttpResponse(HTTP_1_1, status);
  resp.headers().add("Content-Length", "0");
  final ChannelFuture cf = ctx.channel().writeAndFlush(resp);
  if (!HttpUtil.isKeepAlive(request)) {
    cf.addListener(ChannelFutureListener.CLOSE);
  }
  logPushEvent(request, status, userAuth);
}
origin: ffay/lanproxy

private void handleDisconnectMessage(ChannelHandlerContext ctx, ProxyMessage proxyMessage) {
  Channel realServerChannel = ctx.channel().attr(Constants.NEXT_CHANNEL).get();
  logger.debug("handleDisconnectMessage, {}", realServerChannel);
  if (realServerChannel != null) {
    ctx.channel().attr(Constants.NEXT_CHANNEL).remove();
    ClientChannelMannager.returnProxyChanel(ctx.channel());
    realServerChannel.writeAndFlush(Unpooled.EMPTY_BUFFER).addListener(ChannelFutureListener.CLOSE);
  }
}
origin: jamesdbloom/mockserver

/**
 * Closes the specified channel after all queued write requests are flushed.
 */
public static void closeOnFlush(Channel ch) {
  if (ch != null && ch.isActive()) {
    ch.writeAndFlush(Unpooled.EMPTY_BUFFER).addListener(ChannelFutureListener.CLOSE);
  }
}
origin: netty/netty

private void shutdownOutputDone(final ChannelFuture shutdownOutputFuture, final ChannelPromise promise) {
  ChannelFuture shutdownInputFuture = shutdownInput();
  if (shutdownInputFuture.isDone()) {
    shutdownDone(shutdownOutputFuture, shutdownInputFuture, promise);
  } else {
    shutdownInputFuture.addListener(new ChannelFutureListener() {
      @Override
      public void operationComplete(ChannelFuture shutdownInputFuture) throws Exception {
        shutdownDone(shutdownOutputFuture, shutdownInputFuture, promise);
      }
    });
  }
}
origin: Netflix/zuul

public final void sendErrorAndClose(ChannelHandlerContext ctx, int statusCode, String reasonText) {
  final Object mesg = serverClosingConnectionMessage(statusCode, reasonText);
  ctx.writeAndFlush(mesg).addListener(ChannelFutureListener.CLOSE);
}
origin: Netflix/zuul

@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
  int status = 500;
  final String errorMsg = "ClientResponseWriter caught exception in client connection pipeline: " +
      ChannelUtils.channelInfoForLogging(ctx.channel());
  if (cause instanceof ZuulException) {
    final ZuulException ze = (ZuulException) cause;
    status = ze.getStatusCode();
    LOG.error(errorMsg, cause);
  }
  else if (cause instanceof ReadTimeoutException) {
    LOG.error(errorMsg + ", Read timeout fired");
    status = 504;
  }
  else {
    LOG.error(errorMsg, cause);
  }
  if (isHandlingRequest && !startedSendingResponseToClient && ctx.channel().isActive()) {
    final HttpResponse httpResponse = new DefaultFullHttpResponse(HTTP_1_1, HttpResponseStatus.valueOf(status));
    ctx.writeAndFlush(httpResponse).addListener(ChannelFutureListener.CLOSE);
    startedSendingResponseToClient = true;
  }
  else {
    ctx.close();
  }
}
origin: Graylog2/graylog2-server

@Override
public void channelActive(ChannelHandlerContext ctx) throws Exception {
  connections.incrementAndGet();
  totalConnections.incrementAndGet();
  ctx.channel().closeFuture().addListener(f -> connections.decrementAndGet());
  super.channelActive(ctx);
}
origin: apache/pulsar

public CompletableFuture<MessageIdData> sendGetLastMessageId(ByteBuf request, long requestId) {
  CompletableFuture<MessageIdData> future = new CompletableFuture<>();
  pendingGetLastMessageIdRequests.put(requestId, future);
  ctx.writeAndFlush(request).addListener(writeFuture -> {
    if (!writeFuture.isSuccess()) {
      log.warn("{} Failed to send GetLastMessageId request to broker: {}", ctx.channel(), writeFuture.cause().getMessage());
      pendingGetLastMessageIdRequests.remove(requestId);
      future.completeExceptionally(writeFuture.cause());
    }
  });
  return future;
}
io.netty.channelChannelFutureaddListener

Popular methods of ChannelFuture

  • channel
    Returns a channel where the I/O operation associated with this future takes place.
  • sync
  • isSuccess
  • cause
  • awaitUninterruptibly
  • syncUninterruptibly
  • isDone
  • await
  • cancel
  • isCancelled
  • get
  • removeListener
  • get,
  • removeListener,
  • addListeners,
  • getCause,
  • getChannel,
  • setFailure,
  • setSuccess,
  • getNow,
  • isCancellable

Popular in Java

  • Making http requests using okhttp
  • orElseThrow (Optional)
    Return the contained value, if present, otherwise throw an exception to be created by the provided s
  • compareTo (BigDecimal)
    Compares this BigDecimal with the specified BigDecimal. Two BigDecimal objects that are equal in val
  • requestLocationUpdates (LocationManager)
  • Rectangle (java.awt)
    A Rectangle specifies an area in a coordinate space that is enclosed by the Rectangle object's top-
  • JFileChooser (javax.swing)
  • StringUtils (org.apache.commons.lang)
    Operations on java.lang.String that arenull safe. * IsEmpty/IsBlank - checks if a String contains
  • IsNull (org.hamcrest.core)
    Is the value null?
  • DateTimeFormat (org.joda.time.format)
    Factory that creates instances of DateTimeFormatter from patterns and styles. Datetime formatting i
  • Scheduler (org.quartz)
    This is the main interface of a Quartz Scheduler. A Scheduler maintains a registery of org.quartz
Codota Logo
  • Products

    Search for Java codeSearch for JavaScript codeEnterprise
  • IDE Plugins

    IntelliJ IDEAWebStormAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimAtomGoLandRubyMineEmacsJupyter
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogCodota Academy Plugin user guide Terms of usePrivacy policyJava Code IndexJavascript Code Index
Get Codota for your IDE now