Java Code Examples for com.alibaba.dubbo.remoting.Channel#getRemoteAddress()

The following examples show how to use com.alibaba.dubbo.remoting.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: AbstractCodec.java    From dubbox with Apache License 2.0 6 votes vote down vote up
protected boolean isClientSide(Channel channel) {
	String side = (String) channel.getAttribute(Constants.SIDE_KEY);
	if ("client".equals(side)) {
		return true;
	} else if ("server".equals(side)) {
		return false;
	} else {
		InetSocketAddress address = channel.getRemoteAddress();
		URL url = channel.getUrl();
		boolean client = url.getPort() == address.getPort()
				&& NetUtils.filterLocalHost(url.getIp()).equals(
						NetUtils.filterLocalHost(address.getAddress()
								.getHostAddress()));
		channel.setAttribute(Constants.SIDE_KEY, client ? "client"
				: "server");
		return client;
	}
}
 
Example 2
Source File: AbstractCodec.java    From dubbox-hystrix with Apache License 2.0 6 votes vote down vote up
protected boolean isClientSide(Channel channel) {
	String side = (String) channel.getAttribute(Constants.SIDE_KEY);
	if ("client".equals(side)) {
		return true;
	} else if ("server".equals(side)) {
		return false;
	} else {
		InetSocketAddress address = channel.getRemoteAddress();
		URL url = channel.getUrl();
		boolean client = url.getPort() == address.getPort()
				&& NetUtils.filterLocalHost(url.getIp()).equals(
						NetUtils.filterLocalHost(address.getAddress()
								.getHostAddress()));
		channel.setAttribute(Constants.SIDE_KEY, client ? "client"
				: "server");
		return client;
	}
}
 
Example 3
Source File: DeprecatedTelnetCodec.java    From dubbo-2.6.5 with Apache License 2.0 6 votes vote down vote up
protected boolean isClientSide(Channel channel) {
    String side = (String) channel.getAttribute(Constants.SIDE_KEY);
    if ("client".equals(side)) {
        return true;
    } else if ("server".equals(side)) {
        return false;
    } else {
        InetSocketAddress address = channel.getRemoteAddress();
        URL url = channel.getUrl();
        boolean client = url.getPort() == address.getPort()
                && NetUtils.filterLocalHost(url.getIp()).equals(
                NetUtils.filterLocalHost(address.getAddress()
                        .getHostAddress()));
        channel.setAttribute(Constants.SIDE_KEY, client ? "client"
                : "server");
        return client;
    }
}
 
Example 4
Source File: DubboProtocol.java    From dubbo3 with Apache License 2.0 6 votes vote down vote up
Invoker<?> getInvoker(Channel channel, Invocation inv) throws RemotingException {
    boolean isCallBackServiceInvoke;
    boolean isStubServiceInvoke;
    int port = channel.getLocalAddress().getPort();
    String path = inv.getAttachments().get(Constants.PATH_KEY);
    //如果是客户端的回调服务.
    isStubServiceInvoke = Boolean.TRUE.toString().equals(inv.getAttachments().get(Constants.STUB_EVENT_KEY));
    if (isStubServiceInvoke) {
        port = channel.getRemoteAddress().getPort();
    }
    //callback
    isCallBackServiceInvoke = isClientSide(channel) && !isStubServiceInvoke;
    if (isCallBackServiceInvoke) {
        path = inv.getAttachments().get(Constants.PATH_KEY) + "." + inv.getAttachments().get(Constants.CALLBACK_SERVICE_KEY);
        inv.getAttachments().put(IS_CALLBACK_SERVICE_INVOKE, Boolean.TRUE.toString());
    }
    String serviceKey = serviceKey(port, path, inv.getAttachments().get(Constants.VERSION_KEY), inv.getAttachments().get(Constants.GROUP_KEY));

    DubboExporter<?> exporter = (DubboExporter<?>) exporterMap.get(serviceKey);

    if (exporter == null)
        throw new RemotingException(channel, "Not found exported service: " + serviceKey + " in " + exporterMap.keySet() + ", may be version or group mismatch " + ", channel: consumer: " + channel.getRemoteAddress() + " --> provider: " + channel.getLocalAddress() + ", message:" + inv);

    return exporter.getInvoker();
}
 
