當前位置: 首頁>>代碼示例>>Java>>正文


Java URL類代碼示例

本文整理匯總了Java中com.alibaba.dubbo.common.URL的典型用法代碼示例。如果您正苦於以下問題:Java URL類的具體用法?Java URL怎麽用?Java URL使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


URL類屬於com.alibaba.dubbo.common包,在下文中一共展示了URL類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: testNofity_disabled_specifiedProvider

import com.alibaba.dubbo.common.URL; //導入依賴的package包/類
/**
 * 測試override通過enable=false,禁用指定服務提供者
 * 預期:可以禁用指定的服務提供者。
 */
@Test
public void testNofity_disabled_specifiedProvider(){
	RegistryDirectory registryDirectory = getRegistryDirectory();
    invocation = new RpcInvocation();
    
    // 初始就禁用
    List<URL> durls = new ArrayList<URL>();
    durls.add(SERVICEURL.setHost("10.20.30.140").addParameter(Constants.ENABLED_KEY, "false"));
    durls.add(SERVICEURL.setHost("10.20.30.141"));
    registryDirectory.notify(durls);
    
    List<Invoker<?>> invokers = registryDirectory.list(invocation);
    Assert.assertEquals(1,invokers.size());
    Assert.assertEquals("10.20.30.141", invokers.get(0).getUrl().getHost());
    
    // 通過覆蓋規則啟用
    durls = new ArrayList<URL>();
    durls.add(URL.valueOf("override://10.20.30.140?"+Constants.DISABLED_KEY+"=false"));
    registryDirectory.notify(durls);
    List<Invoker<?>> invokers2 = registryDirectory.list(invocation);
    Assert.assertEquals(2,invokers2.size());
}
 
開發者ID:yunhaibin,項目名稱:dubbox-hystrix,代碼行數:27,代碼來源:RegistryDirectoryTest.java

示例2: isProviderSide

import com.alibaba.dubbo.common.URL; //導入依賴的package包/類
/**
 * is provider side.
 * 
 * @return provider side.
 */
public boolean isProviderSide() {
    URL url = getUrl();
    if (url == null) {
        return false;
    }
    InetSocketAddress address = getRemoteAddress();
    if (address == null) {
        return false;
    }
    String host;
    if (address.getAddress() == null) {
        host = address.getHostName();
    } else {
        host = address.getAddress().getHostAddress();
    }
    return url.getPort() != address.getPort() || 
            ! NetUtils.filterLocalHost(url.getIp()).equals(NetUtils.filterLocalHost(host));
}
 
開發者ID:yunhaibin,項目名稱:dubbox-hystrix,代碼行數:24,代碼來源:RpcContext.java

示例3: test_Notified_acceptProtocol1

import com.alibaba.dubbo.common.URL; //導入依賴的package包/類
@Test
public void test_Notified_acceptProtocol1() {
	URL errorPathUrl  = URL.valueOf("notsupport:/xxx");
	errorPathUrl = errorPathUrl.addParameterAndEncoded(Constants.REFER_KEY, "interface="+service + "&protocol=dubbo");
    RegistryDirectory registryDirectory = getRegistryDirectory(errorPathUrl);
    List<URL> serviceUrls = new ArrayList<URL>();
    URL dubbo1URL = URL.valueOf("dubbo://127.0.0.1:9098?lazy=true&methods=getXXX");
    URL dubbo2URL = URL.valueOf("injvm://127.0.0.1:9098?lazy=true&methods=getXXX");
    serviceUrls.add(dubbo1URL);
    serviceUrls.add(dubbo2URL);
    registryDirectory.notify(serviceUrls);

    invocation = new RpcInvocation();

    List<Invoker<DemoService>> invokers = registryDirectory.list(invocation);
    Assert.assertEquals(1, invokers.size());
}
 
開發者ID:flychao88,項目名稱:dubbocloud,代碼行數:18,代碼來源:RegistryDirectoryTest.java

示例4: test_urlHolder_getAdaptiveExtension_ExceptionWhenNotAdativeMethod

import com.alibaba.dubbo.common.URL; //導入依賴的package包/類
@Test
public void test_urlHolder_getAdaptiveExtension_ExceptionWhenNotAdativeMethod() throws Exception {
    Ext2 ext = ExtensionLoader.getExtensionLoader(Ext2.class).getAdaptiveExtension();

    Map<String, String> map = new HashMap<String, String>();
    URL url = new URL("p1", "1.2.3.4", 1010, "path1", map);

    try {
        ext.bang(url, 33);
        fail();
    } catch (UnsupportedOperationException expected) {
        assertThat(expected.getMessage(), containsString("method "));
        assertThat(
                expected.getMessage(),
                containsString("of interface com.alibaba.dubbo.common.extensionloader.ext2.Ext2 is not adaptive method!"));
    }
}
 
