@Override public void connect(ChannelHandlerContext ctx, SocketAddress remoteAddress, SocketAddress localAddress, ChannelPromise promise) throws Exception { final String local = localAddress == null ? "UNKNOW" : localAddress.toString(); final String remote = remoteAddress == null ? "UNKNOW" : remoteAddress.toString(); LOGGER.info("CLIENT : CONNECT {} => {}", local, remote); super.connect(ctx, remoteAddress, localAddress, promise); if (channelEventListener != null) { assert remoteAddress != null; putRemotingEvent(new RemotingEvent(RemotingEventType.CONNECT, remoteAddress .toString(), new NettyChannel(ctx))); } }
RemotingEvent event = this.eventQueue.poll(3000, TimeUnit.MILLISECONDS); if (event != null) { switch (event.getType()) { case ALL_IDLE: listener.onChannelIdle(IdleState.ALL_IDLE, event.getRemoteAddr(), event.getChannel()); break; case WRITER_IDLE: listener.onChannelIdle(IdleState.WRITER_IDLE, event.getRemoteAddr(), event.getChannel()); break; case READER_IDLE: listener.onChannelIdle(IdleState.READER_IDLE, event.getRemoteAddr(), event.getChannel()); break; case CLOSE: listener.onChannelClose(event.getRemoteAddr(), event.getChannel()); break; case CONNECT: listener.onChannelConnect(event.getRemoteAddr(), event.getChannel()); break; case EXCEPTION: listener.onChannelException(event.getRemoteAddr(), event.getChannel()); break; default:
public void putRemotingEvent(final RemotingEvent event) { if (this.eventQueue.size() <= MaxSize) { this.eventQueue.add(event); } else { LOGGER.warn("event queue size[{}] enough, so drop this event {}", this.eventQueue.size(), event.toString()); } }
@Override public void connect(ChannelHandlerContext ctx, SocketAddress remoteAddress, SocketAddress localAddress, ChannelPromise promise) throws Exception { final String local = localAddress == null ? "UNKNOW" : localAddress.toString(); final String remote = remoteAddress == null ? "UNKNOW" : remoteAddress.toString(); LOGGER.info("CLIENT : CONNECT {} => {}", local, remote); super.connect(ctx, remoteAddress, localAddress, promise); if (channelEventListener != null) { assert remoteAddress != null; putRemotingEvent(new RemotingEvent(RemotingEventType.CONNECT, remoteAddress .toString(), new NettyChannel(ctx))); } }
RemotingEvent event = this.eventQueue.poll(3000, TimeUnit.MILLISECONDS); if (event != null) { switch (event.getType()) { case ALL_IDLE: listener.onChannelIdle(IdleState.ALL_IDLE, event.getRemoteAddr(), event.getChannel()); break; case WRITER_IDLE: listener.onChannelIdle(IdleState.WRITER_IDLE, event.getRemoteAddr(), event.getChannel()); break; case READER_IDLE: listener.onChannelIdle(IdleState.READER_IDLE, event.getRemoteAddr(), event.getChannel()); break; case CLOSE: listener.onChannelClose(event.getRemoteAddr(), event.getChannel()); break; case CONNECT: listener.onChannelConnect(event.getRemoteAddr(), event.getChannel()); break; case EXCEPTION: listener.onChannelException(event.getRemoteAddr(), event.getChannel()); break; default:
public void putRemotingEvent(final RemotingEvent event) { if (this.eventQueue.size() <= MaxSize) { this.eventQueue.add(event); } else { LOGGER.warn("event queue size[{}] enough, so drop this event {}", this.eventQueue.size(), event.toString()); } }
@Override public void sessionOpened(IoSession session) throws Exception { Channel channel = new MinaChannel(session); final String remoteAddress = RemotingHelper.parseChannelRemoteAddr(channel); LOGGER.info("{}: sessionOpened, the channel[{}]", sideType, remoteAddress); if (remoting.getChannelEventListener() != null) { remoting.putRemotingEvent(new RemotingEvent(RemotingEventType.CONNECT, remoteAddress, channel)); } }
RemotingEvent event = this.eventQueue.poll(3000, TimeUnit.MILLISECONDS); if (event != null) { switch (event.getType()) { case ALL_IDLE: listener.onChannelIdle(IdleState.ALL_IDLE, event.getRemoteAddr(), event.getChannel()); break; case WRITER_IDLE: listener.onChannelIdle(IdleState.WRITER_IDLE, event.getRemoteAddr(), event.getChannel()); break; case READER_IDLE: listener.onChannelIdle(IdleState.READER_IDLE, event.getRemoteAddr(), event.getChannel()); break; case CLOSE: listener.onChannelClose(event.getRemoteAddr(), event.getChannel()); break; case CONNECT: listener.onChannelConnect(event.getRemoteAddr(), event.getChannel()); break; case EXCEPTION: listener.onChannelException(event.getRemoteAddr(), event.getChannel()); break; default:
public void putRemotingEvent(final RemotingEvent event) { if (this.eventQueue.size() <= MaxSize) { this.eventQueue.add(event); } else { LOGGER.warn("event queue size[{}] enough, so drop this event {}", this.eventQueue.size(), event.toString()); } }
@Override public void channelInactive(ChannelHandlerContext ctx) throws Exception { com.github.ltsopensource.remoting.Channel channel = new NettyChannel(ctx); final String remoteAddress = RemotingHelper.parseChannelRemoteAddr(channel); LOGGER.info("SERVER: channelInactive, the channel[{}]", remoteAddress); super.channelInactive(ctx); if (channelEventListener != null) { putRemotingEvent(new RemotingEvent(RemotingEventType.CLOSE, remoteAddress, channel)); } }
@Override public void channelActive(ChannelHandlerContext ctx) throws Exception { com.github.ltsopensource.remoting.Channel channel = new NettyChannel(ctx); final String remoteAddress = RemotingHelper.parseChannelRemoteAddr(channel); LOGGER.info("SERVER: channelActive, the channel[{}]", remoteAddress); super.channelActive(ctx); if (channelEventListener != null) { putRemotingEvent(new RemotingEvent(RemotingEventType.CONNECT, remoteAddress, channel)); } }
@Override public void channelInactive(ChannelHandlerContext ctx) throws Exception { com.github.ltsopensource.remoting.Channel channel = new NettyChannel(ctx); final String remoteAddress = RemotingHelper.parseChannelRemoteAddr(channel); LOGGER.info("SERVER: channelInactive, the channel[{}]", remoteAddress); super.channelInactive(ctx); if (channelEventListener != null) { putRemotingEvent(new RemotingEvent(RemotingEventType.CLOSE, remoteAddress, channel)); } }
@Override public void sessionOpened(IoSession session) throws Exception { Channel channel = new MinaChannel(session); final String remoteAddress = RemotingHelper.parseChannelRemoteAddr(channel); LOGGER.info("{}: sessionOpened, the channel[{}]", sideType, remoteAddress); if (remoting.getChannelEventListener() != null) { remoting.putRemotingEvent(new RemotingEvent(RemotingEventType.CONNECT, remoteAddress, channel)); } }
@Override public void sessionClosed(IoSession session) throws Exception { com.github.ltsopensource.remoting.Channel channel = new MinaChannel(session); final String remoteAddress = RemotingHelper.parseChannelRemoteAddr(channel); LOGGER.info("{}: sessionClosed, the channel[{}]", sideType, remoteAddress); if (remoting.getChannelEventListener() != null) { remoting.putRemotingEvent(new RemotingEvent(RemotingEventType.CLOSE, remoteAddress, channel)); } }
@Override public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception { com.github.ltsopensource.remoting.Channel channel = new NettyChannel(ctx); final String remoteAddress = RemotingHelper.parseChannelRemoteAddr(channel); LOGGER.warn("SERVER: exceptionCaught {}", remoteAddress, cause); if (channelEventListener != null) { putRemotingEvent(new RemotingEvent(RemotingEventType.EXCEPTION, remoteAddress, channel)); } RemotingHelper.closeChannel(channel); } }
@Override public void channelConnected(NioChannel channel) { Channel ch = new LtsChannel(channel); final String remoteAddress = RemotingHelper.parseChannelRemoteAddr(ch); LOGGER.info("{}: channelConnected, the channel[{}]", sideType, remoteAddress); if (remoting.getChannelEventListener() != null) { remoting.putRemotingEvent(new RemotingEvent(RemotingEventType.CONNECT, remoteAddress, ch)); } }
@Override public void sessionClosed(IoSession session) throws Exception { com.github.ltsopensource.remoting.Channel channel = new MinaChannel(session); final String remoteAddress = RemotingHelper.parseChannelRemoteAddr(channel); LOGGER.info("{}: sessionClosed, the channel[{}]", sideType, remoteAddress); if (remoting.getChannelEventListener() != null) { remoting.putRemotingEvent(new RemotingEvent(RemotingEventType.CLOSE, remoteAddress, channel)); } }
@Override public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception { com.github.ltsopensource.remoting.Channel channel = new NettyChannel(ctx); final String remoteAddress = RemotingHelper.parseChannelRemoteAddr(channel); LOGGER.warn("SERVER: exceptionCaught {}", remoteAddress, cause); if (channelEventListener != null) { putRemotingEvent(new RemotingEvent(RemotingEventType.EXCEPTION, remoteAddress, channel)); } RemotingHelper.closeChannel(channel); } }
@Override public void channelActive(ChannelHandlerContext ctx) throws Exception { com.github.ltsopensource.remoting.Channel channel = new NettyChannel(ctx); final String remoteAddress = RemotingHelper.parseChannelRemoteAddr(channel); LOGGER.info("SERVER: channelActive, the channel[{}]", remoteAddress); super.channelActive(ctx); if (channelEventListener != null) { putRemotingEvent(new RemotingEvent(RemotingEventType.CONNECT, remoteAddress, channel)); } }
@Override public void channelConnected(NioChannel channel) { Channel ch = new LtsChannel(channel); final String remoteAddress = RemotingHelper.parseChannelRemoteAddr(ch); LOGGER.info("{}: channelConnected, the channel[{}]", sideType, remoteAddress); if (remoting.getChannelEventListener() != null) { remoting.putRemotingEvent(new RemotingEvent(RemotingEventType.CONNECT, remoteAddress, ch)); } }