org.jboss.netty.channel.Channel.getRemoteAddress()方法的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(7.1k)|赞(0)|评价(0)|浏览(191)

本文整理了Java中org.jboss.netty.channel.Channel.getRemoteAddress()方法的一些代码示例,展示了Channel.getRemoteAddress()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Channel.getRemoteAddress()方法的具体详情如下:
包路径:org.jboss.netty.channel.Channel
类名称:Channel
方法名:getRemoteAddress

Channel.getRemoteAddress介绍

[英]Returns the remote address where this channel is connected to. The returned SocketAddress is supposed to be down-cast into more concrete type such as InetSocketAddress to retrieve the detailed information.
[中]返回此通道连接到的远程地址。返回的SocketAddress应该向下转换为更具体的类型,如InetSocketAddress,以检索详细信息。

代码示例

代码示例来源:origin: apache/incubator-dubbo

@Override
public InetSocketAddress getRemoteAddress() {
  return (InetSocketAddress) channel.getRemoteAddress();
}

代码示例来源:origin: apache/incubator-dubbo

@Override
public InetSocketAddress getRemoteAddress() {
  return (InetSocketAddress) channel.getRemoteAddress();
}

代码示例来源:origin: alibaba/jstorm

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;
  }
}

代码示例来源:origin: weibocom/motan

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;

  }
}

代码示例来源:origin: alibaba/jstorm

public synchronized boolean remove(Channel channel) {
  channelMap.remove(channel.getRemoteAddress().toString());
  return super.remove(channel);
}

代码示例来源:origin: weibocom/motan

@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());
}

代码示例来源:origin: weibocom/motan

@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());
}

代码示例来源:origin: alibaba/jstorm

@Override
public void channelConnected(ChannelHandlerContext ctx, ChannelStateEvent e) {
  LOG.info("Connection established {}", e.getChannel().getRemoteAddress());
  server.addChannel(e.getChannel());
}

代码示例来源:origin: weibocom/motan

@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);
}

代码示例来源:origin: alibaba/jstorm

@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());
}

代码示例来源:origin: alibaba/jstorm

@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());
}

代码示例来源:origin: apache/incubator-dubbo

@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());
  }
}

代码示例来源:origin: apache/incubator-dubbo

@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());
  }
}

代码示例来源:origin: apache/incubator-dubbo

@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());
  }
}

代码示例来源:origin: apache/incubator-dubbo

@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());
  }
}

代码示例来源:origin: alibaba/jstorm

@Override
public void disconnectChannel(Channel channel) {
  releaseFlowCtrlsForRemoteAddr(channel.getRemoteAddress().toString());
  if (isClosed()) {
    return;
  }
  if (channel == channelRef.get()) {
    setChannel(null);
    reconnect();
  } else {
    closeChannel(channel);
  }
}

代码示例来源:origin: alibaba/jstorm

@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());
  }
}

代码示例来源:origin: weibocom/motan

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;
    }
  }
}

代码示例来源:origin: alibaba/jstorm

@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());
}

代码示例来源:origin: weibocom/motan

@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();
}

相关文章