当前位置: 首页>>代码示例>>Java>>正文


Java NotifyListener类代码示例

本文整理汇总了Java中com.alibaba.dubbo.registry.NotifyListener的典型用法代码示例。如果您正苦于以下问题:Java NotifyListener类的具体用法?Java NotifyListener怎么用?Java NotifyListener使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


NotifyListener类属于com.alibaba.dubbo.registry包,在下文中一共展示了NotifyListener类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: subscribe

import com.alibaba.dubbo.registry.NotifyListener; //导入依赖的package包/类
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);
}
 
开发者ID:dachengxi,项目名称:EatDubbo,代码行数:25,代码来源:SimpleRegistryService.java

示例2: notify

import com.alibaba.dubbo.registry.NotifyListener; //导入依赖的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:zhuxiaolei,项目名称:dubbo2,代码行数:22,代码来源:FailbackRegistry.java

示例3: testSubscribe

import com.alibaba.dubbo.registry.NotifyListener; //导入依赖的package包/类
/**
 * Test method for
 * {@link com.alibaba.dubbo.registry.support.injvm.InjvmRegistry#subscribe(java.util.Map, com.alibaba.dubbo.registry.support.NotifyListener)}
 * .
 */
@Test
public void testSubscribe() {
    // verify lisener.
    final AtomicReference<URL> args = new AtomicReference<URL>();
    registry.subscribe(consumerUrl, new NotifyListener() {

        public void notify(List<URL> urls) {
            // FIXME assertEquals(MulticastRegistry.this.service, service);
            args.set(urls.get(0));
        }
    });
    assertEquals(serviceUrl.toFullString(), args.get().toFullString());
    Map<URL, Set<NotifyListener>> arg = registry.getSubscribed();
    assertEquals(consumerUrl, arg.keySet().iterator().next());

}
 
开发者ID:flychao88,项目名称:dubbocloud,代码行数:22,代码来源:MulticastRegistryTest.java

示例4: testNotifyOverride_notmatch

import com.alibaba.dubbo.registry.NotifyListener; //导入依赖的package包/类
/**
 * 服务名称不匹配,不能override invoker
 * 服务名称匹配,服务版本号不匹配
 */
@Test
public void testNotifyOverride_notmatch() throws Exception{
    URL newRegistryUrl = registryUrl.addParameter(Constants.EXPORT_KEY, serviceUrl);
    Invoker<RegistryProtocolTest> invoker = new MockInvoker<RegistryProtocolTest>(RegistryProtocolTest.class, newRegistryUrl);
    Exporter<?> exporter = protocol.export(invoker);
    RegistryProtocol rprotocol = RegistryProtocol.getRegistryProtocol();
    NotifyListener listener = getListener(rprotocol);
    List<URL> urls = new ArrayList<URL>();
    urls.add(URL.valueOf("override://0.0.0.0/com.alibaba.dubbo.registry.protocol.HackService?timeout=100"));
    listener.notify(urls);
    assertEquals(true, exporter.getInvoker().isAvailable());
    assertEquals(null, exporter.getInvoker().getUrl().getParameter("timeout"));
    exporter.unexport();
    destroyRegistryProtocol();
}
 
开发者ID:dachengxi,项目名称:EatDubbo,代码行数:20,代码来源:RegistryProtocolTest.java

示例5: testNotifyOverride_notmatch

import com.alibaba.dubbo.registry.NotifyListener; //导入依赖的package包/类
/**
 * 服务名称不匹配,不能override invoker
 * 服务名称匹配,服务版本号不匹配
 */
