Search in sources :

Example 1 with ConsumerModel

use of org.apache.dubbo.rpc.model.ConsumerModel in project dubbo by alibaba.

the class FutureFilter method getAsyncMethodInfo.

private AsyncMethodInfo getAsyncMethodInfo(Invoker<?> invoker, Invocation invocation) {
    AsyncMethodInfo asyncMethodInfo = (AsyncMethodInfo) invocation.get(ASYNC_METHOD_INFO);
    if (asyncMethodInfo != null) {
        return asyncMethodInfo;
    }
    ConsumerModel consumerModel = ApplicationModel.getConsumerModel(invoker.getUrl().getServiceKey());
    if (consumerModel == null) {
        return null;
    }
    String methodName = invocation.getMethodName();
    if (methodName.equals($INVOKE)) {
        methodName = (String) invocation.getArguments()[0];
    }
    return consumerModel.getAsyncInfo(methodName);
}
Also used : ConsumerModel(org.apache.dubbo.rpc.model.ConsumerModel) AsyncMethodInfo(org.apache.dubbo.rpc.model.AsyncMethodInfo)

Example 2 with ConsumerModel

use of org.apache.dubbo.rpc.model.ConsumerModel in project dubbo by alibaba.

the class ListTelnetHandler method printAllReferredServices.

private void printAllReferredServices(StringBuilder buf, boolean detail) {
    List<ConsumerModel> consumerModels = serviceRepository.getReferredServices();
    if (!consumerModels.isEmpty()) {
        buf.append("CONSUMER:\r\n");
    }
    for (ConsumerModel consumer : consumerModels) {
        buf.append(consumer.getServiceKey());
        if (detail) {
            buf.append(" -> ");
            buf.append(" addresses: ");
            buf.append(ServiceCheckUtils.getConsumerAddressNum(consumer));
        }
        buf.append("\r\n");
    }
}
Also used : ConsumerModel(org.apache.dubbo.rpc.model.ConsumerModel)

Example 3 with ConsumerModel

use of org.apache.dubbo.rpc.model.ConsumerModel in project dubbo by alibaba.

the class Ls method listConsumer.

public String listConsumer() {
    StringBuilder stringBuilder = new StringBuilder();
    stringBuilder.append("As Consumer side:" + System.lineSeparator());
    Collection<ConsumerModel> consumerModelList = ApplicationModel.allConsumerModels();
    TTable tTable = new TTable(new TTable.ColumnDefine[] { new TTable.ColumnDefine(TTable.Align.MIDDLE), new TTable.ColumnDefine(TTable.Align.MIDDLE) });
    // Header
    tTable.addRow("Consumer Service Name", "NUM");
    // TODO to calculate consumerAddressNum
    for (ConsumerModel consumerModel : consumerModelList) {
        tTable.addRow(consumerModel.getServiceKey(), ServiceCheckUtils.getConsumerAddressNum(consumerModel));
    }
    stringBuilder.append(tTable.rendering());
    return stringBuilder.toString();
}
Also used : ConsumerModel(org.apache.dubbo.rpc.model.ConsumerModel) TTable(org.apache.dubbo.qos.textui.TTable)

Example 4 with ConsumerModel

use of org.apache.dubbo.rpc.model.ConsumerModel in project dubbo by alibaba.

the class ReferenceConfig method init.

