@Override public InetSocketAddress getRemoteAddress() { return (InetSocketAddress) channel.getRemoteAddress(); }
@Override public InetSocketAddress getRemoteAddress() { return (InetSocketAddress) channel.getRemoteAddress(); }
public synchronized boolean add(Channel channel) { if (channel != null) { if (channel.getRemoteAddress() != null) { channelMap.put(channel.getRemoteAddress().toString(), channel); } return super.add(channel); } else { return false; } }
private String getRemoteIp(Channel channel) { String ip = ""; SocketAddress remote = channel.getRemoteAddress(); if (remote != null) { try { ip = ((InetSocketAddress) remote).getAddress().getHostAddress(); } catch (Exception e) { LoggerUtil.warn("get remoteIp error!dedault will use. msg:" + e.getMessage() + ", remote:" + remote.toString()); } } return ip; } }
public synchronized boolean remove(Channel channel) { channelMap.remove(channel.getRemoteAddress().toString()); return super.remove(channel); }
@Override public void channelDisconnected(ChannelHandlerContext ctx, ChannelStateEvent e) throws Exception { LoggerUtil.info("NettyChannelHandler channelDisconnected: remote=" + ctx.getChannel().getRemoteAddress() + " local=" + ctx.getChannel().getLocalAddress() + " event=" + e.getClass().getSimpleName()); }
@Override public void channelConnected(ChannelHandlerContext ctx, ChannelStateEvent e) throws Exception { LoggerUtil.info("NettyChannelHandler channelConnected: remote=" + ctx.getChannel().getRemoteAddress() + " local=" + ctx.getChannel().getLocalAddress() + " event=" + e.getClass().getSimpleName()); }
@Override public void channelConnected(ChannelHandlerContext ctx, ChannelStateEvent e) { LOG.info("Connection established {}", e.getChannel().getRemoteAddress()); server.addChannel(e.getChannel()); }
@Override public void channelDisconnected(ChannelHandlerContext ctx, ChannelStateEvent e) throws Exception { Channel channel = ctx.getChannel(); String channelKey = getChannelKey((InetSocketAddress) channel.getLocalAddress(), (InetSocketAddress) channel.getRemoteAddress()); channels.remove(channelKey); ctx.sendUpstream(e); }
@Override public void childChannelClosed(ChannelHandlerContext ctx, ChildChannelStateEvent e) throws Exception { super.childChannelClosed(ctx, e); LOG.info("Connection closed {}", e.getChildChannel().getRemoteAddress()); MessageDecoder.removeTransmitHistogram(e.getChildChannel()); }
@Override public void channelClosed(ChannelHandlerContext ctx, ChannelStateEvent e) throws Exception { super.channelClosed(ctx, e); LOG.info("Connection channelClosed {}", e.getChannel().getRemoteAddress()); MessageDecoder.removeTransmitHistogram(e.getChannel()); }
@Override public void channelDisconnected(ChannelHandlerContext ctx, ChannelStateEvent e) throws Exception { NettyChannel channel = NettyChannel.getOrAddChannel(ctx.getChannel(), url, handler); try { channels.remove(NetUtils.toAddressString((InetSocketAddress) ctx.getChannel().getRemoteAddress())); handler.disconnected(channel); } finally { NettyChannel.removeChannelIfDisconnected(ctx.getChannel()); } }
@Override public void channelConnected(ChannelHandlerContext ctx, ChannelStateEvent e) throws Exception { NettyChannel channel = NettyChannel.getOrAddChannel(ctx.getChannel(), url, handler); try { if (channel != null) { channels.put(NetUtils.toAddressString((InetSocketAddress) ctx.getChannel().getRemoteAddress()), channel); } handler.connected(channel); } finally { NettyChannel.removeChannelIfDisconnected(ctx.getChannel()); } }
@Override public void channelDisconnected(ChannelHandlerContext ctx, ChannelStateEvent e) throws Exception { NettyChannel channel = NettyChannel.getOrAddChannel(ctx.getChannel(), url, handler); try { channels.remove(NetUtils.toAddressString((InetSocketAddress) ctx.getChannel().getRemoteAddress())); handler.disconnected(channel); } finally { NettyChannel.removeChannelIfDisconnected(ctx.getChannel()); } }
@Override public void channelConnected(ChannelHandlerContext ctx, ChannelStateEvent e) throws Exception { NettyChannel channel = NettyChannel.getOrAddChannel(ctx.getChannel(), url, handler); try { if (channel != null) { channels.put(NetUtils.toAddressString((InetSocketAddress) ctx.getChannel().getRemoteAddress()), channel); } handler.connected(channel); } finally { NettyChannel.removeChannelIfDisconnected(ctx.getChannel()); } }
@Override public void disconnectChannel(Channel channel) { releaseFlowCtrlsForRemoteAddr(channel.getRemoteAddress().toString()); if (isClosed()) { return; } if (channel == channelRef.get()) { setChannel(null); reconnect(); } else { closeChannel(channel); } }
@Override public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e) { // removeFailureCounter(e.getChannel()); if (e.getChannel() != null) { LOG.info("Channel occur exception {}, cause={}", e.getChannel().getRemoteAddress(), e.getCause()); } server.closeChannel(e.getChannel()); } }
private void checkMaxContext(int dataLength, ChannelHandlerContext ctx, Channel channel, boolean isRequest, long requestId) throws Exception { if (maxContentLength > 0 && dataLength > maxContentLength) { LoggerUtil.warn("NettyDecoder transport data content length over of limit, size: {} > {}. remote={} local={}", dataLength, maxContentLength, ctx.getChannel().getRemoteAddress(), ctx.getChannel().getLocalAddress()); Exception e = new MotanServiceException("NettyDecoder transport data content length over of limit, size: " + dataLength + " > " + maxContentLength); if (isRequest) { Response response = buildExceptionResponse(requestId, e); channel.write(response); throw e; } else { throw e; } } }
@Override public void channelDisconnected(ChannelHandlerContext ctx, ChannelStateEvent e) throws Exception { super.channelDisconnected(ctx, e); LOG.info("Connection channelDisconnected {}", e.getChannel().getRemoteAddress()); MessageDecoder.removeTransmitHistogram(e.getChannel()); server.getChannelGroup().remove(e.getChannel()); }
@Override public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e) throws Exception { LoggerUtil.error("NettyChannelHandler exceptionCaught: remote=" + ctx.getChannel().getRemoteAddress() + " local=" + ctx.getChannel().getLocalAddress() + " event=" + e.getCause(), e.getCause()); ctx.getChannel().close(); }