當前位置: 首頁>>代碼示例>>Java>>正文


Java ChannelHandlerContext.fireChannelRead方法代碼示例

本文整理匯總了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);
}
 
開發者ID:all4you,項目名稱:redant,代碼行數:17,代碼來源:DataStorer.java

示例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);
    }
}
 
開發者ID:geeker-lait,項目名稱:tasfe-framework,代碼行數:18,代碼來源:ServletContentHandler.java

示例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 ) );
}
 
開發者ID:eclipse,項目名稱:neoscada,代碼行數:24,代碼來源:FrameProcessor.java

示例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);
}
 
開發者ID:freedompy,項目名稱:commelina,代碼行數:26,代碼來源:ChannelInboundHandlerRouterAdapter.java

示例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));
    }
}
 
開發者ID:bitkylin,項目名稱:ClusterDeviceControlPlatform,代碼行數:22,代碼來源:FrameRecognitionInBoundHandler.java

示例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);
}
 
開發者ID:xiongbeer,項目名稱:Cobweb,代碼行數:20,代碼來源:LoginAuthReqHandler.java

示例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));
        }
    });
}
 
開發者ID:wso2,項目名稱:message-broker,代碼行數:17,代碼來源:BasicConsume.java

示例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);
    }
}
 
開發者ID:hekate-io,項目名稱:hekate,代碼行數:11,代碼來源:NettyClientIdleStateHandler.java

示例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);
}
 
開發者ID:all4you,項目名稱:redant,代碼行數:38,代碼來源:ControllerDispatcher.java

示例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);
}
 
開發者ID:12315jack,項目名稱:j1st-mqtt,代碼行數:15,代碼來源:MessageMetricsHandler.java

示例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;
    }
}
 
開發者ID:rsksmart,項目名稱:rskj,代碼行數:34,代碼來源:P2pHandler.java

示例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);
    }
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:9,代碼來源:HttpPipeliningHandler.java

示例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);
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:16,代碼來源:Netty4CorsHandler.java

示例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
    }
}
 
開發者ID:freedompy,項目名稱:commelina,代碼行數:11,代碼來源:ChannelInboundHandlerRouterAdapter.java

示例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);
		}
	}
}
 
開發者ID:juebanlin,項目名稱:util4j,代碼行數:37,代碼來源:AbstractListenerHandler.java


注:本文中的io.netty.channel.ChannelHandlerContext.fireChannelRead方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。