org.apache.dubbo.common.URL

Here are the examples of the java api org.apache.dubbo.common.URL taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

1256 Examples 7

19 Source : RegistryServiceSubscribe.java
with MIT License
from yu120

public void unregister(URL url) {
    URL_IDS_MAPPER.remove(url.toFullString());
    registryService.unregister(url);
}

19 Source : RegistryServiceSubscribe.java
with MIT License
from yu120

private String generateServiceKey(URL url) {
    String inf = url.getServiceInterface();
    if (inf == null) {
        return null;
    }
    StringBuilder buf = new StringBuilder();
    String group = url.getParameter(CommonConstants.GROUP_KEY);
    if (group != null && group.length() > 0) {
        buf.append(group).append("/");
    }
    buf.append(inf);
    String version = url.getParameter(CommonConstants.VERSION_KEY);
    if (version != null && version.length() > 0) {
        buf.append(":").append(version);
    }
    return buf.toString();
}

19 Source : RegistryServiceSubscribe.java
with MIT License
from yu120

public void register(URL url) {
    registryService.register(url);
}

19 Source : RegistryServiceSubscribe.java
with MIT License
from yu120

public void update(URL oldUrl, URL newUrl) {
    registryService.unregister(oldUrl);
    registryService.register(newUrl);
}

19 Source : ZookeeperMetadataReportFactory.java
with MIT License
from yu120

@Override
public MetadataReport createMetadataReport(URL url) {
    return new ZookeeperMetadataReport(url, zookeeperTransporter);
}

19 Source : RedisMetadataReportFactory.java
with MIT License
from yu120

@Override
public MetadataReport createMetadataReport(URL url) {
    return new RedisMetadataReport(url);
}

19 Source : DubboInvoke.java
with MIT License
from yu120

/**
 * DubboInvoke
 *
 * @author lry
 */