開發者ID:dachengxi,項目名稱:EatDubbo,代碼行數:18,代碼來源:ExtensionLoader_Adaptive_Test.java

示例5: testNofityOverrideUrls_disabled_allProvider

import com.alibaba.dubbo.common.URL; //導入依賴的package包/類
/**
 * 測試override通過enable=false,禁用所有服務提供者
 * 預期:不能通過override禁用所有服務提供者.
 */
@Test
public void testNofityOverrideUrls_disabled_allProvider(){
	RegistryDirectory registryDirectory = getRegistryDirectory();
    invocation = new RpcInvocation();
    
    List<URL> durls = new ArrayList<URL>();
    durls.add(SERVICEURL.setHost("10.20.30.140"));
    durls.add(SERVICEURL.setHost("10.20.30.141"));
    registryDirectory.notify(durls);
    
    durls = new ArrayList<URL>();
    durls.add(URL.valueOf("override://0.0.0.0?"+Constants.ENABLED_KEY+"=false"));
    registryDirectory.notify(durls);
    
    List<Invoker<?>> invokers = registryDirectory.list(invocation);
    //不能通過override禁用所有服務提供者.
    Assert.assertEquals(2,invokers.size());
}
 
開發者ID:yunhaibin,項目名稱:dubbox-hystrix,代碼行數:23,代碼來源:RegistryDirectoryTest.java

示例6: ConditionRouter

import com.alibaba.dubbo.common.URL; //導入依賴的package包/類
public ConditionRouter(URL url) {
    this.url = url;
    this.priority = url.getParameter(Constants.PRIORITY_KEY, 0);
    this.force = url.getParameter(Constants.FORCE_KEY, false);
    try {
        String rule = url.getParameterAndDecoded(Constants.RULE_KEY);
        if (rule == null || rule.trim().length() == 0) {
            throw new IllegalArgumentException("Illegal route rule!");
        }
        rule = rule.replace("consumer.", "").replace("provider.", "");
        int i = rule.indexOf("=>");
        String whenRule = i < 0 ? null : rule.substring(0, i).trim();
        String thenRule = i < 0 ? rule.trim() : rule.substring(i + 2).trim();
        Map<String, MatchPair> when = StringUtils.isBlank(whenRule) || "true".equals(whenRule) ? new HashMap<String, MatchPair>() : parseRule(whenRule);
        Map<String, MatchPair> then = StringUtils.isBlank(thenRule) || "false".equals(thenRule) ? null : parseRule(thenRule);
        // NOTE: When條件是允許為空的,外部業務來保證類似的約束條件
        this.whenCondition = when;
        this.thenCondition = then;
    } catch (ParseException e) {
        throw new IllegalStateException(e.getMessage(), e);
    }
}
 
開發者ID:flychao88,項目名稱:dubbocloud,代碼行數:23,代碼來源:ConditionRouter.java

示例7: notify

import com.alibaba.dubbo.common.URL; //導入依賴的package包/類
@Override
protected void notify(URL url, NotifyListener listener, List<URL> urls) {
    if (url == null) {
        throw new IllegalArgumentException("notify url == null");
    }
    if (listener == null) {
        throw new IllegalArgumentException("notify listener == null");
    }
    try {
    	doNotify(url, listener, urls);
    } catch (Exception t) {
        // 將失敗的通知請求記錄到失敗列表,定時重試
        Map<NotifyListener, List<URL>> listeners = failedNotified.get(url);
        if (listeners == null) {
            failedNotified.putIfAbsent(url, new ConcurrentHashMap<NotifyListener, List<URL>>());
            listeners = failedNotified.get(url);
        }
        listeners.put(listener, urls);
        logger.error("Failed to notify for subscribe " + url + ", waiting for retry, cause: " + t.getMessage(), t);
    }
}
 
開發者ID:yunhaibin,項目名稱:dubbox-hystrix,代碼行數:22,代碼來源:FailbackRegistry.java

示例8: findMethodsByService

