本文整理汇总了Java中io.netty.channel.ChannelHandlerContext.fireChannelRead方法的典型用法代码示例。如果您正苦于以下问题:Java ChannelHandlerContext.fireChannelRead方法的具体用法?Java ChannelHandlerContext.fireChannelRead怎么用?Java ChannelHandlerContext.fireChannelRead使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类io.netty.channel.ChannelHandlerContext
的用法示例。
在下文中一共展示了ChannelHandlerContext.fireChannelRead方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: channelRead
import io.netty.channel.ChannelHandlerContext; //导入方法依赖的package包/类
@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
if(msg instanceof HttpRequest){
HttpRequest request = (HttpRequest) msg;
if(!request.uri().equals(CommonConstants.FAVICON_ICO)){
// 将request和context存储到ThreadLocal中去,便于后期在其他地方获取并使用
DataHolder.store(DataHolder.HolderType.REQUEST,request);
DataHolder.store(DataHolder.HolderType.CONTEXT,ctx);
}
}
/**
* 提交给下一个ChannelHandler去处理
* 并且不需要调用ReferenceCountUtil.release(msg);来释放引用计数
*/
ctx.fireChannelRead(msg);
}
示例2: channelRead
import io.netty.channel.ChannelHandlerContext; //导入方法依赖的package包/类
@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
if (msg instanceof HttpRequest) {
HttpRequest request = (HttpRequest) msg;
HttpResponse response = new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK, false);
HttpHeaders.setKeepAlive(response, HttpHeaders.isKeepAlive(request));
NettyHttpServletResponse servletResponse = new NettyHttpServletResponse(ctx, servletContext, response);
NettyHttpServletRequest servletRequest = new NettyHttpServletRequest(ctx, servletContext, request, servletResponse, inputStream);
if (HttpHeaders.is100ContinueExpected(request)) {
ctx.write(new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.CONTINUE), ctx.voidPromise());
}
ctx.fireChannelRead(servletRequest);
}
if (msg instanceof HttpContent) {
inputStream.addContent((HttpContent) msg);
}
}
示例3: handleOpen
import io.netty.channel.ChannelHandlerContext; //导入方法依赖的package包/类
protected void handleOpen ( final ChannelHandlerContext ctx, final Frame frame )
{
final String data = frame.getData ().toString ( CHARSET_OPEN );
final StringTokenizer tok = new StringTokenizer ( data, Constants.LF_STRING );
final Map<String, String> offers = new HashMap<> ();
while ( tok.hasMoreTokens () )
{
final String tpl = tok.nextToken ();
final String[] fields = tpl.split ( "=", 2 );
if ( fields.length > 1 )
{
offers.put ( fields[0], fields[1] );
}
else
{
offers.put ( fields[0], fields[0] );
}
}
ctx.fireChannelRead ( new OpenRequest ( frame.getTransactionId (), offers ) );
}
示例4: channelRead
import io.netty.channel.ChannelHandlerContext; //导入方法依赖的package包/类
/**
* 当客户端发送数据到服务器会触发此函数
*
* @param ctx
* @param msg
*/
@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) {
final SocketASK ask = (SocketASK) msg;
if (ask.getForward() >= SYSTEM_FORWARD_CODE.BOUNDARY_VALUE) {
onRequest(ctx, ask);
return;
}
if (ask.getForward() == SYSTEM_FORWARD_CODE.HEARTBEAT_VALUE) {
// forward = 0 表示心跳
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("client id:{}, heartbeat ", ctx.channel().id());
}
ctx.writeAndFlush(ProtoBuffStatic.HEARTBEAT);
ctx.fireChannelRead(ask);
return;
}
systemOption(ctx, ask);
}
示例5: channelRead0
import io.netty.channel.ChannelHandlerContext; //导入方法依赖的package包/类
@Override
protected void channelRead0(ChannelHandlerContext ctx, ByteBuf byteBuf) throws Exception {
while (true) {
if (byteBuf.readableBytes() < FrameSetting.FRAME_HEAD_LENGTH) {
return;
}
if (byteBuf.readByte() != FrameSetting.MAJOR_FRAME_HEAD_1
|| byteBuf.readByte() != FrameSetting.MAJOR_FRAME_HEAD_2) {
return;
}
int groupId = byteBuf.readByte() & 0xFF;
int msgId = byteBuf.readByte() & 0xFF;
int deviceId = byteBuf.readByte() & 0xFF;
int backupMsg = byteBuf.readByte() & 0xFF;
int dataLength = byteBuf.readShort() & 0xFF;
FrameMajorHeader headMsg = new FrameMajorHeader(msgId, groupId, deviceId, dataLength, backupMsg);
ByteBuf subBuf = ctx.alloc().buffer(dataLength);
byteBuf.readBytes(subBuf, dataLength);
ctx.fireChannelRead(new FrameMajor(headMsg, subBuf));
}
}
示例6: channelRead
import io.netty.channel.ChannelHandlerContext; //导入方法依赖的package包/类
@Override
public void channelRead(ChannelHandlerContext ctx, Object msg)
throws Exception {
ProcessData message = (ProcessData) msg;
MessageType rc = MessageType.get((byte) message.getType());
switch (rc) {
case CRAWLER_RESP:
break;
case SHELL_RESP:
break;
case HEART_BEAT_RESP:
break;
default:
logger.error("login refused");
ctx.close();
return;
}
ctx.fireChannelRead(msg);
}
示例7: handle
import io.netty.channel.ChannelHandlerContext; //导入方法依赖的package包/类
@Override
public void handle(ChannelHandlerContext ctx, AmqpConnectionHandler connectionHandler) {
AmqpChannel channel = connectionHandler.getChannel(getChannel());
ctx.fireChannelRead((BlockingTask) () -> {
try {
ShortString usedConsumerTag = channel.consume(queue, consumerTag, exclusive, ctx);
ctx.writeAndFlush(new BasicConsumeOk(getChannel(), usedConsumerTag));
} catch (BrokerException e) {
ctx.writeAndFlush(new ChannelClose(getChannel(),
ChannelException.NOT_ALLOWED,
ShortString.parseString(e.getMessage()),
CLASS_ID,
METHOD_ID));
}
});
}
示例8: channelRead
import io.netty.channel.ChannelHandlerContext; //导入方法依赖的package包/类
@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
if (msg instanceof Heartbeat) {
ctx.fireChannelRead(msg);
} else {
notifyRead = true;
super.channelRead(ctx, msg);
}
}
示例9: channelRead
import io.netty.channel.ChannelHandlerContext; //导入方法依赖的package包/类
@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) {
if(msg instanceof HttpRequest){
HttpRequest request = (HttpRequest) msg;
boolean forceClose = false;
HttpResponse response;
try{
// 获得路由结果
RouteResult<RenderType> routeResult = RouterContext.getRouteResult(request.method(),request.uri());
// 根据路由获得具体的ControllerProxy
ControllerProxy controllerProxy = RouterContext.getControllerProxy(routeResult);
if(controllerProxy == null){
forceClose = true;
response = HttpRenderUtil.getNotFoundResponse();
}else {
// 每一个Controller的方法返回类型约定为Render的实现类
Render render = ProxyInvocation.invoke(controllerProxy);
response = render.response();
}
}catch(Exception e){
routerLogger.error("Server Internal Error,cause:",e);
forceClose = true;
if(e instanceof IllegalArgumentException || e instanceof InvocationException){
response = HttpRenderUtil.getErrorResponse(e.getMessage());
}else{
response = HttpRenderUtil.getServerErrorResponse();
}
}
DataHolder.store(DataHolder.HolderType.FORCE_CLOSE,forceClose);
DataHolder.store(DataHolder.HolderType.RESPONSE,response);
}
/**
* 提交给下一个ChannelHandler去处理
* 并且不需要调用ReferenceCountUtil.release(msg);来释放引用计数
*/
ctx.fireChannelRead(msg);
}
示例10: channelRead
import io.netty.channel.ChannelHandlerContext; //导入方法依赖的package包/类
@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
if (msg instanceof MqttMessage) {
MqttMessage mqtt = (MqttMessage) msg;
if (StringUtils.isBlank(this.clientId) && mqtt.fixedHeader().messageType() == MqttMessageType.CONNECT) {
this.clientId = ((MqttConnectPayload) mqtt.payload()).clientId();
}
if (StringUtils.isNotBlank(this.clientId)) {
this.metrics.measurement(this.clientId, this.brokerId, MessageDirection.IN, mqtt.fixedHeader().messageType());
}
this.metrics.measurement(this.brokerId, MessageDirection.IN, mqtt.fixedHeader().messageType());
}
ctx.fireChannelRead(msg);
}
示例11: channelRead0
import io.netty.channel.ChannelHandlerContext; //导入方法依赖的package包/类
@Override
public void channelRead0(final ChannelHandlerContext ctx, P2pMessage msg) throws InterruptedException {
if (P2pMessageCodes.inRange(msg.getCommand().asByte())) {
logger.trace("P2PHandler invoke: [{}]", msg.getCommand());
}
ethereumListener.trace(String.format("P2PHandler invoke: [%s]", msg.getCommand()));
switch (msg.getCommand()) {
case HELLO:
msgQueue.receivedMessage(msg);
setHandshake((HelloMessage) msg, ctx);
break;
case DISCONNECT:
msgQueue.receivedMessage(msg);
channel.getNodeStatistics().nodeDisconnectedRemote(((DisconnectMessage) msg).getReason());
processDisconnect((DisconnectMessage) msg);
break;
case PING:
logger.trace("Receive PING message, channel {}", channel);
msgQueue.receivedMessage(msg);
ctx.writeAndFlush(PONG_MESSAGE);
break;
case PONG:
logger.trace("Receive PONG message, channel {}", channel);
msgQueue.receivedMessage(msg);
break;
default:
ctx.fireChannelRead(msg);
break;
}
}
示例12: channelRead
import io.netty.channel.ChannelHandlerContext; //导入方法依赖的package包/类
@Override
public void channelRead(final ChannelHandlerContext ctx, final Object msg) throws Exception {
if (msg instanceof LastHttpContent) {
ctx.fireChannelRead(new HttpPipelinedRequest(((LastHttpContent) msg).retain(), readSequence++));
} else {
ctx.fireChannelRead(msg);
}
}
示例13: channelRead
import io.netty.channel.ChannelHandlerContext; //导入方法依赖的package包/类
@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
if (config.isCorsSupportEnabled() && msg instanceof HttpRequest) {
request = (HttpRequest) msg;
if (isPreflightRequest(request)) {
handlePreflight(ctx, request);
return;
}
if (config.isShortCircuit() && !validateOrigin()) {
forbidden(ctx, request);
return;
}
}
ctx.fireChannelRead(msg);
}
示例14: systemOption
import io.netty.channel.ChannelHandlerContext; //导入方法依赖的package包/类
private void systemOption(ChannelHandlerContext ctx, SocketASK ask) {
switch (ask.getBody().getOpcode()) {
case SYSTEM_OPCODE.LOGIN_CODE_VALUE:
login(ctx, ask);
break;
default:
ctx.fireChannelRead(ask);
// nothing to do
}
}
示例15: channelRead
import io.netty.channel.ChannelHandlerContext; //导入方法依赖的package包/类
/**
* 到达业务线程后需要注意msg被释放的问题
*/
@Override
public final void channelRead(ChannelHandlerContext ctx, Object msg)throws Exception
{
if (msg == null)
{
return;
}
boolean release = false;
try {
@SuppressWarnings("unchecked")
M imsg = (M) msg;
Channel channel=ctx.channel();
JConnection connection = findConnection(channel);
if (connection != null) {
listener.messageArrived(connection, imsg);
release = true;
} else {
log.error(ctx.channel() + ":not found NettyConnection Created.");
ctx.fireChannelRead(msg);// 下一个handler继续处理
release = false;
}
} catch (Exception e) {
log.error(e.getMessage(),e);
if(!release)
{//如果出错且还没有被释放
ctx.fireChannelRead(msg);// 下一个handler继续处理
}
} finally {
if (release) {
ReferenceCountUtil.release(msg);
}
}
}