本文整理汇总了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);
}
示例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);
}
}
示例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());
}
示例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();
}
示例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();
}
示例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);
}
}
}
}
}
示例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();
}
}
}
}
}
示例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);
}
}
}
示例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) {
}
}
}
示例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);
}
}
}
}
示例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);
}
}
}
}
示例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);
}
}
}
}
示例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);
}
}
示例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);
}
}
示例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);
}
}
}