Java Code Examples for org.jboss.netty.channel.Channel#getRemoteAddress()

The following examples show how to use org.jboss.netty.channel.Channel#getRemoteAddress() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MessageDecoder.java    From jstorm with Apache License 2.0 6 votes vote down vote up
public AsmHistogram getTransmitHistogram(Channel channel, int clientPort) {
    AsmHistogram netTransTime = networkTransmitTimeMap.get(channel);
    if (netTransTime == null) {
        InetSocketAddress sockAddr = (InetSocketAddress) (channel.getRemoteAddress());

        String nettyConnection = NettyConnection.mkString(sockAddr.getAddress().getHostAddress(), clientPort, localIp, localPort);
        netTransTime = (AsmHistogram) JStormMetrics.registerNettyMetric(
                MetricUtils.nettyMetricName(AsmMetric.mkName(MetricDef.NETTY_SRV_MSG_TRANS_TIME, nettyConnection), MetricType.HISTOGRAM),
                new AsmHistogram());

        networkTransmitTimeMap.put(channel, netTransTime);
        transmitNameMap.put(channel, nettyConnection);
        LOG.info("Register transmit histogram of {}, channel {}", nettyConnection, channel);
    }

    return netTransTime;
}
 
Example 2
Source File: NettyAsyncHttpProvider.java    From ck with Apache License 2.0 5 votes vote down vote up
private final static <T> void executeRequest(final Channel channel,
                                             final AsyncHttpClientConfig config,
                                             final NettyResponseFuture<T> future,
                                             final HttpRequest nettyRequest) throws ConnectException {

	if (!channel.isConnected()){
		String url = channel.getRemoteAddress() != null ? channel.getRemoteAddress().toString() : null;
		if (url == null) {
			try {
				url = future.getURI().toString();
			} catch (MalformedURLException e) {
				log.debug(e);
			}
		}
		throw new ConnectException(String.format("Connection refused to %s", url));
	}

	channel.getPipeline().getContext(NettyAsyncHttpProvider.class).setAttachment(future);
	channel.write(nettyRequest);

	try{
		future.setReaperFuture(config.reaper().schedule(new Callable<Object>() {
			public Object call() {
				if (!future.isDone() && !future.isCancelled()) {
					future.abort(new TimeoutException());
					channel.getPipeline().getContext(NettyAsyncHttpProvider.class).setAttachment(ClosedEvent.class);
				}
				return null;
			}

		}, config.getRequestTimeoutInMs(), TimeUnit.MILLISECONDS));
	} catch (RejectedExecutionException ex){
		future.abort(ex);
	}
}
 
Example 3
Source File: DefaultPinpointClientHandler.java    From pinpoint with Apache License 2.0 5 votes vote down vote up
@Override
public SocketAddress getRemoteAddress() {
    final Channel channel = this.channel;
    if (channel == null) {
        return null;
    }
    return channel.getRemoteAddress();
}
 
Example 4
Source File: AddressFilterAdaptor.java    From pinpoint with Apache License 2.0 5 votes vote down vote up
@Override
public boolean accept(Channel channel) {
    final InetSocketAddress remoteAddress = (InetSocketAddress) channel.getRemoteAddress();
    if (remoteAddress == null) {
        return true;
    }
    InetAddress address = remoteAddress.getAddress();
    return filter.accept(address);
}
 
Example 5
Source File: PcepClientImpl.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
public final void setChannel(Channel channel) {
    this.channel = channel;
    final SocketAddress address = channel.getRemoteAddress();
    if (address instanceof InetSocketAddress) {
        final InetSocketAddress inetAddress = (InetSocketAddress) address;
        final IpAddress ipAddress = IpAddress.valueOf(inetAddress.getAddress());
        if (ipAddress.isIp4()) {
            channelId = ipAddress.toString() + ':' + inetAddress.getPort();
        } else {
            channelId = '[' + ipAddress.toString() + "]:" + inetAddress.getPort();
        }
    }
}
 
Example 6
Source File: BgpPeerImpl.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
public final void setChannel(Channel channel) {
    this.channel = channel;
    final SocketAddress address = channel.getRemoteAddress();
    if (address instanceof InetSocketAddress) {
        final InetSocketAddress inetAddress = (InetSocketAddress) address;
        final IpAddress ipAddress = IpAddress.valueOf(inetAddress.getAddress());
        if (ipAddress.isIp4()) {
            channelId = ipAddress.toString() + ':' + inetAddress.getPort();
        } else {
            channelId = '[' + ipAddress.toString() + "]:" + inetAddress.getPort();
        }
    }
}
 
Example 7
Source File: StormChannelGroup.java    From jstorm with Apache License 2.0 5 votes vote down vote up
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;
    }
}