Search in sources :

Example 1 with URL

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

the class ProviderServiceImpl method findAddresses.

public List<String> findAddresses() {
    List<String> ret = new ArrayList<String>();
    ConcurrentMap<String, Map<Long, URL>> providerUrls = getRegistryCache().get(Constants.PROVIDERS_CATEGORY);
    if (null == providerUrls)
        return ret;
    for (Map.Entry<String, Map<Long, URL>> e1 : providerUrls.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) HashMap(java.util.HashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap) Map(java.util.Map) URL(com.alibaba.dubbo.common.URL)

Example 2 with URL

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

the class RouteServiceImpl method deleteRoute.

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

Example 3 with URL

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

the class RouteServiceImpl method enableRoute.

public void enableRoute(Long id) {
    if (id == null) {
        throw new IllegalStateException("no route id");
    }
    URL oldRoute = findRouteUrl(id);
    if (oldRoute == null) {
        throw new IllegalStateException("Route was changed!");
    }
    if (oldRoute.getParameter("enabled", true)) {
        return;
    }
    registryService.unregister(oldRoute);
    URL newRoute = oldRoute.addParameter("enabled", true);
    registryService.register(newRoute);
}
Also used : URL(com.alibaba.dubbo.common.URL)

Example 4 with URL

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

the class RouteServiceImpl method updateRoute.

public void updateRoute(Route route) {
    Long id = route.getId();
    if (id == null) {
        throw new IllegalStateException("no route id");
    }
    URL oldRoute = findRouteUrl(id);
    if (oldRoute == null) {
        throw new IllegalStateException("Route was changed!");
    }
    registryService.unregister(oldRoute);
    registryService.register(route.toUrl());
}
Also used : URL(com.alibaba.dubbo.common.URL)

Example 5 with URL

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

the class RegistryServerSync method notify.

// 收到的通知对于 ,同一种类型数据(override、subcribe、route、其它是Provider),同一个服务的数据是全量的
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<Long, URL>>> categories = new HashMap<String, Map<String, Map<Long, URL>>>();
    for (URL url : urls) {
        String category = url.getParameter(Constants.CATEGORY_KEY, Constants.PROVIDERS_CATEGORY);
        if (Constants.EMPTY_PROTOCOL.equalsIgnoreCase(url.getProtocol())) {
            // 注意:empty协议的group和version为*
            ConcurrentMap<String, Map<Long, URL>> services = registryCache.get(category);
            if (services != null) {
                String group = url.getParameter(Constants.GROUP_KEY);
                String version = url.getParameter(Constants.VERSION_KEY);
                // 注意:empty协议的group和version为*
                if (!Constants.ANY_VALUE.equals(group) && !Constants.ANY_VALUE.equals(version)) {
                    services.remove(url.getServiceKey());
                } else {
                    for (Map.Entry<String, Map<Long, URL>> serviceEntry : services.entrySet()) {
                        String service = serviceEntry.getKey();
                        if (Tool.getInterface(service).equals(url.getServiceInterface()) && (Constants.ANY_VALUE.equals(group) || StringUtils.isEquals(group, Tool.getGroup(service))) && (Constants.ANY_VALUE.equals(version) || StringUtils.isEquals(version, Tool.getVersion(service)))) {
                            services.remove(service);
                        }
                    }
                }
            }
        } else {
            Map<String, Map<Long, URL>> services = categories.get(category);
            if (services == null) {
                services = new HashMap<String, Map<Long, URL>>();
                categories.put(category, services);
            }
            String service = url.getServiceKey();
            Map<Long, URL> ids = services.get(service);
            if (ids == null) {
                ids = new HashMap<Long, URL>();
                services.put(service, ids);
            }
            ids.put(ID.incrementAndGet(), url);
        }
    }
    for (Map.Entry<String, Map<String, Map<Long, URL>>> categoryEntry : categories.entrySet()) {
        String category = categoryEntry.getKey();
        ConcurrentMap<String, Map<Long, URL>> services = registryCache.get(category);
        if (services == null) {
            services = new ConcurrentHashMap<String, Map<Long, URL>>();
            registryCache.put(category, services);
        }
        services.putAll(categoryEntry.getValue());
    }
}
Also used : ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) URL(com.alibaba.dubbo.common.URL) AtomicLong(java.util.concurrent.atomic.AtomicLong) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap) Map(java.util.Map)

Aggregations

URL (com.alibaba.dubbo.common.URL)360 Test (org.junit.Test)173 ArrayList (java.util.ArrayList)98 HashMap (java.util.HashMap)71 RpcInvocation (com.alibaba.dubbo.rpc.RpcInvocation)64 Map (java.util.Map)57 ConcurrentMap (java.util.concurrent.ConcurrentMap)46 List (java.util.List)40 Invoker (com.alibaba.dubbo.rpc.Invoker)37 Result (com.alibaba.dubbo.rpc.Result)37 Invocation (com.alibaba.dubbo.rpc.Invocation)31 RegistryDirectory (com.alibaba.dubbo.registry.integration.RegistryDirectory)28 NotifyListener (com.alibaba.dubbo.registry.NotifyListener)25 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)24 RpcException (com.alibaba.dubbo.rpc.RpcException)22 RpcResult (com.alibaba.dubbo.rpc.RpcResult)17 Set (java.util.Set)17 ConcurrentHashSet (com.alibaba.dubbo.common.utils.ConcurrentHashSet)16 DemoService (com.alibaba.dubbo.rpc.support.DemoService)12 HashSet (java.util.HashSet)12