@Slf4j
@Getter
@Extension("dubbo")
public clreplaced DubboInvoke implements LemonInvoke {

    private static final String GROUP_KEY = "group";

    private static final String VERSION_KEY = "version";

    private LemonConfig lemonConfig;

    private URL serverUrl;

    private RegistryConfig registryConfig;

    private RegistryService registryService;

    private MetadataCollectorFactory metadataCollectorFactory;

    private RegistryServiceSubscribe registryServiceSubscribe;

    @Override
    public void initialize(LemonConfig lemonConfig) {
        this.lemonConfig = lemonConfig;
        // 创建注册中心配置
        RegistryConfig registryConfig = new RegistryConfig();
        registryConfig.setAddress(lemonConfig.getDubbo().getRegistryAddress());
        this.registryConfig = registryConfig;
        // 启动注册中心,并注册服务本身至注册中心
        URL url = URL.valueOf(lemonConfig.getRegistryAddress());
        RegistryFactory registryFactory = ExtensionLoader.getExtensionLoader(RegistryFactory.clreplaced).getExtension(url.getProtocol());
        this.registryService = registryFactory.getRegistry(url);
        this.serverUrl = new URL("http", NetUtils.getLocalHost(), lemonConfig.getPort(), lemonConfig.getApplication());
        registryService.register(serverUrl);
        this.registryServiceSubscribe = new RegistryServiceSubscribe();
        registryServiceSubscribe.initialize(registryService);
        // 启动Metadata数据收集器
        this.metadataCollectorFactory = MetadataCollectorFactory.INSTANCE;
        metadataCollectorFactory.initialize(lemonConfig);
    }

    @Override
    public LemonContext invoke(LemonContext lemonContext) {
        LemonRequest request = lemonContext.getRequest();
        OriginalConfig originalConfig = lemonConfig.getOriginal();
        // setter request header list
        for (Map.Entry<String, Object> entry : request.getHeaders().entrySet()) {
            // originalReqHeaders contains or starts with 'X-'
            if (originalConfig.getReqHeaders().contains(entry.getKey()) || entry.getKey().startsWith(LemonContext.HEADER_PREFIX)) {
                RpcContext.getContext().setAttachment(entry.getKey(), String.valueOf(entry.getValue()));
            }
        }
        // call original remote
        ServiceMapping serviceMapping = parseServiceMapping(request);
        byte[] bytes = (byte[]) request.getContent();
        String body = new String(bytes, StandardCharsets.UTF_8);
        List<Object> paramValues = new ArrayList<>();
        paramValues.add(JSON.isValid(body) ? JSON.parse(bytes) : body);
        serviceMapping.setParamValues(paramValues.toArray(new Object[0]));
        GenericService genericService = buildGenericService(request, serviceMapping);
        Object result = genericService.$invoke(serviceMapping.getMethod(), serviceMapping.getParamTypes(), serviceMapping.getParamValues());
        // setter response header list
        Map<String, Object> headers = new HashMap<>();
        for (Map.Entry<String, String> entry : RpcContext.getContext().getAttachments().entrySet()) {
            headers.put(entry.getKey(), entry.getValue());
        }
        lemonContext.getResponse().addHeader(headers);
        lemonContext.getResponse().setContent(result);
        return lemonContext;
    }

    @Override
    public LemonStatusCode failure(LemonContext context, Throwable throwable) {
        if (throwable instanceof RpcException) {
            RpcException e = (RpcException) throwable;
            if (e.isTimeout()) {
                return LemonStatusCode.CALL_ORIGINAL_TIMEOUT;
            } else if (e.isBiz()) {
                return LemonStatusCode.CALL_ORIGINAL_BIZ_ERROR;
            } else if (e.isNetwork()) {
                return LemonStatusCode.CALL_ORIGINAL_NETWORK_ERROR;
            } else if (e.isSerialization()) {
                return LemonStatusCode.CALL_ORIGINAL_SERIALIZATION;
            }
        }
        return LemonStatusCode.CALL_ORIGINAL_UNKNOWN;
    }

    @Override
    public void destroy() {
        if (registryService != null) {
            registryService.unregister(serverUrl);
        }
    }

    /**
     * The build {@link GenericService} by {@link ServiceMapping}
     *
     * @param request        {@link LemonRequest}
     * @param serviceMapping {@link ServiceMapping}
     * @return {@link GenericService}
     */
    private GenericService buildGenericService(LemonRequest request, ServiceMapping serviceMapping) {
        ReferenceConfig<GenericService> referenceConfig = new ReferenceConfig<>();
        referenceConfig.setApplication(new ApplicationConfig(serviceMapping.getApplication()));
        referenceConfig.setGroup(serviceMapping.getGroup());
        referenceConfig.setVersion(serviceMapping.getVersion());
        referenceConfig.setRegistry(registryConfig);
        referenceConfig.setInterface(serviceMapping.getServiceName());
        referenceConfig.setGeneric(true);
        if (serviceMapping.getParamTypes() == null) {
            metadataCollectorFactory.wrapperTypesFromMetadata(request, serviceMapping);
        }
        return ReferenceConfigCache.getCache().get(referenceConfig);
    }

    /**
     * The wrapper {@link ServiceMapping} by {@link LemonContext}
     *
     * @param request {@link LemonRequest}
     */
    private ServiceMapping parseServiceMapping(LemonRequest request) {
        List<String> paths = Arrays.asList(request.getContextPath().split(LemonContext.URL_DELIMITER));
        if (paths.size() != 5) {
            throw new IllegalArgumentException("Illegal Request");
        }
        ServiceMapping serviceMapping = new ServiceMapping();
        serviceMapping.setApplication(paths.get(2));
        serviceMapping.setService(paths.get(3));
        serviceMapping.setMethod(paths.get(4));
        // wrapper service name
        serviceMapping.setServiceName(this.getServiceName(serviceMapping));
        Map<String, Object> parameters = request.getHeaders();
        if (parameters.containsKey(GROUP_KEY)) {
            serviceMapping.setGroup(String.valueOf(parameters.get(GROUP_KEY)));
        }
        if (parameters.containsKey(VERSION_KEY)) {
            serviceMapping.setVersion(String.valueOf(parameters.get(VERSION_KEY)));
        }
        return serviceMapping;
    }

    /**
     * The get service name
     *
     * @param serviceMapping {@link ServiceMapping}
     * @return service name
     */
    private String getServiceName(ServiceMapping serviceMapping) {
        ConcurrentMap<String, String> serviceNames = registryServiceSubscribe.getServiceNames().get(serviceMapping.getApplication());
        if (serviceNames == null || serviceNames.isEmpty()) {
            return serviceMapping.getService();
        }
        String serviceName = serviceNames.get(serviceMapping.getService());
        if (serviceName == null || serviceName.length() == 0) {
            return serviceMapping.getService();
        }
        return serviceName;
    }
}

