com.alibaba.dubbo.common.URL Java Examples

The following examples show how to use com.alibaba.dubbo.common.URL. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AbstractRegistry.java    From dubbo-2.6.5 with Apache License 2.0 6 votes vote down vote up
public AbstractRegistry(URL url) {
        setUrl(url);
        // Start file save timer 查询注册信息保存本地文件save.file
        syncSaveFile = url.getParameter(Constants.REGISTRY_FILESAVE_SYNC_KEY, false);
//        默认文件名 /Users/jiangweifeng/.dubbo/dubbo-registry-dubbo-provider-192.168.50.251:2181.cache
        String filename = url.getParameter(Constants.FILE_KEY, System.getProperty("user.home") + "/.dubbo/dubbo-registry-" + url.getParameter(Constants.APPLICATION_KEY) + "-" + url.getAddress() + ".cache");
        File file = null;
        if (ConfigUtils.isNotEmpty(filename)) {
            file = new File(filename);
            if (!file.exists() && file.getParentFile() != null && !file.getParentFile().exists()) {
                if (!file.getParentFile().mkdirs()) {
                    throw new IllegalArgumentException("Invalid registry store file " + file + ", cause: Failed to create directory " + file.getParentFile() + "!");
                }
            }
        }
        this.file = file;
//        从配置文件中加载注册
        loadProperties();
        notify(url.getBackupUrls());
    }
 
Example #2
Source File: HessianProtocol.java    From dubbox with Apache License 2.0 6 votes vote down vote up
protected <T> Runnable doExport(T impl, Class<T> type, URL url) throws RpcException {
    String addr = url.getIp() + ":" + url.getPort();
    HttpServer server = serverMap.get(addr);
    if (server == null) {
        server = httpBinder.bind(url, new HessianHandler());
        serverMap.put(addr, server);
    }
    final String path = url.getAbsolutePath();
    HessianSkeleton skeleton = new HessianSkeleton(impl, type);
    skeletonMap.put(path, skeleton);
    return new Runnable() {
        public void run() {
            skeletonMap.remove(path);
        }
    };
}
 
Example #3
Source File: RegistryDirectoryTest.java    From dubbox with Apache License 2.0 6 votes vote down vote up
/**
 * 测试override通过enable=false,禁用指定服务提供者
 * 预期:可以禁用指定的服务提供者。
 */
@Test
public void testNofityOverrideUrls_disabled_specifiedProvider(){
	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://10.20.30.140?"+Constants.DISABLED_KEY+"=true"));
    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("empty://0.0.0.0?"+Constants.DISABLED_KEY+"=true&"+Constants.CATEGORY_KEY+"="+Constants.CONFIGURATORS_CATEGORY));
    registryDirectory.notify(durls);
    List<Invoker<?>> invokers2 = registryDirectory.list(invocation);
    Assert.assertEquals(2,invokers2.size());
}
 
Example #4
Source File: ConfigTest.java    From dubbo3 with Apache License 2.0 6 votes vote down vote up
@Test
public void testMultiProtocolRegister() {
    SimpleRegistryService registryService = new SimpleRegistryService();
    Exporter<RegistryService> exporter = SimpleRegistryExporter.export(4547, registryService);
    ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(ConfigTest.class.getPackage().getName().replace('.', '/') + "/multi-protocol-register.xml");
    ctx.start();
    try {
        List<URL> urls = registryService.getRegistered().get("com.alibaba.dubbo.config.spring.api.DemoService");
        assertNotNull(urls);
        assertEquals(1, urls.size());
        assertEquals("dubbo://" + NetUtils.getLocalHost() + ":20824/com.alibaba.dubbo.config.spring.api.DemoService", urls.get(0).toIdentityString());
    } finally {
        ctx.stop();
        ctx.close();
        exporter.unexport();
    }
}
 
Example #5
Source File: ExtensionLoader.java    From dubbox with Apache License 2.0 6 votes vote down vote up
private boolean isActive(Activate activate, URL url) {
    String[] keys = activate.value();
    if (keys == null || keys.length == 0) {
        return true;
    }
    for (String key : keys) {
        for (Map.Entry<String, String> entry : url.getParameters().entrySet()) {
            String k = entry.getKey();
            String v = entry.getValue();
            if ((k.equals(key) || k.endsWith("." + key))
                    && ConfigUtils.isNotEmpty(v)) {
                return true;
            }
        }
    }
    return false;
}
 
