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

The following examples show how to use org.jboss.netty.channel.Channel#getRemoteAddress() . These examples are extracted from open source projects. 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 want to check out the right sidebar which shows the related API usage.
Example 1
Source Project: jstorm   File: MessageDecoder.java    License: 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 Project: ck   File: NettyAsyncHttpProvider.java    License: 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
@Override
public SocketAddress getRemoteAddress() {
    final Channel channel = this.channel;
    if (channel == null) {
        return null;
    }
    return channel.getRemoteAddress();
}
 
Example 4
Source Project: pinpoint   File: AddressFilterAdaptor.java    License: 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 Project: onos   File: PcepClientImpl.java    License: 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 Project: onos   File: BgpPeerImpl.java    License: 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 Project: jstorm   File: StormChannelGroup.java    License: 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;
    }
}