Search in sources :

Example 6 with URL

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

the class SyncUtils method url2Override.

public static com.alibaba.dubbo.registry.common.domain.Override url2Override(Pair<Long, URL> pair) {
    if (pair == null) {
        return null;
    }
    Long id = pair.getKey();
    URL url = pair.getValue();
    if (null == url)
        return null;
    com.alibaba.dubbo.registry.common.domain.Override o = new com.alibaba.dubbo.registry.common.domain.Override();
    o.setId(id);
    Map<String, String> parameters = new HashMap<String, String>(url.getParameters());
    o.setService(url.getServiceKey());
    parameters.remove(Constants.INTERFACE_KEY);
    parameters.remove(Constants.GROUP_KEY);
    parameters.remove(Constants.VERSION_KEY);
    parameters.remove(Constants.APPLICATION_KEY);
    parameters.remove(Constants.CATEGORY_KEY);
    parameters.remove(Constants.DYNAMIC_KEY);
    parameters.remove(Constants.ENABLED_KEY);
    o.setEnabled(url.getParameter(Constants.ENABLED_KEY, true));
    String host = url.getHost();
    boolean anyhost = url.getParameter(Constants.ANYHOST_VALUE, false);
    if (!anyhost || !"0.0.0.0".equals(host)) {
        o.setAddress(url.getAddress());
    }
    o.setApplication(url.getParameter(Constants.APPLICATION_KEY, url.getUsername()));
    parameters.remove(Constants.VERSION_KEY);
    o.setParams(StringUtils.toQueryString(parameters));
    return o;
}
Also used : HashMap(java.util.HashMap) URL(com.alibaba.dubbo.common.URL)

Example 7 with URL

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

the class SyncUtils method filterFromUrls.

// Map<Long, URL>
static void filterFromUrls(Map<Long, URL> from, Map<Long, URL> to, Map<String, String> filter) {
    if (from == null || from.isEmpty())
        return;
    for (Map.Entry<Long, URL> entry : from.entrySet()) {
        URL url = entry.getValue();
        boolean match = true;
        for (Map.Entry<String, String> e : filter.entrySet()) {
            String key = e.getKey();
            String value = e.getValue();
            if (ADDRESS_FILTER_KEY.equals(key)) {
                if (!value.equals(url.getAddress())) {
                    match = false;
                    break;
                }
            } else {
                if (!value.equals(url.getParameter(key))) {
                    match = false;
                    break;
                }
            }
        }
        if (match) {
            to.put(entry.getKey(), url);
        }
    }
}
Also used : Map(java.util.Map) HashMap(java.util.HashMap) URL(com.alibaba.dubbo.common.URL)

Example 8 with URL

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

the class SyncUtils method url2Route.

public static Route url2Route(Pair<Long, URL> pair) {
    if (pair == null) {
        return null;
    }
    Long id = pair.getKey();
    URL url = pair.getValue();
    if (null == url)
        return null;
    Route r = new Route();
    r.setId(id);
    r.setName(url.getParameter("name"));
    r.setService(url.getServiceKey());
    r.setPriority(url.getParameter(Constants.PRIORITY_KEY, 0));
    r.setEnabled(url.getParameter(Constants.ENABLED_KEY, true));
    r.setForce(url.getParameter(Constants.FORCE_KEY, false));
    r.setRule(url.getParameterAndDecoded(Constants.RULE_KEY));
    return r;
}
Also used : URL(com.alibaba.dubbo.common.URL) Route(com.alibaba.dubbo.registry.common.domain.Route)

Example 9 with URL

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

the class OverrideServiceImpl method updateOverride.

public void updateOverride(Override override) {
    Long id = override.getId();
    if (id == null) {
        throw new IllegalStateException("no override id");
    }
    URL oldOverride = findOverrideUrl(id);
    if (oldOverride == null) {
        throw new IllegalStateException("Route was changed!");
    }
    URL newOverride = getUrlFromOverride(override);
    registryService.unregister(oldOverride);
    registryService.register(newOverride);
}
Also used : URL(com.alibaba.dubbo.common.URL)

Example 10 with URL

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

the class OverrideServiceImpl method enableOverride.

public void enableOverride(Long id) {
    if (id == null) {
        throw new IllegalStateException("no override id");
    }
    URL oldOverride = findOverrideUrl(id);
    if (oldOverride == null) {
        throw new IllegalStateException("Override was changed!");
    }
    if (oldOverride.getParameter("enabled", true)) {
        return;
    }
    URL newOverride = oldOverride.removeParameter("enabled");
    registryService.unregister(oldOverride);
    registryService.register(newOverride);
}
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