Example #6
Source File: ReferenceCountExchangeClientTest.java    From dubbox with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
private void init(int connections){
    int port = NetUtils.getAvailablePort();
    URL demoUrl = URL.valueOf("dubbo://127.0.0.1:"+port+"/demo?"+Constants.CONNECTIONS_KEY+"="+connections);
    URL helloUrl = URL.valueOf("dubbo://127.0.0.1:"+port+"/hello?"+Constants.CONNECTIONS_KEY+"="+connections);
    
    demoExporter = export(new DemoServiceImpl(), IDemoService.class, demoUrl);
    helloExporter = export(new HelloServiceImpl(), IHelloService.class, helloUrl);
    
    demoServiceInvoker = (Invoker<IDemoService>) referInvoker(IDemoService.class, demoUrl);
    demoService = proxy.getProxy(demoServiceInvoker);
    Assert.assertEquals("demo", demoService.demo());
    
    helloServiceInvoker = (Invoker<IHelloService>) referInvoker(IHelloService.class, helloUrl);
    helloService = proxy.getProxy(helloServiceInvoker);
    Assert.assertEquals("hello", helloService.hello());
    
    demoClient = getClient(demoServiceInvoker);
    helloClient = getClient(helloServiceInvoker);
}
 
Example #7
Source File: RegistryProtocol.java    From dubbo-2.6.5 with Apache License 2.0 6 votes vote down vote up
private List<URL> getMatchedUrls(List<URL> configuratorUrls, URL currentSubscribe) {
    List<URL> result = new ArrayList<URL>();
    for (URL url : configuratorUrls) {
        URL overrideUrl = url;
        // Compatible with the old version
        if (url.getParameter(Constants.CATEGORY_KEY) == null
                && Constants.OVERRIDE_PROTOCOL.equals(url.getProtocol())) {
            overrideUrl = url.addParameter(Constants.CATEGORY_KEY, Constants.CONFIGURATORS_CATEGORY);
        }

        // Check whether url is to be applied to the current service 检查url是否应用于当前服务
        if (UrlUtils.isMatch(currentSubscribe, overrideUrl)) {
            result.add(url);
        }
    }
    return result;
}
 
Example #8
Source File: SimpleRegistryService.java    From dubbox-hystrix with Apache License 2.0 6 votes vote down vote up
public void subscribe(URL url, NotifyListener listener) {
    if (getUrl().getPort() == 0) {
        URL registryUrl = RpcContext.getContext().getUrl();
        if (registryUrl != null && registryUrl.getPort() > 0
        		&& RegistryService.class.getName().equals(registryUrl.getPath())) {
            super.setUrl(registryUrl);
            super.register(registryUrl);
        }
    }
    String client = RpcContext.getContext().getRemoteAddressString();
    ConcurrentMap<URL, Set<NotifyListener>> clientListeners = remoteSubscribed.get(client);
    if (clientListeners == null) {
        remoteSubscribed.putIfAbsent(client, new ConcurrentHashMap<URL, Set<NotifyListener>>());
        clientListeners = remoteSubscribed.get(client);
    }
    Set<NotifyListener> listeners = clientListeners.get(url);
    if (listeners == null) {
        clientListeners.putIfAbsent(url, new ConcurrentHashSet<NotifyListener>());
        listeners = clientListeners.get(url);
    }
    listeners.add(listener);
    super.subscribe(url, listener);
    subscribed(url, listener);
}
 
Example #9
Source File: FileGroup.java    From dubbox with Apache License 2.0 6 votes vote down vote up
@Override
public void leave(URL url) throws RemotingException {
    super.leave(url);
    try {
        String full = url.toFullString();
        String[] lines = IOUtils.readLines(file);
        List<String> saves = new ArrayList<String>();
        for (String line : lines) {
            if (full.equals(line)) {
                return;
            }
            saves.add(line);
        }
        IOUtils.appendLines(file, saves.toArray(new String[0]));
    } catch (IOException e) {
        throw new RemotingException(new InetSocketAddress(NetUtils.getLocalHost(), 0), getUrl().toInetSocketAddress(), e.getMessage(), e);
    }
}
 