19 Source : ApacheDubboServerSpanCreater.java
with Apache License 2.0
from yametech

/**
 * dubbo-2.7.0 URL没有getPathKey方法所以参考实现copy到这里
 *
 * @param url
 * @return
 */
private String getPathKey(URL url) {
    String path = url.getPath();
    String inf = StringUtil.notEmpty(path) ? path : url.getServiceInterface();
    if (inf == null) {
        return null;
    }
    StringBuilder buf = new StringBuilder();
    String group = url.getParameter("group");
    String version = url.getParameter("version");
    if (group != null && group.length() > 0) {
        buf.append(group).append("/");
    }
    buf.append(inf);
    if (version != null && version.length() > 0) {
        buf.append(":").append(version);
    }
    return buf.toString();
}

19 Source : RegistryServerSync.java
with Apache License 2.0
from thubbo

/**
 * RegistryServerSync
 */
public clreplaced RegistryServerSync implements NotifyListener, Serializable {

    private static final long serialVersionUID = -1744756264793278229L;

    private static ConcurrentMap<String, RegistryServerSync> cache = new ConcurrentHashMap<>();

    public static RegistryServerSync get(String key) {
        RegistryServerSync sync = cache.get(key);
        if (sync == null) {
            cache.putIfAbsent(key, new RegistryServerSync());
            sync = cache.get(key);
        }
        return sync;
    }

    public static final URL SUBSCRIBE = new URL(Constants.ADMIN_PROTOCOL, NetUtils.getLocalHost(), 0, "", CommonConstants.INTERFACE_KEY, CommonConstants.ANY_VALUE, CommonConstants.GROUP_KEY, CommonConstants.ANY_VALUE, CommonConstants.VERSION_KEY, CommonConstants.ANY_VALUE, CommonConstants.CLreplacedIFIER_KEY, CommonConstants.ANY_VALUE, RegistryConstants.CATEGORY_KEY, RegistryConstants.PROVIDERS_CATEGORY, // Constants.CATEGORY_KEY, Constants.PROVIDERS_CATEGORY + ","
    // + Constants.CONSUMERS_CATEGORY + ","
    // + Constants.ROUTERS_CATEGORY + ","
    // + Constants.CONFIGURATORS_CATEGORY,
    CommonConstants.ENABLED_KEY, CommonConstants.ANY_VALUE, CommonConstants.CHECK_KEY, String.valueOf(false));

    // ConcurrentMap<category, ConcurrentMap<servicename, Map<MD5, URL>>>
    private final ConcurrentMap<String, ConcurrentMap<String, Map<String, URL>>> registryCache = new ConcurrentHashMap<>();

    /**
     * Make sure ID never changed when the same url notified many times
     */
    private final ConcurrentHashMap<String, String> URL_IDS_MAPPER = new ConcurrentHashMap<>();

    public RegistryServerSync() {
    }

    public ConcurrentMap<String, ConcurrentMap<String, Map<String, URL>>> getRegistryCache() {
        return registryCache;
    }

    @Override
    public void notify(List<URL> urls) {
        if (urls == null || urls.isEmpty()) {
            return;
        }
        // Map<category, Map<servicename, Map<Long, URL>>>
        final Map<String, Map<String, Map<String, URL>>> categories = new HashMap<>();
        String interfaceName = null;
        for (URL url : urls) {
            String category = url.getParameter(RegistryConstants.CATEGORY_KEY, RegistryConstants.PROVIDERS_CATEGORY);
            if (RegistryConstants.EMPTY_PROTOCOL.equalsIgnoreCase(url.getProtocol())) {
                // NOTE: group and version in empty protocol is *
                ConcurrentMap<String, Map<String, URL>> services = registryCache.get(category);
                if (services != null) {
                    String group = url.getParameter(CommonConstants.GROUP_KEY);
                    String version = url.getParameter(CommonConstants.VERSION_KEY);
                    // NOTE: group and version in empty protocol is *
                    if (!CommonConstants.ANY_VALUE.equals(group) && !CommonConstants.ANY_VALUE.equals(version)) {
                        services.remove(url.getServiceKey());
                    } else {
                        for (Map.Entry<String, Map<String, URL>> serviceEntry : services.entrySet()) {
                            String service = serviceEntry.getKey();
                            if (this.getInterface(service).equals(url.getServiceInterface()) && (CommonConstants.ANY_VALUE.equals(group) || StringUtils.isEquals(group, this.getGroup(service))) && (CommonConstants.ANY_VALUE.equals(version) || StringUtils.isEquals(version, this.getVersion(service)))) {
                                services.remove(service);
                            }
                        }
                    }
                }
            } else {
                if (StringUtils.isEmpty(interfaceName)) {
                    interfaceName = url.getServiceInterface();
                }
                Map<String, Map<String, URL>> services = categories.get(category);
                if (services == null) {
                    services = new HashMap<>();
                    categories.put(category, services);
                }
                String service = url.getServiceKey();
                Map<String, URL> ids = services.get(service);
                if (ids == null) {
                    ids = new HashMap<>();
                    services.put(service, ids);
                }
                // Make sure we use the same ID for the same URL
                if (URL_IDS_MAPPER.containsKey(url.toFullString())) {
                    ids.put(URL_IDS_MAPPER.get(url.toFullString()), url);
                } else {
                    String md5 = MD5Util.MD5_16bit(url.toFullString());
                    ids.put(md5, url);
                    URL_IDS_MAPPER.putIfAbsent(url.toFullString(), md5);
                }
            }
        }
        if (categories.size() == 0) {
            return;
        }
        for (Map.Entry<String, Map<String, Map<String, URL>>> categoryEntry : categories.entrySet()) {
            String category = categoryEntry.getKey();
            ConcurrentMap<String, Map<String, URL>> services = registryCache.get(category);
            if (services == null) {
                services = new ConcurrentHashMap<String, Map<String, URL>>();
                registryCache.put(category, services);
            } else {
                // Fix map can not be cleared when service is unregistered: when a unique “group/service:version” service is unregistered, but we still have the same services with different version or group, so empty protocols can not be invoked.
                Set<String> keys = new HashSet<String>(services.keySet());
                for (String key : keys) {
                    if (this.getInterface(key).equals(interfaceName) && !categoryEntry.getValue().entrySet().contains(key)) {
                        services.remove(key);
                    }
                }
            }
            services.putAll(categoryEntry.getValue());
        }
    }

    public String getInterface(String service) {
        if (service != null && service.length() > 0) {
            int i = service.indexOf('/');
            if (i >= 0) {
                service = service.substring(i + 1);
            }
            i = service.lastIndexOf(':');
            if (i >= 0) {
                service = service.substring(0, i);
            }
        }
        return service;
    }

    public String getGroup(String service) {
        if (service != null && service.length() > 0) {
            int i = service.indexOf('/');
            if (i >= 0) {
                return service.substring(0, i);
            }
        }
        return null;
    }

    public String getVersion(String service) {
        if (service != null && service.length() > 0) {
            int i = service.lastIndexOf(':');
            if (i >= 0) {
                return service.substring(i + 1);
            }
        }
        return null;
    }
}