Example 5
Source File: DubboProtocol.java    From dubbox with Apache License 2.0 6 votes vote down vote up
Invoker<?> getInvoker(Channel channel, Invocation inv) throws RemotingException{
    boolean isCallBackServiceInvoke = false;
    boolean isStubServiceInvoke = false;
    int port = channel.getLocalAddress().getPort();
    String path = inv.getAttachments().get(Constants.PATH_KEY);
    //如果是客户端的回调服务.
    isStubServiceInvoke = Boolean.TRUE.toString().equals(inv.getAttachments().get(Constants.STUB_EVENT_KEY));
    if (isStubServiceInvoke){
        port = channel.getRemoteAddress().getPort();
    }
    //callback
    isCallBackServiceInvoke = isClientSide(channel) && !isStubServiceInvoke;
    if(isCallBackServiceInvoke){
        path = inv.getAttachments().get(Constants.PATH_KEY)+"."+inv.getAttachments().get(Constants.CALLBACK_SERVICE_KEY);
        inv.getAttachments().put(IS_CALLBACK_SERVICE_INVOKE, Boolean.TRUE.toString());
    }
    String serviceKey = serviceKey(port, path, inv.getAttachments().get(Constants.VERSION_KEY), inv.getAttachments().get(Constants.GROUP_KEY));

    DubboExporter<?> exporter = (DubboExporter<?>) exporterMap.get(serviceKey);
    
    if (exporter == null)
        throw new RemotingException(channel, "Not found exported service: " + serviceKey + " in " + exporterMap.keySet() + ", may be version or group mismatch " + ", channel: consumer: " + channel.getRemoteAddress() + " --> provider: " + channel.getLocalAddress() + ", message:" + inv);

    return exporter.getInvoker();
}
 
Example 6
Source File: DubboProtocol.java    From dubbox-hystrix with Apache License 2.0 6 votes vote down vote up
Invoker<?> getInvoker(Channel channel, Invocation inv) throws RemotingException{
    boolean isCallBackServiceInvoke = false;
    boolean isStubServiceInvoke = false;
    int port = channel.getLocalAddress().getPort();
    String path = inv.getAttachments().get(Constants.PATH_KEY);
    //如果是客户端的回调服务.
    isStubServiceInvoke = Boolean.TRUE.toString().equals(inv.getAttachments().get(Constants.STUB_EVENT_KEY));
    if (isStubServiceInvoke){
        port = channel.getRemoteAddress().getPort();
    }
    //callback
    isCallBackServiceInvoke = isClientSide(channel) && !isStubServiceInvoke;
    if(isCallBackServiceInvoke){
        path = inv.getAttachments().get(Constants.PATH_KEY)+"."+inv.getAttachments().get(Constants.CALLBACK_SERVICE_KEY);
        inv.getAttachments().put(IS_CALLBACK_SERVICE_INVOKE, Boolean.TRUE.toString());
    }
    String serviceKey = serviceKey(port, path, inv.getAttachments().get(Constants.VERSION_KEY), inv.getAttachments().get(Constants.GROUP_KEY));

    DubboExporter<?> exporter = (DubboExporter<?>) exporterMap.get(serviceKey);
    
    if (exporter == null)
        throw new RemotingException(channel, "Not found exported service: " + serviceKey + " in " + exporterMap.keySet() + ", may be version or group mismatch " + ", channel: consumer: " + channel.getRemoteAddress() + " --> provider: " + channel.getLocalAddress() + ", message:" + inv);

    return exporter.getInvoker();
}
 
