当前位置: 首页>>代码示例>>Java>>正文


Java ExchangeChannel.getRemoteAddress方法代码示例

本文整理汇总了Java中com.alibaba.dubbo.remoting.exchange.ExchangeChannel.getRemoteAddress方法的典型用法代码示例。如果您正苦于以下问题:Java ExchangeChannel.getRemoteAddress方法的具体用法?Java ExchangeChannel.getRemoteAddress怎么用?Java ExchangeChannel.getRemoteAddress使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.alibaba.dubbo.remoting.exchange.ExchangeChannel的用法示例。


在下文中一共展示了ExchangeChannel.getRemoteAddress方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: reply

import com.alibaba.dubbo.remoting.exchange.ExchangeChannel; //导入方法依赖的package包/类
public Object reply(ExchangeChannel channel, Object message) throws RemotingException {
    if (message instanceof Invocation) {
        Invocation inv = (Invocation) message;
        Invoker<?> invoker = getInvoker(channel, inv);
        //如果是callback 需要处理高版本调用低版本的问题
        if (Boolean.TRUE.toString().equals(inv.getAttachments().get(IS_CALLBACK_SERVICE_INVOKE))){
            String methodsStr = invoker.getUrl().getParameters().get("methods");
            boolean hasMethod = false;
            if (methodsStr == null || methodsStr.indexOf(",") == -1){
                hasMethod = inv.getMethodName().equals(methodsStr);
            } else {
                String[] methods = methodsStr.split(",");
                for (String method : methods){
                    if (inv.getMethodName().equals(method)){
                        hasMethod = true;
                        break;
                    }
                }
            }
            if (!hasMethod){
                logger.warn(new IllegalStateException("The methodName "+inv.getMethodName()+" not found in callback service interface ,invoke will be ignored. please update the api interface. url is:" + invoker.getUrl()) +" ,invocation is :"+inv );
                return null;
            }
        }
        RpcContext.getContext().setRemoteAddress(channel.getRemoteAddress());
        return invoker.invoke(inv);
    }
    throw new RemotingException(channel, "Unsupported request: " + message == null ? null : (message.getClass().getName() + ": " + message) + ", channel: consumer: " + channel.getRemoteAddress() + " --> provider: " + channel.getLocalAddress());
}
 
开发者ID:dachengxi,项目名称:EatDubbo,代码行数:30,代码来源:DubboProtocol.java

示例2: reply

import com.alibaba.dubbo.remoting.exchange.ExchangeChannel; //导入方法依赖的package包/类
@Override
public Object reply( ExchangeChannel channel, Object msg ) throws RemotingException {

    if ( msg instanceof Invocation ) {
        Invocation inv = ( Invocation ) msg;
        String serviceName = inv.getAttachments().get(Constants.INTERFACE_KEY);
        String serviceKey = serviceKey( channel.getLocalAddress().getPort(),
                                        serviceName, null, null );
        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:"+ msg);
        }

        RpcContext.getContext().setRemoteAddress(channel.getRemoteAddress());
        return exporter.getInvoker().invoke( inv );

    }

    throw new RemotingException(channel,
                                "Unsupported request: "
                                        + (msg.getClass().getName() + ": " + msg)
                                        + ", channel: consumer: "
                                        + channel.getRemoteAddress()
                                        + " --> provider: "
                                        + channel.getLocalAddress());
}
 
开发者ID:dachengxi,项目名称:EatDubbo,代码行数:37,代码来源:ThriftProtocol.java


注:本文中的com.alibaba.dubbo.remoting.exchange.ExchangeChannel.getRemoteAddress方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。