public synchronized void init() {
    if (initialized) {
        return;
    }
    if (bootstrap == null) {
        bootstrap = DubboBootstrap.getInstance();
        // compatible with api call.
        if (null != this.getRegistries()) {
            bootstrap.registries(this.getRegistries());
        }
        bootstrap.initialize();
    }
    checkAndUpdateSubConfigs();
    checkStubAndLocal(interfaceClass);
    ConfigValidationUtils.checkMock(interfaceClass, this);
    Map<String, String> map = new HashMap<String, String>();
    map.put(SIDE_KEY, CONSUMER_SIDE);
    ReferenceConfigBase.appendRuntimeParameters(map);
    if (!ProtocolUtils.isGeneric(generic)) {
        String revision = Version.getVersion(interfaceClass, version);
        if (revision != null && revision.length() > 0) {
            map.put(REVISION_KEY, revision);
        }
        String[] methods = Wrapper.getWrapper(interfaceClass).getMethodNames();
        if (methods.length == 0) {
            logger.warn("No method found in service interface " + interfaceClass.getName());
            map.put(METHODS_KEY, ANY_VALUE);
        } else {
            map.put(METHODS_KEY, StringUtils.join(new HashSet<String>(Arrays.asList(methods)), COMMA_SEPARATOR));
        }
    }
    map.put(INTERFACE_KEY, interfaceName);
    AbstractConfig.appendParameters(map, getMetrics());
    AbstractConfig.appendParameters(map, getApplication());
    AbstractConfig.appendParameters(map, getModule());
    // remove 'default.' prefix for configs from ConsumerConfig
    // appendParameters(map, consumer, Constants.DEFAULT_KEY);
    AbstractConfig.appendParameters(map, consumer);
    AbstractConfig.appendParameters(map, this);
    MetadataReportConfig metadataReportConfig = getMetadataReportConfig();
    if (metadataReportConfig != null && metadataReportConfig.isValid()) {
        map.putIfAbsent(METADATA_KEY, REMOTE_METADATA_STORAGE_TYPE);
    }
    Map<String, AsyncMethodInfo> attributes = null;
    if (CollectionUtils.isNotEmpty(getMethods())) {
        attributes = new HashMap<>();
        for (MethodConfig methodConfig : getMethods()) {
            AbstractConfig.appendParameters(map, methodConfig, methodConfig.getName());
            String retryKey = methodConfig.getName() + ".retry";
            if (map.containsKey(retryKey)) {
                String retryValue = map.remove(retryKey);
                if ("false".equals(retryValue)) {
                    map.put(methodConfig.getName() + ".retries", "0");
                }
            }
            AsyncMethodInfo asyncMethodInfo = AbstractConfig.convertMethodConfig2AsyncInfo(methodConfig);
            if (asyncMethodInfo != null) {
                // consumerModel.getMethodModel(methodConfig.getName()).addAttribute(ASYNC_KEY, asyncMethodInfo);
                attributes.put(methodConfig.getName(), asyncMethodInfo);
            }
        }
    }
    String hostToRegistry = ConfigUtils.getSystemProperty(DUBBO_IP_TO_REGISTRY);
    if (StringUtils.isEmpty(hostToRegistry)) {
        hostToRegistry = NetUtils.getLocalHost();
    } else if (isInvalidLocalHost(hostToRegistry)) {
        throw new IllegalArgumentException("Specified invalid registry ip from property:" + DUBBO_IP_TO_REGISTRY + ", value:" + hostToRegistry);
    }
    map.put(REGISTER_IP_KEY, hostToRegistry);
    serviceMetadata.getAttachments().putAll(map);
    ref = createProxy(map);
    serviceMetadata.setTarget(ref);
    serviceMetadata.addAttribute(PROXY_CLASS_REF, ref);
    ConsumerModel consumerModel = repository.lookupReferredService(serviceMetadata.getServiceKey());
    consumerModel.setProxyObject(ref);
    consumerModel.init(attributes);
    initialized = true;
    checkInvokerAvailable();
    // dispatch a ReferenceConfigInitializedEvent since 2.7.4
    dispatch(new ReferenceConfigInitializedEvent(this, invoker));
}
Also used : HashMap(java.util.HashMap) AsyncMethodInfo(org.apache.dubbo.rpc.model.AsyncMethodInfo) ReferenceConfigInitializedEvent(org.apache.dubbo.config.event.ReferenceConfigInitializedEvent) ConsumerModel(org.apache.dubbo.rpc.model.ConsumerModel) HashSet(java.util.HashSet)

Aggregations

ConsumerModel (org.apache.dubbo.rpc.model.ConsumerModel)4 AsyncMethodInfo (org.apache.dubbo.rpc.model.AsyncMethodInfo)2 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 ReferenceConfigInitializedEvent (org.apache.dubbo.config.event.ReferenceConfigInitializedEvent)1 TTable (org.apache.dubbo.qos.textui.TTable)1