Example #10
Source File: AbstractRegistry.java    From dubbox with Apache License 2.0 6 votes vote down vote up
public void subscribe(URL url, NotifyListener listener) {
    if (url == null) {
        throw new IllegalArgumentException("subscribe url == null");
    }
    if (listener == null) {
        throw new IllegalArgumentException("subscribe listener == null");
    }
    if (logger.isInfoEnabled()){
        logger.info("Subscribe: " + url);
    }
    Set<NotifyListener> listeners = subscribed.get(url);
    if (listeners == null) {
        subscribed.putIfAbsent(url, new ConcurrentHashSet<NotifyListener>());
        listeners = subscribed.get(url);
    }
    listeners.add(listener);
}
 
Example #11
Source File: ProviderServiceImpl.java    From dubbox with Apache License 2.0 5 votes vote down vote up
public void updateProvider(Provider provider) {
    Long id = provider.getId();
    if(id == null) {
        throw new IllegalStateException("no provider id");
    }
    
    URL oldProvider = findProviderUrl(id);
    if(oldProvider == null) {
        throw new IllegalStateException("Provider was changed!");
    }
    URL newProvider = provider.toUrl();
    
    registryService.unregister(oldProvider);
    registryService.register(newProvider);
}
 
Example #12
Source File: AbstractRegistry.java    From dubbo-2.6.5 with Apache License 2.0 5 votes vote down vote up
private void saveProperties(URL url) {
        if (file == null) {
            return;
        }

        try {
            StringBuilder buf = new StringBuilder();
            Map<String, List<URL>> categoryNotified = notified.get(url);
            if (categoryNotified != null) {
                for (List<URL> us : categoryNotified.values()) {
                    for (URL u : us) {
                        if (buf.length() > 0) {
                            buf.append(URL_SEPARATOR);
                        }
                        buf.append(u.toFullString());
                    }
                }
            }
            properties.setProperty(url.getServiceKey(), buf.toString());
//            配置文件最后一次修改的版本号
            long version = lastCacheChanged.incrementAndGet();
//            同步保存
            if (syncSaveFile) {
//                nio方式保存注册信息到文件
                doSaveProperties(version);
//                异步保存
            } else {
                registryCacheExecutor.execute(new SaveProperties(version));
            }
        } catch (Throwable t) {
            logger.warn(t.getMessage(), t);
        }
    }
 
Example #13
Source File: FailbackRegistryTest.java    From dubbo3 with Apache License 2.0 5 votes vote down vote up
@Override
protected void doSubscribe(URL url, NotifyListener listener) {
    if (bad) {
        throw new RuntimeException("can not invoke!");
    }
    //System.out.println("do doSubscribe");
    super.notify(url, listener, Arrays.asList(new URL[] { serviceUrl }));
    latch.countDown();
}
 
Example #14
Source File: ConfigTest.java    From dubbox with Apache License 2.0 5 votes vote down vote up
@Test
public void test_noMethodInterface_methodsKeyHasValue() throws Exception {
    ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(ConfigTest.class.getPackage().getName().replace('.', '/') + "/demo-provider-no-methods-interface.xml");
    ctx.start();
    try {
        ServiceBean bean = (ServiceBean) ctx.getBean("service");
        List<URL> urls = bean.getExportedUrls();
        assertEquals(1, urls.size());
        URL url = urls.get(0);
        assertEquals("sayName,getBox", url.getParameter("methods"));
    } finally {
        ctx.stop();
        ctx.close();
    }
}
 
Example #15
Source File: RpcUtils.java    From dubbox-hystrix with Apache License 2.0 5 votes vote down vote up
private static boolean isAttachInvocationId(URL url , Invocation invocation) {
	String value = url.getMethodParameter(invocation.getMethodName(), Constants.AUTO_ATTACH_INVOCATIONID_KEY);
	if ( value == null ) {
		//异步操作默认添加invocationid
		return isAsync(url,invocation) ;
	} else if (Boolean.TRUE.toString().equalsIgnoreCase(value)) {
		//设置为添加,则一定添加
		return true;
	} else {
		//value为false时,不添加
		return false;
	}
}
 
Example #16
Source File: AbstractRegistryService.java    From dubbo-2.6.5 with Apache License 2.0 5 votes vote down vote up
@Override
public void register(URL url) {
    if (logger.isInfoEnabled()) {
        logger.info("Register service: " + url.getServiceKey() + ",url:" + url);
    }
    register(url.getServiceKey(), url);
}
 