import com.alibaba.dubbo.common.URL; //導入依賴的package包/類
public List<String> findMethodsByService(String service) {
    List<String> ret = new ArrayList<String>();

    ConcurrentMap<String, Map<Long, URL>> providerUrls = getRegistryCache().get(Constants.PROVIDERS_CATEGORY);
    if(providerUrls == null || service == null || service.length() == 0) return ret;
    
    Map<Long, URL> providers = providerUrls.get(service);
    if(null == providers || providers.isEmpty()) return ret;
    
    Entry<Long, URL> p = providers.entrySet().iterator().next();
    String value = p.getValue().getParameter("methods");
    if (value == null || value.length() == 0) {
        return ret;
    }
    String[] methods = value.split(ParseUtils.METHOD_SPLIT);
    if (methods == null || methods.length == 0) {
        return ret;
    }
    
    for(String m : methods) {
        ret.add(m);
    }
    return ret;
}
 
開發者ID:flychao88,項目名稱:dubbocloud,代碼行數:25,代碼來源:ProviderServiceImpl.java

示例9: ConsistentHashSelector

import com.alibaba.dubbo.common.URL; //導入依賴的package包/類
public ConsistentHashSelector(List<Invoker<T>> invokers, String methodName, int identityHashCode) {
    this.virtualInvokers = new TreeMap<Long, Invoker<T>>();
    this.identityHashCode = System.identityHashCode(invokers);
    URL url = invokers.get(0).getUrl();
    this.replicaNumber = url.getMethodParameter(methodName, "hash.nodes", 160);
    String[] index = Constants.COMMA_SPLIT_PATTERN.split(url.getMethodParameter(methodName, "hash.arguments", "0"));
    argumentIndex = new int[index.length];
    for (int i = 0; i < index.length; i ++) {
        argumentIndex[i] = Integer.parseInt(index[i]);
    }
    for (Invoker<T> invoker : invokers) {
        for (int i = 0; i < replicaNumber / 4; i++) {
            byte[] digest = md5(invoker.getUrl().toFullString() + i);
            for (int h = 0; h < 4; h++) {
                long m = hash(digest, h);
                virtualInvokers.put(m, invoker);
            }
        }
    }
}
 
開發者ID:flychao88,項目名稱:dubbocloud,代碼行數:21,代碼來源:ConsistentHashLoadBalance.java

示例10: handle

import com.alibaba.dubbo.common.URL; //導入依賴的package包/類
public Page handle(URL url) {
    String consumer = url.getParameterAndDecoded("consumer");
    if (consumer == null || consumer.length() == 0) {
        throw new IllegalArgumentException("Please input consumer parameter.");
    }
    URL consumerUrl = URL.valueOf(consumer);
    RegistryContainer.getInstance().getRegistry().unsubscribe(consumerUrl, NotifyListenerAdapter.NOTIFY_LISTENER);
    String parameter;
    if (url.hasParameter("service")) {
        parameter = "service=" + url.getParameter("service");
    } else if (url.hasParameter("host")) {
        parameter = "host=" + url.getParameter("host");
    } else if (url.hasParameter("application")) {
        parameter = "application=" + url.getParameter("application");
    } else {
        parameter = "service=" + consumerUrl.getServiceInterface();
    }
    return new Page("<script type=\"text/javascript\">window.location.href=\"consumers.html?" + parameter + "\";</script>");
}
 
開發者ID:flychao88,項目名稱:dubbocloud,代碼行數:20,代碼來源:UnsubscribePageHandler.java

示例11: getExporter

import com.alibaba.dubbo.common.URL; //導入依賴的package包/類
static Exporter<?> getExporter(Map<String, Exporter<?>> map, URL key) {
    Exporter<?> result = null;

    if (!key.getServiceKey().contains("*")) {
        result = map.get(key.getServiceKey());
    } else {
        if (map != null && !map.isEmpty()) {
            for (Exporter<?> exporter : map.values()) {
                if (UrlUtils.isServiceKeyMatch(key, exporter.getInvoker().getUrl())) {
                    result = exporter;
                    break;
                }
            }
        }
    }

    if (result == null) {
        return null;
    } else if (ProtocolUtils.isGeneric(
        result.getInvoker().getUrl().getParameter(Constants.GENERIC_KEY))) {
        return null;
    } else {
        return result;
    }
}
 
開發者ID:dachengxi,項目名稱:EatDubbo,代碼行數:26,代碼來源:InjvmProtocol.java

示例12: ZookeeperRegistry

