Search in sources :

Example 16 with URL

use of com.alibaba.dubbo.common.URL in project dubbo by alibaba.

the class ConsumerServiceImpl method findServicesByAddress.

public List<String> findServicesByAddress(String address) {
    List<String> ret = new ArrayList<String>();
    ConcurrentMap<String, Map<Long, URL>> consumerUrls = getRegistryCache().get(Constants.CONSUMERS_CATEGORY);
    if (consumerUrls == null || address == null || address.length() == 0)
        return ret;
    for (Map.Entry<String, Map<Long, URL>> e1 : consumerUrls.entrySet()) {
        Map<Long, URL> value = e1.getValue();
        for (Map.Entry<Long, URL> e2 : value.entrySet()) {
            URL u = e2.getValue();
            if (address.equals(u.getAddress())) {
                ret.add(e1.getKey());
                break;
            }
        }
    }
    return ret;
}
Also used : ArrayList(java.util.ArrayList) Map(java.util.Map) HashMap(java.util.HashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap) URL(com.alibaba.dubbo.common.URL)

Example 17 with URL

use of com.alibaba.dubbo.common.URL in project dubbo by alibaba.

the class ConsumerServiceImpl method findAddressesByService.

public List<String> findAddressesByService(String service) {
    List<String> ret = new ArrayList<String>();
    ConcurrentMap<String, Map<Long, URL>> consumerUrls = getRegistryCache().get(Constants.CONSUMERS_CATEGORY);
    if (null == consumerUrls)
        return ret;
    for (Map.Entry<Long, URL> e2 : consumerUrls.get(service).entrySet()) {
        URL u = e2.getValue();
        String app = u.getAddress();
        if (app != null)
            ret.add(app);
    }
    return ret;
}
Also used : ArrayList(java.util.ArrayList) Map(java.util.Map) HashMap(java.util.HashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap) URL(com.alibaba.dubbo.common.URL)

Example 18 with URL

use of com.alibaba.dubbo.common.URL in project dubbo by alibaba.

the class ConsumerServiceImpl method findAddresses.

public List<String> findAddresses() {
    List<String> ret = new ArrayList<String>();
    ConcurrentMap<String, Map<Long, URL>> consumerUrls = getRegistryCache().get(Constants.CONSUMERS_CATEGORY);
    if (null == consumerUrls)
        return ret;
    for (Map.Entry<String, Map<Long, URL>> e1 : consumerUrls.entrySet()) {
        Map<Long, URL> value = e1.getValue();
        for (Map.Entry<Long, URL> e2 : value.entrySet()) {
            URL u = e2.getValue();
            String app = u.getAddress();
            if (app != null)
                ret.add(app);
        }
    }
    return ret;
}
Also used : ArrayList(java.util.ArrayList) Map(java.util.Map) HashMap(java.util.HashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap) URL(com.alibaba.dubbo.common.URL)

Example 19 with URL

use of com.alibaba.dubbo.common.URL in project dubbo by alibaba.

the class OverrideServiceImpl method deleteOverride.

public void deleteOverride(Long id) {
    URL oldOverride = findOverrideUrl(id);
    if (oldOverride == null) {
        throw new IllegalStateException("Route was changed!");
    }
    registryService.unregister(oldOverride);
}
Also used : URL(com.alibaba.dubbo.common.URL)

Example 20 with URL

use of com.alibaba.dubbo.common.URL in project dubbo by alibaba.

the class Provider method toUrl.

public URL toUrl() {
    Map<String, String> serviceName2Map = ConvertUtil.serviceName2Map(getService());
    /*if(!serviceName2Map.containsKey(Constants.INTERFACE_KEY)) {
            throw new IllegalArgumentException("No interface info");
        }
        if(!serviceName2Map.containsKey(Constants.VERSION_KEY)) {
            throw new IllegalArgumentException("No version info");
        }*/
    String u = getUrl();
    URL url = URL.valueOf(u + "?" + getParameters());
    url = url.addParameters(serviceName2Map);
    boolean dynamic = isDynamic();
    if (!dynamic) {
        url = url.addParameter(Constants.DYNAMIC_KEY, false);
    }
    boolean enabled = isEnabled();
    if (enabled != url.getParameter("enabled", true)) {
        if (enabled) {
            url = url.removeParameter("enabled");
        } else {
            url = url.addParameter("enabled", false);
        }
    }
    return url;
}
Also used : URL(com.alibaba.dubbo.common.URL)

Aggregations

URL (com.alibaba.dubbo.common.URL)283 Test (org.junit.Test)157 ArrayList (java.util.ArrayList)73 RpcInvocation (com.alibaba.dubbo.rpc.RpcInvocation)62 HashMap (java.util.HashMap)39 Result (com.alibaba.dubbo.rpc.Result)37 Map (java.util.Map)36 Invoker (com.alibaba.dubbo.rpc.Invoker)34 List (java.util.List)30 ConcurrentMap (java.util.concurrent.ConcurrentMap)29 RegistryDirectory (com.alibaba.dubbo.registry.integration.RegistryDirectory)28 Invocation (com.alibaba.dubbo.rpc.Invocation)28 RpcException (com.alibaba.dubbo.rpc.RpcException)22 NotifyListener (com.alibaba.dubbo.registry.NotifyListener)20 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)17 RpcResult (com.alibaba.dubbo.rpc.RpcResult)16 DemoService (com.alibaba.dubbo.rpc.support.DemoService)12 Set (java.util.Set)12 ConcurrentHashSet (com.alibaba.dubbo.common.utils.ConcurrentHashSet)11 Protocol (com.alibaba.dubbo.rpc.Protocol)10