Java tutorial
/* * Copyright 2015 The RPC Project * * The RPC Project licenses this file to you under the Apache License, * version 2.0 (the "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at: * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations * under the License. */ package io.flood.rpc.network; import io.netty.channel.*; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import static io.flood.common.utils.LogHelper.format; public class MessageHandler extends ChannelHandlerAdapter { private final Logger log = LoggerFactory.getLogger(MessageHandler.class); private SocketWapper wapper; public MessageHandler(SocketWapper socketWapper) { this.wapper = socketWapper; } @Override public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception { wapper.exceptionCaught(ctx, cause); } @Override public void channelActive(ChannelHandlerContext ctx) throws Exception { wapper.channelActive(ctx); } @Override public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception { wapper.userEventTriggered(ctx, evt); } @Override public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { if (msg instanceof NetPackage) { NetPackage netPackage = (NetPackage) msg; log.debug(format(netPackage.sequeue(), "{} RECV:[{}]"), ctx.channel(), netPackage.sequeue()); } wapper.channelRead(ctx, msg); } @Override public void close(ChannelHandlerContext ctx, ChannelPromise promise) throws Exception { wapper.close(ctx, promise); } }