19 Source : DubboCommonPanel.java
with Apache License 2.0
from thubbo

private void doChange(String key) {
    String address = (StringUtils.isBlank(Constants.DEFAULT_PANEL_ADDRESS) ? addressText.getText() : Constants.DEFAULT_PANEL_ADDRESS);
    ProviderService providerService = ProviderService.get(address);
    Map<String, URL> provider = providerService.findByService(key);
    if (provider != null && !provider.isEmpty()) {
        URL url = new ArrayList<URL>(provider.values()).get(0);
        String group = url.getParameter(com.alibaba.dubbo.common.Constants.GROUP_KEY);
        String version = url.getParameter(com.alibaba.dubbo.common.Constants.VERSION_KEY);
        String timeout = url.getParameter(com.alibaba.dubbo.common.Constants.TIMEOUT_KEY);
        String protocol = url.getProtocol() + "://";
        String interfaceName = url.getServiceInterface();
        String method = url.getParameter(com.alibaba.dubbo.common.Constants.METHODS_KEY);
        groupText.setText(group);
        versionText.setText(version);
        timeoutText.setText(timeout);
        rpcProtocolText.setSelectedItem(protocol);
        interfaceText.setText(interfaceName);
        // set method
        String[] items = method.split(",");
        methodList.setModel(new DefaultComboBoxModel<String>(items));
    } else {
        methodList.setModel(new DefaultComboBoxModel<String>(new String[] {}));
    }
}

19 Source : MyHessian2Serialization.java
with MIT License
from threedr3am