@Test
public void testNotifyOverride_notmatch() throws Exception {
    URL newRegistryUrl = registryUrl.addParameter(Constants.EXPORT_KEY, serviceUrl);
    Invoker<RegistryProtocolTest> invoker = new MockInvoker<RegistryProtocolTest>(RegistryProtocolTest.class, newRegistryUrl);
    Exporter<?> exporter = protocol.export(invoker);
    RegistryProtocol rprotocol = RegistryProtocol.getRegistryProtocol();
    NotifyListener listener = getListener(rprotocol);
    List<URL> urls = new ArrayList<URL>();
    urls.add(URL.valueOf("override://0.0.0.0/com.alibaba.dubbo.registry.protocol.HackService?timeout=100"));
    listener.notify(urls);
    assertEquals(true, exporter.getInvoker().isAvailable());
    assertEquals(null, exporter.getInvoker().getUrl().getParameter("timeout"));
    exporter.unexport();
    destroyRegistryProtocol();
}
 
开发者ID:l1325169021,项目名称:github-test,代码行数:20,代码来源:RegistryProtocolTest.java

示例6: notify

import com.alibaba.dubbo.registry.NotifyListener; //导入依赖的package包/类
protected void notify(List<URL> urls) {
    if(urls == null || urls.isEmpty()) return;
    
    for (Map.Entry<URL, Set<NotifyListener>> entry : getSubscribed().entrySet()) {
        URL url = entry.getKey();
        
        if(! UrlUtils.isMatch(url, urls.get(0))) {
            continue;
        }
        
        Set<NotifyListener> listeners = entry.getValue();
        if (listeners != null) {
            for (NotifyListener listener : listeners) {
                try {
                    notify(url, listener, filterEmpty(url, urls));
                } catch (Throwable t) {
                    logger.error("Failed to notify registry event, urls: " +  urls + ", cause: " + t.getMessage(), t);
                }
            }
        }
    }
}
 
开发者ID:zhuxiaolei,项目名称:dubbo2,代码行数:23,代码来源:AbstractRegistry.java

示例7: registered

import com.alibaba.dubbo.registry.NotifyListener; //导入依赖的package包/类
protected void registered(URL url) {
    for (Map.Entry<URL, Set<NotifyListener>> entry : getSubscribed().entrySet()) {
        URL key = entry.getKey();
        if (UrlUtils.isMatch(key, url)) {
            Set<URL> urls = received.get(key);
            if (urls == null) {
                received.putIfAbsent(key, new ConcurrentHashSet<URL>());
                urls = received.get(key);
            }
            urls.add(url);
            List<URL> list = toList(urls);
            for (NotifyListener listener : entry.getValue()) {
                notify(key, listener, list);
                synchronized (listener) {
                    listener.notify();
                }
            }
        }
    }
}
 
开发者ID:dachengxi,项目名称:EatDubbo,代码行数:21,代码来源:MulticastRegistry.java

示例8: unsubscribe

import com.alibaba.dubbo.registry.NotifyListener; //导入依赖的package包/类
public void unsubscribe(URL url, NotifyListener listener) {
    if (! Constants.ANY_VALUE.equals(url.getServiceInterface())
            && url.getParameter(Constants.REGISTER_KEY, true)) {
        unregister(url);
    }
    String client = RpcContext.getContext().getRemoteAddressString();
    Map<URL, Set<NotifyListener>> clientListeners = remoteSubscribed.get(client);
    if (clientListeners != null && clientListeners.size() > 0) {
        Set<NotifyListener> listeners = clientListeners.get(url);
        if (listeners != null && listeners.size() > 0) {
            listeners.remove(listener);
        }
    }
}
 
开发者ID:dachengxi,项目名称:EatDubbo,代码行数:15,代码来源:SimpleRegistryService.java

示例9: doSubscribe

import com.alibaba.dubbo.registry.NotifyListener; //导入依赖的package包/类
protected void doSubscribe(URL url, NotifyListener listener) {
    if (Constants.ANY_VALUE.equals(url.getServiceInterface())) {
        admin = true;
    }
    broadcast(Constants.SUBSCRIBE + " " + url.toFullString());
    synchronized (listener) {
        try {
            listener.wait(url.getParameter(Constants.TIMEOUT_KEY, Constants.DEFAULT_TIMEOUT));
        } catch (InterruptedException e) {
        }
    }
}
 
