use of com.networknt.exception.FrameworkException in project light-4j by networknt.
the class ZooKeeperRegistry method doRegister.
@Override
protected void doRegister(URL url) {
try {
serverLock.lock();
removeNode(url, ZkNodeType.AVAILABLE_SERVER);
removeNode(url, ZkNodeType.UNAVAILABLE_SERVER);
createNode(url, ZkNodeType.UNAVAILABLE_SERVER);
} catch (Throwable e) {
throw new FrameworkException(new Status(REGISTER_ZOOKEEPER_ERROR, url, getUrl(), e.getMessage()), e);
} finally {
serverLock.unlock();
}
}
use of com.networknt.exception.FrameworkException in project light-4j by networknt.
the class ZooKeeperRegistry method discoverService.
@Override
protected List<URL> discoverService(URL url) {
try {
String parentPath = ZkUtils.toNodeTypePath(url, ZkNodeType.AVAILABLE_SERVER);
List<String> currentChilds = new ArrayList<String>();
if (client.exists(parentPath)) {
currentChilds = client.getChildren(parentPath);
}
return nodeChildsToUrls(parentPath, currentChilds);
} catch (Throwable e) {
throw new FrameworkException(new Status(DISCOVER_ZOOKEEPER_SERVICE_ERROR, url, getUrl(), e.getMessage()), e);
}
}
use of com.networknt.exception.FrameworkException in project light-4j by networknt.
the class ZooKeeperRegistry method subscribeService.
@Override
protected void subscribeService(final URL url, final ServiceListener serviceListener) {
try {
clientLock.lock();
ConcurrentHashMap<ServiceListener, IZkChildListener> childChangeListeners = serviceListeners.get(url);
if (childChangeListeners == null) {
serviceListeners.putIfAbsent(url, new ConcurrentHashMap<ServiceListener, IZkChildListener>());
childChangeListeners = serviceListeners.get(url);
}
IZkChildListener zkChildListener = childChangeListeners.get(serviceListener);
if (zkChildListener == null) {
childChangeListeners.putIfAbsent(serviceListener, new IZkChildListener() {
@Override
public void handleChildChange(String parentPath, List<String> currentChilds) {
serviceListener.notifyService(url, getUrl(), nodeChildsToUrls(parentPath, currentChilds));
if (logger.isInfoEnabled())
logger.info(String.format("[ZooKeeperRegistry] service list change: path=%s, currentChilds=%s", parentPath, currentChilds.toString()));
}
});
zkChildListener = childChangeListeners.get(serviceListener);
}
// prevent old node unregistered
removeNode(url, ZkNodeType.CLIENT);
createNode(url, ZkNodeType.CLIENT);
String serverTypePath = ZkUtils.toNodeTypePath(url, ZkNodeType.AVAILABLE_SERVER);
client.subscribeChildChanges(serverTypePath, zkChildListener);
if (logger.isInfoEnabled())
logger.info(String.format("[ZooKeeperRegistry] subscribe service: path=%s, info=%s", ZkUtils.toNodePath(url, ZkNodeType.AVAILABLE_SERVER), url.toFullStr()));
} catch (Throwable e) {
throw new FrameworkException(new Status(SUBSCRIBE_ZOOKEEPER_SERVICE_ERROR, url, getUrl(), e.getMessage()), e);
} finally {
clientLock.unlock();
}
}
use of com.networknt.exception.FrameworkException in project light-4j by networknt.
the class ZooKeeperRegistry method unsubscribeService.
@Override
protected void unsubscribeService(URL url, ServiceListener serviceListener) {
try {
clientLock.lock();
Map<ServiceListener, IZkChildListener> childChangeListeners = serviceListeners.get(url);
if (childChangeListeners != null) {
IZkChildListener zkChildListener = childChangeListeners.get(serviceListener);
if (zkChildListener != null) {
client.unsubscribeChildChanges(ZkUtils.toNodeTypePath(url, ZkNodeType.CLIENT), zkChildListener);
childChangeListeners.remove(serviceListener);
}
}
} catch (Throwable e) {
throw new FrameworkException(new Status(UNSUBSCRIBE_ZOOKEEPER_SERVICE_ERROR, url, getUrl(), e.getMessage()), e);
} finally {
clientLock.unlock();
}
}
Aggregations