Example 7
Source File: AbstractCodec.java    From dubbo3 with Apache License 2.0 6 votes vote down vote up
protected boolean isClientSide(Channel channel) {
	String side = (String) channel.getAttribute(Constants.SIDE_KEY);
	if ("client".equals(side)) {
		return true;
	} else if ("server".equals(side)) {
		return false;
	} else {
		InetSocketAddress address = channel.getRemoteAddress();
		URL url = channel.getUrl();
		boolean client = url.getPort() == address.getPort()
				&& NetUtils.filterLocalHost(url.getIp()).equals(
						NetUtils.filterLocalHost(address.getAddress()
								.getHostAddress()));
		channel.setAttribute(Constants.SIDE_KEY, client ? "client"
				: "server");
		return client;
	}
}
 
Example 8
Source File: DeprecatedTelnetCodec.java    From dubbox with Apache License 2.0 6 votes vote down vote up
protected boolean isClientSide(Channel channel) {
    String side = (String) channel.getAttribute(Constants.SIDE_KEY);
    if ("client".equals(side)) {
        return true;
    } else if ("server".equals(side)) {
        return false;
    } else {
        InetSocketAddress address = channel.getRemoteAddress();
        URL url = channel.getUrl();
        boolean client = url.getPort() == address.getPort()
            && NetUtils.filterLocalHost(url.getIp()).equals(
            NetUtils.filterLocalHost(address.getAddress()
                                         .getHostAddress()));
        channel.setAttribute(Constants.SIDE_KEY, client ? "client"
            : "server");
        return client;
    }
}
 
Example 9
Source File: DubboProtocol.java    From dubbo3 with Apache License 2.0 5 votes vote down vote up
private boolean isClientSide(Channel channel) {
    InetSocketAddress address = channel.getRemoteAddress();
    URL url = channel.getUrl();
    return url.getPort() == address.getPort() &&
            NetUtils.filterLocalHost(channel.getUrl().getIp())
                    .equals(NetUtils.filterLocalHost(address.getAddress().getHostAddress()));
}
 
Example 10
Source File: HeaderExchangeHandler.java    From dubbox with Apache License 2.0 5 votes vote down vote up
private static boolean isClientSide(Channel channel) {
    InetSocketAddress address = channel.getRemoteAddress();
    URL url = channel.getUrl();
    return url.getPort() == address.getPort() && 
                NetUtils.filterLocalHost(url.getIp())
                .equals(NetUtils.filterLocalHost(address.getAddress().getHostAddress()));
}
 
Example 11
Source File: HeaderExchangeHandler.java    From dubbox-hystrix with Apache License 2.0 5 votes vote down vote up
private static boolean isClientSide(Channel channel) {
    InetSocketAddress address = channel.getRemoteAddress();
    URL url = channel.getUrl();
    return url.getPort() == address.getPort() && 
                NetUtils.filterLocalHost(url.getIp())
                .equals(NetUtils.filterLocalHost(address.getAddress().getHostAddress()));
}
 
Example 12
Source File: HeaderExchangeHandler.java    From dubbox with Apache License 2.0 5 votes vote down vote up
public void sent(Channel channel, Object message) throws RemotingException {
    Throwable exception = null;
    try {
        channel.setAttribute(KEY_WRITE_TIMESTAMP, System.currentTimeMillis());
        ExchangeChannel exchangeChannel = HeaderExchangeChannel.getOrAddChannel(channel);
        try {
            handler.sent(exchangeChannel, message);
        } finally {
            HeaderExchangeChannel.removeChannelIfDisconnected(channel);
        }
    } catch (Throwable t) {
        exception = t;
    }
    if (message instanceof Request) {
        Request request = (Request) message;
        DefaultFuture.sent(channel, request);
    }
    if (exception != null) {
        if (exception instanceof RuntimeException) {
            throw (RuntimeException) exception;
        } else if (exception instanceof RemotingException) {
            throw (RemotingException) exception;
        } else {
            throw new RemotingException(channel.getLocalAddress(), channel.getRemoteAddress(),
                                        exception.getMessage(), exception);
        }
    }
}
 