@Override
public ObjectInput deserialize(URL url, InputStream is) throws IOException {
    return new MyHessian2ObjectInput(is);
}

19 Source : NacosNamingServiceUtils.java
with Apache License 2.0
from mercyblitz

private static void setProperties(URL url, Properties properties) {
    putPropertyIfAbsent(url, properties, NACOS_NAMING_LOG_NAME);
    putPropertyIfAbsent(url, properties, NAMING_LOAD_CACHE_AT_START, "true");
    for (String propertyName : NACOS_PROPERTY_NAMES) {
        putPropertyIfAbsent(url, properties, propertyName);
    }
}

19 Source : NacosNamingServiceUtils.java
with Apache License 2.0
from mercyblitz

private static void putPropertyIfAbsent(URL url, Properties properties, String propertyName) {
    putPropertyIfAbsent(url, properties, propertyName, null);
}

19 Source : NacosNamingServiceUtils.java
with Apache License 2.0
from mercyblitz

private static void setServerAddr(URL url, Properties properties) {
    StringBuilder serverAddrBuilder = // Host
    new StringBuilder(url.getHost()).append(":").append(// Port
    url.getPort());
    // Append backup parameter as other servers
    String backup = url.getParameter(BACKUP_KEY);
    if (backup != null) {
        serverAddrBuilder.append(",").append(backup);
    }
    String serverAddr = serverAddrBuilder.toString();
    properties.put(SERVER_ADDR, serverAddr);
}

19 Source : NacosNamingServiceUtils.java
with Apache License 2.0
from mercyblitz

private static void putPropertyIfAbsent(URL url, Properties properties, String propertyName, String defaultValue) {
    String propertyValue = url.getParameter(propertyName);
    putPropertyIfAbsent(properties, propertyName, propertyValue, defaultValue);
}

19 Source : NacosNamingServiceUtils.java
with Apache License 2.0
from mercyblitz

/**
 * The group of {@link NamingService} to register
 *
 * @param connectionURL {@link URL connection url}
 * @return non-null, "default" as default
 * @since 2.7.5
 */
public static String getGroup(URL connectionURL) {
    return connectionURL.getParameter("nacos.group", DEFAULT_GROUP);
}

19 Source : NacosNamingServiceUtils.java
with Apache License 2.0
from mercyblitz

private static Properties buildNacosProperties(URL url) {
    Properties properties = new Properties();
    setServerAddr(url, properties);
    setProperties(url, properties);
    return properties;
}

19 Source : NacosNamingServiceUtils.java
with Apache License 2.0
from mercyblitz

/**
 * Create an instance of {@link NamingService} from specified {@link URL connection url}
 *
 * @param connectionURL {@link URL connection url}
 * @return {@link NamingService}
 * @since 2.7.5
 */
public static NamingService createNamingService(URL connectionURL) {
    Properties nacosProperties = buildNacosProperties(connectionURL);
    NamingService namingService;
    try {
        namingService = NacosFactory.createNamingService(nacosProperties);
    } catch (NacosException e) {
        if (logger.isErrorEnabled()) {
            logger.error(e.getErrMsg(), e);
        }
        throw new IllegalStateException(e);
    }
    return namingService;
}

19 Source : NacosServiceName.java
with Apache License 2.0
from mercyblitz

/**
 * Build an instance of {@link NacosServiceName}
 *
 * @param url {@link URL}
 * @return {@link NacosServiceName} instance
 */
public static NacosServiceName valueOf(URL url) {
    return new NacosServiceName(url);
}

19 Source : NacosServiceDiscovery.java
with Apache License 2.0
from mercyblitz

@Override
public void initialize(URL registryURL) throws Exception {
    this.namingService = createNamingService(registryURL);
    this.group = getGroup(registryURL);
}

19 Source : NacosRegistryFactory.java
with Apache License 2.0
from mercyblitz

@Override
protected Registry createRegistry(URL url) {
    return new NacosRegistry(url, createNamingService(url));
}

19 Source : NacosRegistry.java
with Apache License 2.0
from mercyblitz