开发者ID:yunhaibin,项目名称:dubbox-hystrix,代码行数:13,代码来源:MulticastRegistry.java

示例10: unregistered

import com.alibaba.dubbo.registry.NotifyListener; //导入依赖的package包/类
protected void unregistered(URL url) {
    for (Map.Entry<URL, Set<NotifyListener>> entry : getSubscribed().entrySet()) {
        URL key = entry.getKey();
        if (UrlUtils.isMatch(key, url)) {
            List<URL> list = lookup(key);
            for (NotifyListener listener : entry.getValue()) {
            	listener.notify(list);
            }
        }
    }
}
 
开发者ID:dachengxi,项目名称:EatDubbo,代码行数:12,代码来源:SimpleRegistryService.java

示例11: unregistered

import com.alibaba.dubbo.registry.NotifyListener; //导入依赖的package包/类
protected void unregistered(URL url) {
    for (Map.Entry<URL, Set<NotifyListener>> entry : getSubscribed().entrySet()) {
        URL key = entry.getKey();
        if (UrlUtils.isMatch(key, url)) {
            Set<URL> urls = received.get(key);
            if (urls != null) {
                urls.remove(url);
            }
            List<URL> list = toList(urls);
            for (NotifyListener listener : entry.getValue()) {
                notify(key, listener, list);
            }
        }
    }
}
 
开发者ID:yunhaibin,项目名称:dubbox-hystrix,代码行数:16,代码来源:MulticastRegistry.java

示例12: doNotify

import com.alibaba.dubbo.registry.NotifyListener; //导入依赖的package包/类
private void doNotify(String service, List<URL> urls) {
    notified.put(service, urls);
    List<NotifyListener> listeners = notifyListeners.get(service);
    if (listeners != null) {
        for (NotifyListener listener : listeners) {
            try {
                notify(service, urls, listener);
            } catch (Throwable t) {
                logger.error("Failed to notify registry event, service: " + service + ", urls: " +  urls + ", cause: " + t.getMessage(), t);
            }
        }
    }
}
 
开发者ID:dachengxi,项目名称:EatDubbo,代码行数:14,代码来源:AbstractRegistryService.java

示例13: addListener

import com.alibaba.dubbo.registry.NotifyListener; //导入依赖的package包/类
private void addListener(final String service, final NotifyListener listener){
    if (listener == null) {
        return;
    }
    List<NotifyListener> listeners = notifyListeners.get(service);
    if (listeners == null) {
        notifyListeners.putIfAbsent(service, new CopyOnWriteArrayList<NotifyListener>());
        listeners = notifyListeners.get(service);
    }
    if (listeners != null && !listeners.contains(listener)){
        listeners.add(listener);
    }
}
 
开发者ID:dachengxi,项目名称:EatDubbo,代码行数:14,代码来源:AbstractRegistryService.java

示例14: removeListener

import com.alibaba.dubbo.registry.NotifyListener; //导入依赖的package包/类
private void removeListener(final String service, final NotifyListener listener){
    if (listener == null) {
        return;
    }
    List<NotifyListener> listeners = notifyListeners.get(service);
    if (listeners != null) {
        listeners.remove(listener);
    }
}
 
开发者ID:dachengxi,项目名称:EatDubbo,代码行数:10,代码来源:AbstractRegistryService.java

示例15: doUnsubscribe

import com.alibaba.dubbo.registry.NotifyListener; //导入依赖的package包/类
protected void doUnsubscribe(URL url, NotifyListener listener) {
    ConcurrentMap<NotifyListener, ChildListener> listeners = zkListeners.get(url);
    if (listeners != null) {
        ChildListener zkListener = listeners.get(listener);
        if (zkListener != null) {
            zkClient.removeChildListener(toUrlPath(url), zkListener);
        }
    }
}
 
开发者ID:flychao88,项目名称:dubbocloud,代码行数:10,代码来源:ZookeeperRegistry.java


注:本文中的com.alibaba.dubbo.registry.NotifyListener类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。