Example #17
Source File: ConditionRouterTest.java    From dubbox with Apache License 2.0 5 votes vote down vote up
@Test
public void testRoute_NoForce(){
    Router router = new ConditionRouterFactory().getRouter(getRouteUrl("host = " + NetUtils.getLocalHost() + " => " + " host = 1.2.3.4"));
    List<Invoker<String>> invokers = new ArrayList<Invoker<String>>();
    Invoker<String> invoker1 = new MockInvoker<String>(URL.valueOf("dubbo://10.20.3.3:20880/com.foo.BarService")) ;
    Invoker<String> invoker2 = new MockInvoker<String>(URL.valueOf("dubbo://" + NetUtils.getLocalHost() + ":20880/com.foo.BarService")) ;
    Invoker<String> invoker3 = new MockInvoker<String>(URL.valueOf("dubbo://" + NetUtils.getLocalHost() + ":20880/com.foo.BarService")) ;
    invokers.add(invoker1);
    invokers.add(invoker2);
    invokers.add(invoker3);
    List<Invoker<String>> fileredInvokers = router.route(invokers, URL.valueOf("consumer://" + NetUtils.getLocalHost() + "/com.foo.BarService"), new RpcInvocation());
    Assert.assertEquals(invokers, fileredInvokers);
}
 
Example #18
Source File: ProviderConsumerRegTable.java    From dubbo-2.6.5 with Apache License 2.0 5 votes vote down vote up
public static void registerProvider(Invoker invoker, URL registryUrl, URL providerUrl) {
        ProviderInvokerWrapper wrapperInvoker = new ProviderInvokerWrapper(invoker, registryUrl, providerUrl);
//        service唯一的名字 group/interface:version helloGroup/com.tianhe.lianxi.dubbo.api.HelloFacade:1.0.0
        String serviceUniqueName = providerUrl.getServiceKey();
        Set<ProviderInvokerWrapper> invokers = providerInvokers.get(serviceUniqueName);
        if (invokers == null) {
            providerInvokers.putIfAbsent(serviceUniqueName, new ConcurrentHashSet<ProviderInvokerWrapper>());
//            ProviderInvokerWrapper
            invokers = providerInvokers.get(serviceUniqueName);
        }
        invokers.add(wrapperInvoker);
    }
 
Example #19
Source File: SimpleRegistryService.java    From dubbox-hystrix with Apache License 2.0 5 votes vote down vote up
@Override
public void unsubscribe(String service, URL url, NotifyListener listener) {
    super.unsubscribe(service, url, listener);
    String client = RpcContext.getContext().getRemoteAddressString();
    Map<String, NotifyListener> listeners = remoteListeners.get(client);
    if (listeners != null && listeners.size() > 0) {
        listeners.remove(service);
    }
    List<URL> urls = getRegistered().get(service);
    if (urls != null && urls.size() > 0) {
        listener.notify(urls);
    }
}
 
Example #20
Source File: NettyChannel.java    From dubbox with Apache License 2.0 5 votes vote down vote up
private NettyChannel(org.jboss.netty.channel.Channel channel, URL url, ChannelHandler handler){
    super(url, handler);
    if (channel == null) {
        throw new IllegalArgumentException("netty channel == null;");
    }
    this.channel = channel;
}
 
Example #21
Source File: Overrides.java    From dubbox with Apache License 2.0 5 votes vote down vote up
public void show(Long id, Map<String, Object> context) {
    Override override = overrideService.findById(id);
    
    Map<String, String> parameters = parseQueryString(override.getParams());

    if(parameters.get(DEFAULT_MOCK_JSON_KEY) != null) {
        String mock = URL.decode(parameters.get(DEFAULT_MOCK_JSON_KEY));
        String[] tokens = parseMock(mock);
        context.put(FORM_DEFAULT_MOCK_METHOD_FORCE, tokens[0]);
        context.put(FORM_DEFAULT_MOCK_METHOD_JSON, tokens[1]);
        parameters.remove(DEFAULT_MOCK_JSON_KEY);
    }
    
    Map<String, String> method2Force = new LinkedHashMap<String, String>();
    Map<String, String> method2Json = new LinkedHashMap<String, String>();
    
    for (Iterator<Map.Entry<String, String>> iterator = parameters.entrySet().iterator(); iterator.hasNext();) {
        Map.Entry<String, String> e =  iterator.next();
        String key = e.getKey();
        
        if(key.endsWith(MOCK_JSON_KEY_POSTFIX)) {
            String m = key.substring(0, key.length() - MOCK_JSON_KEY_POSTFIX.length());
            parseMock(m, e.getValue(), method2Force, method2Json);
            iterator.remove();
        }
    }
    
    context.put("methodForces", method2Force);
    context.put("methodJsons", method2Json);
    context.put("parameters", parameters);
    context.put("override", override);
}
 
