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

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

Best Java code snippets using io.netty.channel.ChannelHandlerContext.writeAndFlush (Showing top 20 results out of 3,753)

Refine searchRefine arrow

  • ChannelFuture.addListener
  • ChannelHandlerContext.channel
  • Common ways to obtain ChannelHandlerContext
private void myMethod () {
ChannelHandlerContext c =
  • Codota IconMockito mockito;mockito.mock(ChannelHandlerContext.class)
  • 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: wildfly/wildfly

/**
 * Sends the specified message to the proxy server.  Use this method to send a response to the proxy server in
 * {@link #handleResponse(ChannelHandlerContext, Object)}.
 */
protected final void sendToProxyServer(Object msg) {
  ctx.writeAndFlush(msg).addListener(writeListener);
}
origin: yu199195/Raincat

/**
 * async Send message to tx Manager.
 *
 * @param heartBeat {@linkplain HeartBeat }
 */
public void asyncSendTxManagerMessage(final HeartBeat heartBeat) {
  if (ctx != null && ctx.channel() != null && ctx.channel().isActive()) {
    ctx.writeAndFlush(heartBeat);
  }
}
origin: dreamhead/moco

@Override
public void channelActive(final ChannelHandlerContext ctx) throws Exception {
  ctx.writeAndFlush(shutdownKey + "\r\n").addListener(ChannelFutureListener.CLOSE);
}
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: alibaba/fescar

@Override
@SuppressWarnings("unchecked")
public void channelRead(final ChannelHandlerContext ctx, final Object msg) throws Exception {
  final Channel channel = ctx.channel();
  final String request = (String)msg;
  try {
    ctx.writeAndFlush(request, ctx.voidPromise());
    LOGGER.info("client:" + msg);
  } catch (Exception e) {
    LOGGER.error("when try flush error", e);
  }
}
origin: normanmaurer/netty-in-action

@Override
public void channelReadComplete(ChannelHandlerContext ctx)
    throws Exception {
  ctx.writeAndFlush(Unpooled.EMPTY_BUFFER)
      .addListener(ChannelFutureListener.CLOSE);
}
origin: apache/incubator-dubbo

@Override
protected void channelRead0(ChannelHandlerContext ctx, String msg) throws Exception {
  if (StringUtils.isBlank(msg)) {
    ctx.writeAndFlush(QosProcessHandler.prompt);
  } else {
    CommandContext commandContext = TelnetCommandDecoder.decode(msg);
    commandContext.setRemote(ctx.channel());
    try {
      String result = commandExecutor.execute(commandContext);
      if (StringUtils.isEquals(QosConstants.CLOSE, result)) {
        ctx.writeAndFlush(getByeLabel()).addListener(ChannelFutureListener.CLOSE);
      } else {
        ctx.writeAndFlush(result + QosConstants.BR_STR + QosProcessHandler.prompt);
      }
    } catch (NoSuchCommandException ex) {
      ctx.writeAndFlush(msg + " :no such command");
      ctx.writeAndFlush(QosConstants.BR_STR + QosProcessHandler.prompt);
      log.error("can not found command " + commandContext, ex);
    } catch (Exception ex) {
      ctx.writeAndFlush(msg + " :fail to execute commandContext by " + ex.getMessage());
      ctx.writeAndFlush(QosConstants.BR_STR + QosProcessHandler.prompt);
      log.error("execute commandContext got exception " + commandContext, ex);
    }
  }
}
origin: apache/pulsar

@Override
final protected void handlePing(CommandPing ping) {
  // Immediately reply success to ping requests
  if (log.isDebugEnabled()) {
    log.debug("[{}] Replying back to ping message", ctx.channel());
  }
  ctx.writeAndFlush(Commands.newPong());
}
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: apache/incubator-dubbo

@Override
protected void channelRead0(ChannelHandlerContext ctx, String msg) throws Exception {
  if (StringUtils.isBlank(msg)) {
    ctx.writeAndFlush(QosProcessHandler.prompt);
  } else {
    CommandContext commandContext = TelnetCommandDecoder.decode(msg);
    commandContext.setRemote(ctx.channel());
    try {
      String result = commandExecutor.execute(commandContext);
      if (StringUtils.isEquals(QosConstants.CLOSE, result)) {
        ctx.writeAndFlush(getByeLabel()).addListener(ChannelFutureListener.CLOSE);
      } else {
        ctx.writeAndFlush(result + QosConstants.BR_STR + QosProcessHandler.prompt);
      }
    } catch (NoSuchCommandException ex) {
      ctx.writeAndFlush(msg + " :no such command");
      ctx.writeAndFlush(QosConstants.BR_STR + QosProcessHandler.prompt);
      log.error("can not found command " + commandContext, ex);
    } catch (Exception ex) {
      ctx.writeAndFlush(msg + " :fail to execute commandContext by " + ex.getMessage());
      ctx.writeAndFlush(QosConstants.BR_STR + QosProcessHandler.prompt);
      log.error("execute commandContext got exception " + commandContext, ex);
    }
  }
}
origin: blynkkk/blynk-server

private void sendRedirectResponse(ChannelHandlerContext ctx, String token, String server, int msgId) {
  MessageBase response;
  if (server == null || server.equals(holder.props.host)) {
    log.debug("HardwareLogic token is invalid. Token '{}', '{}'", token, ctx.channel().remoteAddress());
    response = invalidToken(msgId);
  } else {
    log.debug("Redirecting token '{}' to {}", token, server);
    response = makeASCIIStringMessage(CONNECT_REDIRECT, msgId, server + BODY_SEPARATOR + listenPort);
  }
  ctx.writeAndFlush(response, ctx.voidPromise());
}
origin: Netflix/zuul

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

private void protocolViolation(ChannelHandlerContext ctx, CorruptedFrameException ex) {
  state = State.CORRUPT;
  if (ctx.channel().isActive()) {
    Object closeMessage;
    if (receivedClosingHandshake) {
      closeMessage = Unpooled.EMPTY_BUFFER;
    } else {
      closeMessage = new CloseWebSocketFrame(1002, null);
    }
    ctx.writeAndFlush(closeMessage).addListener(ChannelFutureListener.CLOSE);
  }
  throw ex;
}
origin: blynkkk/blynk-server

@Override
protected void channelRead0(ChannelHandlerContext ctx, MessageBase msg) {
  log.debug("User not logged. {}. Closing.", ctx.channel().remoteAddress());
  if (msg instanceof RegisterMessage) {
    if (ctx.channel().isWritable()) {
      ctx.writeAndFlush(notAllowed(msg.id), ctx.voidPromise());
    }
  }
  ctx.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: 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;
}
origin: ethereum/ethereumj

public void sendHelloMessage(ChannelHandlerContext ctx, FrameCodec frameCodec,
               String nodeId) throws IOException, InterruptedException {
  final HelloMessage helloMessage = staticMessages.createHelloMessage(nodeId);
  ByteBuf byteBufMsg = ctx.alloc().buffer();
  frameCodec.writeFrame(new FrameCodec.Frame(helloMessage.getCode(), helloMessage.getEncoded()), byteBufMsg);
  ctx.writeAndFlush(byteBufMsg).sync();
  if (logger.isDebugEnabled())
    logger.debug("To:   {}    Send:  {}", ctx.channel().remoteAddress(), helloMessage);
  getNodeStatistics().rlpxOutHello.add();
}
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: apache/pulsar

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

Popular methods of ChannelHandlerContext

  • channel
    Return the Channel which is bound to the ChannelHandlerContext.
  • close
  • write
  • flush
  • fireChannelRead
  • pipeline
    Return the assigned ChannelPipeline
  • alloc
    Return the assigned ByteBufAllocator which will be used to allocate ByteBufs.
  • executor
    Returns the EventExecutor which is used to execute an arbitrary task.
  • fireExceptionCaught
  • fireUserEventTriggered
  • newPromise
  • fireChannelActive
  • newPromise,
  • fireChannelActive,
  • fireChannelInactive,
  • voidPromise,
  • read,
  • fireChannelReadComplete,
  • name,
  • attr,
  • disconnect

Popular in Java

  • Updating database using SQL prepared statement
  • getContentResolver (Context)
  • orElseThrow (Optional)
  • getSystemService (Context)
  • Container (java.awt)
    A generic Abstract Window Toolkit(AWT) container object is a component that can contain other AWT co
  • Socket (java.net)
    Provides a client-side TCP socket.
  • SQLException (java.sql)
    An exception that indicates a failed JDBC operation. It provides the following information about pro
  • Arrays (java.util)
    This class contains various methods for manipulating arrays (such as sorting and searching). This cl
  • SortedMap (java.util)
    A map that has its keys ordered. The sorting is according to either the natural ordering of its keys
  • JList (javax.swing)
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