private Set<String> getServiceNames0(URL url) {
    NacosServiceName serviceName = createServiceName(url);
    final Set<String> serviceNames;
    if (serviceName.isConcrete()) {
        // is the concrete service name
        serviceNames = new LinkedHashSet<>();
        serviceNames.add(serviceName.toString());
        // Add the legacy service name since 2.7.6
        String legacySubscribedServiceName = getLegacySubscribedServiceName(url);
        if (!serviceName.toString().equals(legacySubscribedServiceName)) {
            // avoid duplicated service names
            serviceNames.add(legacySubscribedServiceName);
        }
    } else {
        serviceNames = filterServiceNames(serviceName);
    }
    return serviceNames;
}

19 Source : NacosRegistry.java
with Apache License 2.0
from mercyblitz

private String getServiceName(URL url) {
    return getServiceName(url, url.getParameter(CATEGORY_KEY, DEFAULT_CATEGORY));
}

19 Source : NacosRegistry.java
with Apache License 2.0
from mercyblitz

private void appendIfPresent(StringBuilder target, URL url, String parameterName) {
    String parameterValue = url.getParameter(parameterName);
    if (!org.apache.commons.lang3.StringUtils.isBlank(parameterValue)) {
        target.append(SERVICE_NAME_SEPARATOR).append(parameterValue);
    }
}

19 Source : NacosRegistry.java
with Apache License 2.0
from mercyblitz

/**
 * Since 2.7.6 the legacy service name will be added to serviceNames
 * to fix bug with https://github.com/apache/dubbo/issues/5442
 *
 * @param url
 * @return
 */
private boolean isServiceNamesWithCompatibleMode(final URL url) {
    if (!isAdminProtocol(url) && createServiceName(url).isConcrete()) {
        return true;
    } else {
        return false;
    }
}

19 Source : NacosRegistry.java
with Apache License 2.0
from mercyblitz

private List<URL> buildURLs(URL consumerURL, Collection<Instance> instances) {
    List<URL> urls = new LinkedList<>();
    if (instances != null && !instances.isEmpty()) {
        for (Instance instance : instances) {
            URL url = buildURL(instance);
            if (UrlUtils.isMatch(consumerURL, url)) {
                urls.add(url);
            }
        }
    }
    return urls;
}

19 Source : NacosRegistry.java
with Apache License 2.0
from mercyblitz

@Override
public void doUnregister(final URL url) {
    execute(namingService -> {
        String serviceName = getServiceName(url);
        Instance instance = createInstance(url);
        namingService.deregisterInstance(serviceName, instance.getIp(), instance.getPort());
    });
}

19 Source : NacosRegistry.java
with Apache License 2.0
from mercyblitz

private boolean isAdminProtocol(URL url) {
    return ADMIN_PROTOCOL.equals(url.getProtocol());
}

19 Source : NacosRegistry.java
with Apache License 2.0
from mercyblitz

private List<URL> toUrlWithEmpty(URL consumerURL, Collection<Instance> instances) {
    List<URL> urls = buildURLs(consumerURL, instances);
    if (urls.size() == 0) {
        URL empty = URLBuilder.from(consumerURL).setProtocol(EMPTY_PROTOCOL).addParameter(CATEGORY_KEY, DEFAULT_CATEGORY).build();
        urls.add(empty);
    }
    return urls;
}

19 Source : NacosRegistry.java
with Apache License 2.0
from mercyblitz

@Deprecated
private List<String> doGetServiceNames(URL url) {
    List<String> categories = getCategories(url);
    List<String> serviceNames = new ArrayList<>(categories.size());
    for (String category : categories) {
        final String serviceName = getServiceName(url, category);
        serviceNames.add(serviceName);
    }
    return serviceNames;
}

19 Source : NacosRegistry.java
with Apache License 2.0
from mercyblitz

private void filterServiceNames(Set<String> serviceNames, URL url) {
    final List<String> categories = getCategories(url);
    final String targetServiceInterface = url.getServiceInterface();
    final String targetVersion = url.getParameter(VERSION_KEY, "");
    final String targetGroup = url.getParameter(GROUP_KEY, "");
    filterData(serviceNames, serviceName -> {
        // split service name to segments
        // (required) segments[0] = category
        // (required) segments[1] = serviceInterface
        // (optional) segments[2] = version
        // (optional) segments[3] = group
        String[] segments = serviceName.split(SERVICE_NAME_SEPARATOR, -1);
        int length = segments.length;
        if (length != 4) {
            // must present 4 segments
            return false;
        }
        String category = segments[CATEGORY_INDEX];
        if (!categories.contains(category)) {
            // no match category
            return false;
        }
        String serviceInterface = segments[SERVICE_INTERFACE_INDEX];
        // no match service interface
        if (!WILDCARD.equals(targetServiceInterface) && !StringUtils.isEquals(targetServiceInterface, serviceInterface)) {
            return false;
        }
        // no match service version
        String version = segments[SERVICE_VERSION_INDEX];
        if (!WILDCARD.equals(targetVersion) && !StringUtils.isEquals(targetVersion, version)) {
            return false;
        }
        String group = segments[SERVICE_GROUP_INDEX];
        return group == null || WILDCARD.equals(targetGroup) || StringUtils.isEquals(targetGroup, group);
    });
}