Example #22
Source File: SyncUtils.java    From dubbox with Apache License 2.0 5 votes vote down vote up
public static <SM extends Map<String, Map<Long, URL>>> Pair<Long, URL> filterFromCategory(Map<String, SM> urls, String category, Long id) {
    SM services = urls.get(category);
    if(services == null) return null;
    
    for(Map.Entry<String, Map<Long, URL>> e1 : services.entrySet()) {
        Map<Long, URL> u = e1.getValue();
        if(u.containsKey(id)) return new Pair<Long, URL>(id, u.get(id));
    }
    return null;
}
 
Example #23
Source File: ZookeeperRegistry.java    From dubbox with Apache License 2.0 5 votes vote down vote up
protected void doRegister(URL url) {
    try {
    	zkClient.create(toUrlPath(url), url.getParameter(Constants.DYNAMIC_KEY, true));
    } catch (Throwable e) {
        throw new RpcException("Failed to register " + url + " to zookeeper " + getUrl() + ", cause: " + e.getMessage(), e);
    }
}
 
Example #24
Source File: MockClusterInvokerTest.java    From dubbox with Apache License 2.0 5 votes vote down vote up
/**
 * 测试mock策略是否正常-fail-mock
 */
@Test
public void testMockInvokerFromOverride_Invoke_checkCompatible_ImplMock2(){
	URL url = URL.valueOf("remote://1.2.3.4/"+IHelloService.class.getName())
			.addParameter("mock","fail")
			.addParameter("invoke_return_error", "true" );
	Invoker<IHelloService> cluster = getClusterInvoker(url);        
	//方法配置了mock
       RpcInvocation invocation = new RpcInvocation();
	invocation.setMethodName("getSomething");
       Result ret = cluster.invoke(invocation);
       Assert.assertEquals("somethingmock", ret.getValue());
}
 
Example #25
Source File: RegistryDirectoryTest.java    From dubbox with Apache License 2.0 5 votes vote down vote up
/**
 * 测试override规则是否优先
 * 场景:先推送override,后推送invoker
 */
@Test
public void testNotifyoverrideUrls_afterInvoker(){
    RegistryDirectory registryDirectory = getRegistryDirectory();
    
    //在推送两个provider,directory状态恢复为true
    List<URL> serviceUrls = new ArrayList<URL>();
    serviceUrls.add(SERVICEURL.addParameter("timeout", "1000"));
    serviceUrls.add(SERVICEURL2.addParameter("timeout", "1000").addParameter("connections", "10"));

    registryDirectory.notify(serviceUrls);
    Assert.assertEquals(true, registryDirectory.isAvailable());
    
    List<URL> overrideUrls = new ArrayList<URL>();
    overrideUrls.add(URL.valueOf("override://0.0.0.0?timeout=1&connections=5"));
    registryDirectory.notify(overrideUrls);
    
    //开始验证参数值

    invocation = new RpcInvocation();

    List<Invoker<?>> invokers = registryDirectory.list(invocation);
    Assert.assertEquals(2, invokers.size());
    
    Assert.assertEquals("override rute must be first priority", "1", invokers.get(0).getUrl().getParameter("timeout"));
    Assert.assertEquals("override rute must be first priority", "5", invokers.get(0).getUrl().getParameter("connections"));
}
 
