Codota Logo
Channel.writeAndFlush
Code IndexAdd Codota to your IDE (free)

How to use
writeAndFlush
method
in
io.netty.channel.Channel

Best Java code snippets using io.netty.channel.Channel.writeAndFlush (Showing top 20 results out of 4,401)

Refine searchRefine arrow

  • ChannelFuture.addListener
  • ChannelHandlerContext.channel
  • Common ways to obtain Channel
private void myMethod () {
Channel c =
  • Codota IconChannelFuture future;future.channel()
  • Codota IconChannelHandlerContext ctx;ctx.channel()
  • Codota IconChannelHandlerContext ctx;ctx.channel().read()
  • Smart code suggestions by Codota
}
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: 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: Netflix/zuul

@Override
public ChannelFuture sendPushMessage(ChannelHandlerContext ctx, ByteBuf mesg) {
  final TextWebSocketFrame wsf = new TextWebSocketFrame(mesg);
  return ctx.channel().writeAndFlush(wsf);
}
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: fengjiachun/Jupiter

  @Override
  public void handle(Channel channel, Command command, String... args) {
    channel.writeAndFlush("Bye bye!" + JConstants.NEWLINE)
        .addListener(ChannelFutureListener.CLOSE);
  }
}
origin: Netflix/zuul

@Override
public ChannelFuture sendPing(ChannelHandlerContext ctx) {
  return ctx.channel().writeAndFlush(new PingWebSocketFrame());
}
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: fengjiachun/Jupiter

  @Override
  public void handle(Channel channel, Command command, String... args) {
    channel.writeAndFlush("Bye bye!" + JConstants.NEWLINE)
        .addListener(ChannelFutureListener.CLOSE);
  }
}
origin: weibocom/motan

private ChannelFuture sendResponse(ChannelHandlerContext ctx, Response response) {
  byte[] msg = CodecUtil.encodeObjectToBytes(channel, codec, response);
  if (ctx.channel().isActive()) {
    return ctx.channel().writeAndFlush(msg);
  }
  return null;
}
origin: wildfly/wildfly

@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
  if (cause instanceof WebSocketHandshakeException) {
    FullHttpResponse response = new DefaultFullHttpResponse(
        HTTP_1_1, HttpResponseStatus.BAD_REQUEST, Unpooled.wrappedBuffer(cause.getMessage().getBytes()));
    ctx.channel().writeAndFlush(response).addListener(ChannelFutureListener.CLOSE);
  } else {
    ctx.fireExceptionCaught(cause);
    ctx.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: Netflix/zuul

@Override
public ChannelFuture sendPing(ChannelHandlerContext ctx) {
  final ByteBuf newBuff = ctx.alloc().buffer();
  newBuff.ensureWritable(SSE_PING.length());
  newBuff.writeCharSequence(SSE_PING, Charsets.UTF_8);
  return ctx.channel().writeAndFlush(newBuff);
}
origin: jamesdbloom/mockserver

private void failure(String message, Throwable cause, ChannelHandlerContext ctx, Object response) {
  if (shouldNotIgnoreException(cause)) {
    mockServerLogger.error(message, cause);
  }
  Channel channel = ctx.channel();
  channel.writeAndFlush(response);
  if (channel.isActive()) {
    channel.writeAndFlush(Unpooled.EMPTY_BUFFER).addListener(ChannelFutureListener.CLOSE);
  }
}
origin: jamesdbloom/mockserver

@Override
public void channelRead0(final ChannelHandlerContext ctx, final FullHttpResponse response) {
  upstreamChannel.writeAndFlush(response).addListener(new ChannelFutureListener() {
    @Override
    public void operationComplete(ChannelFuture future) {
      if (future.isSuccess()) {
        ctx.channel().read();
      } else {
        if (isNotSocketClosedException(future.cause())) {
          mockServerLogger.error("Exception while returning writing " + response, future.cause());
        }
        future.channel().close();
      }
    }
  });
}
origin: wildfly/wildfly

  @Override
  public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
    if (msg instanceof FullHttpRequest) {
      ((FullHttpRequest) msg).release();
      FullHttpResponse response =
          new DefaultFullHttpResponse(HTTP_1_1, HttpResponseStatus.FORBIDDEN);
      ctx.channel().writeAndFlush(response);
    } else {
      ctx.fireChannelRead(msg);
    }
  }
};
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: luxiaoxun/NettyRpc

public void close() {
  channel.writeAndFlush(Unpooled.EMPTY_BUFFER).addListener(ChannelFutureListener.CLOSE);
}
origin: jamesdbloom/mockserver

private void sendMessage(ChannelHandlerContext ctx, ImmutableMap<String, Object> message) throws JsonProcessingException {
  ctx.channel().writeAndFlush(new TextWebSocketFrame(
    objectMapper.writeValueAsString(message)
  ));
}
origin: wildfly/wildfly

private static void sendHttpResponse(ChannelHandlerContext ctx, HttpRequest req, HttpResponse res) {
  ChannelFuture f = ctx.channel().writeAndFlush(res);
  if (!isKeepAlive(req) || res.status().code() != 200) {
    f.addListener(ChannelFutureListener.CLOSE);
  }
}
origin: wildfly/wildfly

/**
 * Performs the closing handshake
 *
 * @param channel
 *            Channel
 * @param frame
 *            Closing Frame that was received
 * @param promise
 *            the {@link ChannelPromise} to be notified when the closing handshake is done
 */
public ChannelFuture close(Channel channel, CloseWebSocketFrame frame, ChannelPromise promise) {
  if (channel == null) {
    throw new NullPointerException("channel");
  }
  return channel.writeAndFlush(frame, promise).addListener(ChannelFutureListener.CLOSE);
}
io.netty.channelChannelwriteAndFlush

Popular methods of Channel

  • close
  • remoteAddress
    Returns the remote address where this channel is connected to. The returned SocketAddress is suppose
  • pipeline
    Return the assigned ChannelPipeline.
  • closeFuture
    Returns the ChannelFuture which will be notified when this channel is closed. This method always ret
  • isActive
    Return true if the Channel is active and so connected.
  • localAddress
    Returns the local address where this channel is bound to. The returned SocketAddress is supposed to
  • eventLoop
    Return the EventLoop this Channel was registered to.
  • isOpen
    Returns true if the Channel is open and may get active later
  • attr
  • write
  • alloc
    Return the assigned ByteBufAllocator which will be used to allocate ByteBufs.
  • isWritable
    Returns true if and only if the I/O thread will perform the requested write operation immediately. A
  • alloc,
  • isWritable,
  • config,
  • flush,
  • newPromise,
  • id,
  • read,
  • voidPromise,
  • isRegistered

Popular in Java

  • Creating JSON documents from java classes using gson
  • getApplicationContext (Context)
  • getExternalFilesDir (Context)
  • scheduleAtFixedRate (Timer)
    Schedules the specified task for repeated fixed-rate execution, beginning after the specified delay.
  • InputStream (java.io)
    A readable source of bytes.Most clients will use input streams that read data from the file system (
  • MalformedURLException (java.net)
    Thrown to indicate that a malformed URL has occurred. Either no legal protocol could be found in a s
  • Collections (java.util)
    This class consists exclusively of static methods that operate on or return collections. It contains
  • ThreadPoolExecutor (java.util.concurrent)
    An ExecutorService that executes each submitted task using one of possibly several pooled threads, n
  • AtomicInteger (java.util.concurrent.atomic)
    An int value that may be updated atomically. See the java.util.concurrent.atomic package specificati
  • Response (javax.ws.rs.core)
    Defines the contract between a returned instance and the runtime when an application needs to provid
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