19 Source : NacosRegistry.java
with Apache License 2.0
from mercyblitz

/**
 * Get the service names for Dubbo OPS
 *
 * @param url {@link URL}
 * @return non-null
 */
private Set<String> getServiceNamesForOps(URL url) {
    Set<String> serviceNames = getAllServiceNames();
    filterServiceNames(serviceNames, url);
    return serviceNames;
}

19 Source : NacosRegistry.java
with Apache License 2.0
from mercyblitz

private String getServiceName(URL url, String category) {
    return category + SERVICE_NAME_SEPARATOR + url.getColonSeparatedKey();
}

19 Source : NacosRegistry.java
with Apache License 2.0
from mercyblitz

private NacosServiceName createServiceName(URL url) {
    return valueOf(url);
}

19 Source : NacosRegistry.java
with Apache License 2.0
from mercyblitz

/**
 * Get the categories from {@link URL}
 *
 * @param url {@link URL}
 * @return non-null array
 */
private List<String> getCategories(URL url) {
    return ANY_VALUE.equals(url.getServiceInterface()) ? ALL_SUPPORTED_CATEGORIES : Arrays.asList(DEFAULT_CATEGORY);
}

19 Source : NacosRegistry.java
with Apache License 2.0
from mercyblitz

/**
 * Get the legacy subscribed service name for compatible with Dubbo 2.7.3 and below
 *
 * @param url {@link URL}
 * @return non-null
 * @since 2.7.6
 */
private String getLegacySubscribedServiceName(URL url) {
    StringBuilder serviceNameBuilder = new StringBuilder(DEFAULT_CATEGORY);
    appendIfPresent(serviceNameBuilder, url, INTERFACE_KEY);
    appendIfPresent(serviceNameBuilder, url, VERSION_KEY);
    appendIfPresent(serviceNameBuilder, url, GROUP_KEY);
    return serviceNameBuilder.toString();
}

19 Source : CatRegistryFactoryWrapper.java
with MIT License
from KevinClair

@Override
public Registry getRegistry(URL url) {
    return new RegistryWrapper(registryFactory.getRegistry(url));
}

19 Source : ExtendDubboClientValidation.java
with MIT License
from KevinClair

@Override
public Validator getValidator(URL url) {
    return new ExtendDubboClientValidator(url);
}

19 Source : ServiceCenterRegistryFactory.java
with Apache License 2.0
from huaweicloud

@Override
protected Registry createRegistry(URL url) {
    return new ServiceCenterRegistry(url, registrationListener);
}

19 Source : ServiceCenterRegistry.java
with Apache License 2.0
from huaweicloud

@Override
public void doUnsubscribe(URL url, NotifyListener notifyListener) {
    this.registrationListener.shutdown();
}

19 Source : ServiceCenterRegistry.java
with Apache License 2.0
from huaweicloud

@Override
public void doSubscribe(URL url, NotifyListener notifyListener) {
    if (url.getProtocol().equals(PROTOCOL_CONSUMER)) {
        this.registrationListener.applicationEventPublisher().publishEvent(new NewSubscriberEvent(url, notifyListener));
    }
}

19 Source : ServiceCenterRegistry.java
with Apache License 2.0
from huaweicloud

@Override
public void doRegister(URL url) {
    if (!url.getProtocol().equals(PROTOCOL_CONSUMER)) {
        this.registers.add(url);
    }
}

19 Source : ServiceCenterRegistry.java
with Apache License 2.0
from huaweicloud

@Override
public void doUnregister(URL url) {
    this.registrationListener.shutdown();
}

19 Source : NewSubscriberEvent.java
with Apache License 2.0
from huaweicloud

