本文整理汇总了Java中com.alibaba.dubbo.registry.NotifyListener类的典型用法代码示例。如果您正苦于以下问题:Java NotifyListener类的具体用法?Java NotifyListener怎么用?Java NotifyListener使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
NotifyListener类属于com.alibaba.dubbo.registry包,在下文中一共展示了NotifyListener类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
示例16: subscribe
import com.alibaba.dubbo.registry.NotifyListener; //导入依赖的package包/类
public void subscribe(URL url, NotifyListener listener) {
this.subscribedUrl = url;
List<URL> urls = new ArrayList<URL>();
urls.add(url.setProtocol("mockprotocol")
.removeParameter(Constants.CATEGORY_KEY)
.addParameter(Constants.METHODS_KEY, "sayHello"));
listener.notify(urls);
}
开发者ID:yunhaibin,项目名称:dubbox-hystrix,代码行数:11,代码来源:MockRegistry.java
示例17: testDoRetry_nofify
import com.alibaba.dubbo.registry.NotifyListener; //导入依赖的package包/类
@Test
public void testDoRetry_nofify() throws Exception {
//初始值0
final AtomicInteger count = new AtomicInteger(0);
NotifyListener listner = new NotifyListener() {
public void notify(List<URL> urls) {
count.incrementAndGet();
//第一次抛出异常,看后面是否会再次调用到incrementAndGet
if(count.get() == 1l ){
throw new RuntimeException("test exception please ignore");
}
}
};
registry = new MockRegistry(registryUrl, new CountDownLatch(0));
registry.subscribe(serviceUrl.setProtocol(Constants.CONSUMER_PROTOCOL).addParameters(CollectionUtils.toStringMap("check", "false")), listner);
assertEquals(1, count.get()); //确保subscribe调用完成后刚调用过一次count.incrementAndGet
//等定时器.
for (int i = 0; i < trytimes; i++) {
System.out.println("failback notify retry ,times:" + i);
if (count.get() == 2)
break;
Thread.sleep(sleeptime);
}
assertEquals(2, count.get());
}
开发者ID:zhuxiaolei,项目名称:dubbo2,代码行数:29,代码来源:FailbackRegistryTest.java
示例18: unsubscribe
import com.alibaba.dubbo.registry.NotifyListener; //导入依赖的package包/类
@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);
}
}
开发者ID:yunhaibin,项目名称:dubbox-hystrix,代码行数:14,代码来源:SimpleRegistryService.java
示例19: subscribe
import com.alibaba.dubbo.registry.NotifyListener; //导入依赖的package包/类
@Override
public void subscribe(URL url, NotifyListener listener) {
super.subscribe(url, listener);
removeFailedSubscribed(url, listener);
try {
// 向服务器端发送订阅请求
doSubscribe(url, listener);
} catch (Exception e) {
Throwable t = e;
List<URL> urls = getCacheUrls(url);
if (urls != null && urls.size() > 0) {
notify(url, listener, urls);
logger.error("Failed to subscribe " + url + ", Using cached list: " + urls + " from cache file: " + getUrl().getParameter(Constants.FILE_KEY, System.getProperty("user.home") + "/dubbo-registry-" + url.getHost() + ".cache") + ", cause: " + t.getMessage(), t);
} else {
// 如果开启了启动时检测,则直接抛出异常
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 subscribe " + url + ", cause: " + t.getMessage(), t);
} else {
logger.error("Failed to subscribe " + url + ", waiting for retry, cause: " + t.getMessage(), t);
}
}
// 将失败的订阅请求记录到失败列表,定时重试
addFailedSubscribed(url, listener);
}
}
开发者ID:dachengxi,项目名称:EatDubbo,代码行数:34,代码来源:FailbackRegistry.java
示例20: doUnsubscribe
import com.alibaba.dubbo.registry.NotifyListener; //导入依赖的package包/类
protected void doUnsubscribe(URL url, NotifyListener listener) {
if (! Constants.ANY_VALUE.equals(url.getServiceInterface())
&& url.getParameter(Constants.REGISTER_KEY, true)) {
unregister(url);
}
broadcast(Constants.UNSUBSCRIBE + " " + url.toFullString());
}
开发者ID:dachengxi,项目名称:EatDubbo,代码行数:8,代码来源:MulticastRegistry.java
注:本文中的com.alibaba.dubbo.registry.NotifyListener类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论