import com.alibaba.dubbo.common.URL; //導入依賴的package包/類
public ZookeeperRegistry(URL url, ZookeeperTransporter zookeeperTransporter) {
    super(url);
    if (url.isAnyHost()) {
		throw new IllegalStateException("registry address == null");
	}
    String group = url.getParameter(Constants.GROUP_KEY, DEFAULT_ROOT);
    if (! group.startsWith(Constants.PATH_SEPARATOR)) {
        group = Constants.PATH_SEPARATOR + group;
    }
    this.root = group;
    zkClient = zookeeperTransporter.connect(url);
    zkClient.addStateListener(new StateListener() {
        public void stateChanged(int state) {
        	if (state == RECONNECTED) {
         	try {
		recover();
	} catch (Exception e) {
		logger.error(e.getMessage(), e);
	}
        	}
        }
    });
}
 
開發者ID:dachengxi,項目名稱:EatDubbo,代碼行數:24,代碼來源:ZookeeperRegistry.java

示例13: findServicesByAddress

import com.alibaba.dubbo.common.URL; //導入依賴的package包/類
public List<String> findServicesByAddress(String address) {
    List<String> ret = new ArrayList<String>();
    
    ConcurrentMap<String, Map<Long, URL>> providerUrls = getRegistryCache().get(Constants.PROVIDERS_CATEGORY);
    if(providerUrls == null || address == null || address.length() == 0) 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();
            if(address.equals(u.getAddress())) {
                ret.add(e1.getKey());
                break;
            }
        }
    }
    
    return ret;
}
 
開發者ID:flychao88,項目名稱:dubbocloud,代碼行數:20,代碼來源:ProviderServiceImpl.java

示例14: encodeInvocationArgument

import com.alibaba.dubbo.common.URL; //導入依賴的package包/類
public static Object encodeInvocationArgument(Channel channel, RpcInvocation inv, int paraIndex) throws IOException{
    //encode時可直接獲取url
    URL url = inv.getInvoker() == null ? null : inv.getInvoker().getUrl();
    byte callbackstatus = isCallBack(url, inv.getMethodName(), paraIndex);
    Object[] args = inv.getArguments();
    Class<?>[] pts = inv.getParameterTypes();
    switch (callbackstatus) {
        case CallbackServiceCodec.CALLBACK_NONE:
            return args[paraIndex];
        case CallbackServiceCodec.CALLBACK_CREATE:
            inv.setAttachment(INV_ATT_CALLBACK_KEY + paraIndex , exportOrunexportCallbackService(channel, url, pts[paraIndex], args[paraIndex], true));
            return null;
        case CallbackServiceCodec.CALLBACK_DESTROY:
            inv.setAttachment(INV_ATT_CALLBACK_KEY + paraIndex, exportOrunexportCallbackService(channel, url, pts[paraIndex], args[paraIndex], false));
            return null;
        default:
            return args[paraIndex];
    }
}
 
開發者ID:zhuxiaolei,項目名稱:dubbo2,代碼行數:20,代碼來源:CallbackServiceCodec.java

示例15: doRefer

import com.alibaba.dubbo.common.URL; //導入依賴的package包/類
private <T> Invoker<T> doRefer(Cluster cluster, Registry registry, Class<T> type, URL url) {
    RegistryDirectory<T> directory = new RegistryDirectory<T>(type, url);
    directory.setRegistry(registry);
    directory.setProtocol(protocol);
    URL subscribeUrl = new URL(Constants.CONSUMER_PROTOCOL, NetUtils.getLocalHost(), 0, type.getName(), directory.getUrl().getParameters());
    if (! Constants.ANY_VALUE.equals(url.getServiceInterface())
            && url.getParameter(Constants.REGISTER_KEY, true)) {
        registry.register(subscribeUrl.addParameters(Constants.CATEGORY_KEY, Constants.CONSUMERS_CATEGORY,
                Constants.CHECK_KEY, String.valueOf(false)));
    }
    directory.subscribe(subscribeUrl.addParameter(Constants.CATEGORY_KEY, 
            Constants.PROVIDERS_CATEGORY 
            + "," + Constants.CONFIGURATORS_CATEGORY 
            + "," + Constants.ROUTERS_CATEGORY));
    return cluster.join(directory);
}
 
開發者ID:zhuxiaolei,項目名稱:dubbo2,代碼行數:17,代碼來源:RegistryProtocol.java


注:本文中的com.alibaba.dubbo.common.URL類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。