Example 13
Source File: HeaderExchangeHandler.java    From dubbox with Apache License 2.0 5 votes vote down vote up
private static boolean isClientSide(Channel channel) {
    InetSocketAddress address = channel.getRemoteAddress();
    URL url = channel.getUrl();
    return url.getPort() == address.getPort() && 
                NetUtils.filterLocalHost(url.getIp())
                .equals(NetUtils.filterLocalHost(address.getAddress().getHostAddress()));
}
 
Example 14
Source File: HeaderExchangeHandler.java    From dubbox with Apache License 2.0 5 votes vote down vote up
public void sent(Channel channel, Object message) throws RemotingException {
    Throwable exception = null;
    try {
        channel.setAttribute(KEY_WRITE_TIMESTAMP, System.currentTimeMillis());
        ExchangeChannel exchangeChannel = HeaderExchangeChannel.getOrAddChannel(channel);
        try {
            handler.sent(exchangeChannel, message);
        } finally {
            HeaderExchangeChannel.removeChannelIfDisconnected(channel);
        }
    } catch (Throwable t) {
        exception = t;
    }
    if (message instanceof Request) {
        Request request = (Request) message;
        DefaultFuture.sent(channel, request);
    }
    if (exception != null) {
        if (exception instanceof RuntimeException) {
            throw (RuntimeException) exception;
        } else if (exception instanceof RemotingException) {
            throw (RemotingException) exception;
        } else {
            throw new RemotingException(channel.getLocalAddress(), channel.getRemoteAddress(),
                                        exception.getMessage(), exception);
        }
    }
}
 
Example 15
Source File: HeaderExchangeHandler.java    From dubbo3 with Apache License 2.0 5 votes vote down vote up
private static boolean isClientSide(Channel channel) {
    InetSocketAddress address = channel.getRemoteAddress();
    URL url = channel.getUrl();
    return url.getPort() == address.getPort() && 
                NetUtils.filterLocalHost(url.getIp())
                .equals(NetUtils.filterLocalHost(address.getAddress().getHostAddress()));
}
 
Example 16
Source File: HeaderExchangeHandler.java    From dubbox with Apache License 2.0 5 votes vote down vote up
private static boolean isClientSide(Channel channel) {
    InetSocketAddress address = channel.getRemoteAddress();
    URL url = channel.getUrl();
    return url.getPort() == address.getPort() && 
                NetUtils.filterLocalHost(url.getIp())
                .equals(NetUtils.filterLocalHost(address.getAddress().getHostAddress()));
}
 
Example 17
Source File: DubboProtocol.java    From dubbox with Apache License 2.0 5 votes vote down vote up
private boolean isClientSide(Channel channel) {
    InetSocketAddress address = channel.getRemoteAddress();
    URL url = channel.getUrl();
    return url.getPort() == address.getPort() && 
                NetUtils.filterLocalHost(channel.getUrl().getIp())
                .equals(NetUtils.filterLocalHost(address.getAddress().getHostAddress()));
}
 
Example 18
Source File: AbstractClient.java    From dubbox with Apache License 2.0 4 votes vote down vote up
public InetSocketAddress getRemoteAddress() {
    Channel channel = getChannel();
    if (channel == null)
        return getUrl().toInetSocketAddress();
    return channel.getRemoteAddress();
}
 
Example 19
Source File: AbstractClient.java    From dubbox-hystrix with Apache License 2.0 4 votes vote down vote up
public InetSocketAddress getRemoteAddress() {
    Channel channel = getChannel();
    if (channel == null)
        return getUrl().toInetSocketAddress();
    return channel.getRemoteAddress();
}
 
Example 20
Source File: AbstractClient.java    From dubbox with Apache License 2.0 4 votes vote down vote up
public InetSocketAddress getRemoteAddress() {
    Channel channel = getChannel();
    if (channel == null)
        return getUrl().toInetSocketAddress();
    return channel.getRemoteAddress();
}