public clreplaced NewSubscriberEvent extends ApplicationEvent {

    private static final long serialVersionUID = 1L;

    private final URL url;

    private final NotifyListener notifyListener;

    public NewSubscriberEvent(URL url, NotifyListener notifyListener) {
        super(url);
        this.url = url;
        this.notifyListener = notifyListener;
    }

    public URL getUrl() {
        return url;
    }

    public NotifyListener getNotifyListener() {
        return notifyListener;
    }
}

19 Source : DubboAppContextFilterTest.java
with Apache License 2.0
from eacdy

@Test
public void testInvokeNullApplicationKey() {
    Invoker invoker = mock(Invoker.clreplaced);
    Invocation invocation = mock(Invocation.clreplaced);
    URL url = URL.valueOf("test://test:111/test?application=");
    when(invoker.getUrl()).thenReturn(url);
    filter.invoke(invoker, invocation);
    verify(invoker).invoke(invocation);
    String application = RpcContext.getContext().getAttachment(DubboUtils.SENTINEL_DUBBO_APPLICATION_KEY);
    replacedertNull(application);
}

19 Source : DubboAppContextFilterTest.java
with Apache License 2.0
from eacdy

@Test
public void testInvokeApplicationKey() {
    Invoker invoker = mock(Invoker.clreplaced);
    Invocation invocation = mock(Invocation.clreplaced);
    URL url = URL.valueOf("test://test:111/test?application=serviceA");
    when(invoker.getUrl()).thenReturn(url);
    filter.invoke(invoker, invocation);
    verify(invoker).invoke(invocation);
    String application = RpcContext.getContext().getAttachment(DubboUtils.SENTINEL_DUBBO_APPLICATION_KEY);
    replacedertEquals("serviceA", application);
}

19 Source : ApacheDubboClientValidatorTest.java
with Apache License 2.0
from dromara

/**
 * test method {@link ApacheDubboClientValidator#validate(java.lang.String, java.lang.Clreplaced[], java.lang.Object[])}.
 */
@Test
public void validate() {
    URL url = URL.valueOf("dubbo://127.0.0.1:20880/org.dromara.soul" + ".client.apache.dubbo.validation.service.TestService" + "?accepts=500&anyhost=true&application=soul-proxy" + "&bind.ip=127.0.0.1&bind.port=20880&deprecated=false" + "&dubbo=2.0.2&dynamic=true&generic=false" + "&interface=org.dromara.soul.client.apache.dubbo.validation.service.TestService" + "&keep.alive=true&methods=test&pid=67352&qos.enable=false&release=2.7.0" + "&side=provider&threadpool=fixed&threads=500&timeout=20000" + "×tamp=1608119259859&validation=soulValidation");
    Validator apacheDubboClientValidator = new ApacheDubboClientValidation().getValidator(url);
    try {
        apacheDubboClientValidator.validate("test", new Clreplaced[] { TestService.TestObject.clreplaced }, new Object[] { TestService.TestObject.builder().age(null).build() });
    } catch (Exception e) {
        replacedertThat("age cannot be null.", is(e.getMessage()));
    }
}

19 Source : ApacheDubboClientValidatorTest.java
with Apache License 2.0
from dromara

@Test
public void testValidateWithExistMethod() throws Exception {
    final URL url = URL.valueOf(MOCK_SERVICE_URL + "?soulValidation=org.hibernate.validator.HibernateValidator");
    ApacheDubboClientValidator apacheDubboClientValidator = new ApacheDubboClientValidator(url);
    apacheDubboClientValidator.validate("methodOne", new Clreplaced<?>[] { String.clreplaced }, new Object[] { "anything" });
    apacheDubboClientValidator.validate("methodOne", new Clreplaced<?>[] { String.clreplaced }, new Object[] { "anything" });
}

19 Source : ApacheDubboClientValidatorTest.java
with Apache License 2.0
from dromara

@Before
public void setUp() {
    URL url = URL.valueOf(MOCK_SERVICE_URL);
    apacheDubboClientValidatorUnderTest = new ApacheDubboClientValidator(url);
}

19 Source : ApacheDubboClientValidationTest.java
with Apache License 2.0
from dromara

@Test
public void testGetValidator() {
    String mockServiceUrl = "mock://localhost:28000/org.dromara.soul.client.apache.dubbo.validation.mock.MockValidatorTarget";
    final URL url = URL.valueOf(mockServiceUrl);
    apacheDubboClientValidationUnderTest.getValidator(url);
}

See More Examples