Example #26
Source File: DubboProtocol.java    From dubbox-hystrix with Apache License 2.0 5 votes vote down vote up
public <T> Exporter<T> export(Invoker<T> invoker) throws RpcException {
    URL url = invoker.getUrl();
    
    // export service.
    String key = serviceKey(url);
    DubboExporter<T> exporter = new DubboExporter<T>(invoker, key, exporterMap);
    exporterMap.put(key, exporter);
    
    //export an stub service for dispaching event
    Boolean isStubSupportEvent = url.getParameter(Constants.STUB_EVENT_KEY,Constants.DEFAULT_STUB_EVENT);
    Boolean isCallbackservice = url.getParameter(Constants.IS_CALLBACK_SERVICE, false);
    if (isStubSupportEvent && !isCallbackservice){
        String stubServiceMethods = url.getParameter(Constants.STUB_EVENT_METHODS_KEY);
        if (stubServiceMethods == null || stubServiceMethods.length() == 0 ){
            if (logger.isWarnEnabled()){
                logger.warn(new IllegalStateException("consumer [" +url.getParameter(Constants.INTERFACE_KEY) +
                        "], has set stubproxy support event ,but no stub methods founded."));
            }
        } else {
            stubServiceMethodsMap.put(url.getServiceKey(), stubServiceMethods);
        }
    }

    openServer(url);

    // modified by lishen
    optimizeSerialization(url);

    return exporter;
}
 
Example #27
Source File: SyncUtils.java    From dubbox with Apache License 2.0 5 votes vote down vote up
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);
        }
    }
}
 
Example #28
Source File: AbstractPeer.java    From dubbo-2.6.5 with Apache License 2.0 5 votes vote down vote up
public AbstractPeer(URL url, ChannelHandler handler) {
    if (url == null) {
        throw new IllegalArgumentException("url == null");
    }
    if (handler == null) {
        throw new IllegalArgumentException("handler == null");
    }
    this.url = url;
    this.handler = handler;
}
 
Example #29
Source File: FailbackRegistry.java    From dubbo3 with Apache License 2.0 5 votes vote down vote up
@Override
public void unsubscribe(URL url, NotifyListener listener) {
    super.unsubscribe(url, listener);
    removeFailedSubscribed(url, listener);
    try {
        // 向服务器端发送取消订阅请求
        doUnsubscribe(url, listener);
    } catch (Exception e) {
        Throwable t = e;

        // 如果开启了启动时检测,则直接抛出异常
        boolean check = getUrl().getParameter(Constants.CHECK_KEY, true)
                && url.getParameter(Constants.CHECK_KEY, true);
        boolean skipFailback = t instanceof SkipFailbackWrapperException;
        if (check || skipFailback) {
            if(skipFailback) {
                t = t.getCause();
            }
            throw new IllegalStateException("Failed to unsubscribe " + url + " to registry " + getUrl().getAddress() + ", cause: " + t.getMessage(), t);
        } else {
            logger.error("Failed to unsubscribe " + url + ", waiting for retry, cause: " + t.getMessage(), t);
        }

        // 将失败的取消订阅请求记录到失败列表,定时重试
        Set<NotifyListener> listeners = failedUnsubscribed.get(url);
        if (listeners == null) {
            failedUnsubscribed.putIfAbsent(url, new ConcurrentHashSet<NotifyListener>());
            listeners = failedUnsubscribed.get(url);
        }
        listeners.add(listener);
    }
}
 
Example #30
Source File: JCache.java    From dubbo-2.6.5 with Apache License 2.0 5 votes vote down vote up
public JCache(URL url) {
    String method = url.getParameter(Constants.METHOD_KEY, "");
    String key = url.getAddress() + "." + url.getServiceKey() + "." + method;
    // jcache parameter is the full-qualified class name of SPI implementation
    String type = url.getParameter("jcache");

    CachingProvider provider = type == null || type.length() == 0 ? Caching.getCachingProvider() : Caching.getCachingProvider(type);
    CacheManager cacheManager = provider.getCacheManager();
    Cache<Object, Object> cache = cacheManager.getCache(key);
    if (cache == null) {
        try {
            //configure the cache
            MutableConfiguration config =
                    new MutableConfiguration<Object, Object>()
                            .setTypes(Object.class, Object.class)
                            .setExpiryPolicyFactory(CreatedExpiryPolicy.factoryOf(new Duration(TimeUnit.MILLISECONDS, url.getMethodParameter(method, "cache.write.expire", 60 * 1000))))
                            .setStoreByValue(false)
                            .setManagementEnabled(true)
                            .setStatisticsEnabled(true);
            cache = cacheManager.createCache(key, config);
        } catch (CacheException e) {
            // concurrent cache initialization
            cache = cacheManager.getCache(key);
        }
    }

    this.store = cache;
}