use of com.networknt.registry.NotifyListener in project light-4j by networknt.
the class FailbackRegistry method retry.
private void retry() {
if (!failedRegistered.isEmpty()) {
Set<URL> failed = new HashSet<>(failedRegistered);
logger.info("[{}] Retry register {}", registryClassName, failed);
try {
for (URL url : failed) {
super.register(url);
failedRegistered.remove(url);
}
} catch (Exception e) {
logger.error(String.format("[%s] Failed to retry register, retry later, failedRegistered.size=%s, cause=%s", registryClassName, failedRegistered.size(), e.getMessage()), e);
}
}
if (!failedUnregistered.isEmpty()) {
Set<URL> failed = new HashSet<>(failedUnregistered);
logger.info("[{}] Retry unregister {}", registryClassName, failed);
try {
for (URL url : failed) {
super.unregister(url);
failedUnregistered.remove(url);
}
} catch (Exception e) {
logger.error(String.format("[%s] Failed to retry unregister, retry later, failedUnregistered.size=%s, cause=%s", registryClassName, failedUnregistered.size(), e.getMessage()), e);
}
}
if (!failedSubscribed.isEmpty()) {
Map<URL, Set<NotifyListener>> failed = new HashMap<>(failedSubscribed);
for (Map.Entry<URL, Set<NotifyListener>> entry : new HashMap<>(failed).entrySet()) {
if (entry.getValue() == null || entry.getValue().size() == 0) {
failed.remove(entry.getKey());
}
}
if (failed.size() > 0) {
logger.info("[{}] Retry subscribe {}", registryClassName, failed);
try {
for (Map.Entry<URL, Set<NotifyListener>> entry : failed.entrySet()) {
URL url = entry.getKey();
Set<NotifyListener> listeners = entry.getValue();
for (NotifyListener listener : listeners) {
super.subscribe(url, listener);
listeners.remove(listener);
}
}
} catch (Exception e) {
logger.error(String.format("[%s] Failed to retry subscribe, retry later, failedSubscribed.size=%s, cause=%s", registryClassName, failedSubscribed.size(), e.getMessage()), e);
}
}
}
if (!failedUnsubscribed.isEmpty()) {
Map<URL, Set<NotifyListener>> failed = new HashMap<>(failedUnsubscribed);
for (Map.Entry<URL, Set<NotifyListener>> entry : new HashMap<>(failed).entrySet()) {
if (entry.getValue() == null || entry.getValue().size() == 0) {
failed.remove(entry.getKey());
}
}
if (failed.size() > 0) {
logger.info("[{}] Retry unsubscribe {}", registryClassName, failed);
try {
for (Map.Entry<URL, Set<NotifyListener>> entry : failed.entrySet()) {
URL url = entry.getKey();
Set<NotifyListener> listeners = entry.getValue();
for (NotifyListener listener : listeners) {
super.unsubscribe(url, listener);
listeners.remove(listener);
}
}
} catch (Exception e) {
logger.error(String.format("[%s] Failed to retry unsubscribe, retry later, failedUnsubscribed.size=%s, cause=%s", registryClassName, failedUnsubscribed.size(), e.getMessage()), e);
}
}
}
}
use of com.networknt.registry.NotifyListener in project light-4j by networknt.
the class CommandServiceManager method notifyService.
@Override
public void notifyService(URL serviceUrl, URL registryUrl, List<URL> urls) {
if (registry == null) {
throw new FrameworkException(new Status(REGISTRY_IS_NULL));
}
URL urlCopy = serviceUrl.createCopy();
String groupName = urlCopy.getParameter(URLParamType.group.getName(), URLParamType.group.getValue());
groupServiceCache.put(groupName, urls);
List<URL> finalResult = new ArrayList<URL>();
if (logger.isInfoEnabled())
logger.info("command cache is null. service:" + serviceUrl.toSimpleString());
// if no command cache, return group
finalResult.addAll(discoverOneGroup(refUrl));
for (NotifyListener notifyListener : notifySet) {
notifyListener.notify(registry.getUrl(), finalResult);
}
}
Aggregations