use of org.apache.distributedlog.callback.LogSegmentNamesListener in project bookkeeper by apache.
the class ZKLogSegmentMetadataStore method getLogSegmentNames.
@Override
public CompletableFuture<Versioned<List<String>>> getLogSegmentNames(String logSegmentsPath, LogSegmentNamesListener listener) {
Watcher zkWatcher;
if (null == listener) {
zkWatcher = null;
} else {
closeLock.readLock().lock();
try {
if (closed) {
zkWatcher = null;
} else {
Map<LogSegmentNamesListener, VersionedLogSegmentNamesListener> listenerSet = listeners.get(logSegmentsPath);
if (null == listenerSet) {
Map<LogSegmentNamesListener, VersionedLogSegmentNamesListener> newListenerSet = new HashMap<LogSegmentNamesListener, VersionedLogSegmentNamesListener>();
Map<LogSegmentNamesListener, VersionedLogSegmentNamesListener> oldListenerSet = listeners.putIfAbsent(logSegmentsPath, newListenerSet);
if (null != oldListenerSet) {
listenerSet = oldListenerSet;
} else {
listenerSet = newListenerSet;
}
}
synchronized (listenerSet) {
listenerSet.put(listener, new VersionedLogSegmentNamesListener(listener));
if (!listeners.containsKey(logSegmentsPath)) {
// listener set has been removed, add it back
if (null != listeners.putIfAbsent(logSegmentsPath, listenerSet)) {
logger.debug("Listener set is already found for log segments path {}", logSegmentsPath);
}
}
}
zkWatcher = ZKLogSegmentMetadataStore.this;
}
} finally {
closeLock.readLock().unlock();
}
}
CompletableFuture<Versioned<List<String>>> getLogSegmentNamesResult = zkGetLogSegmentNames(logSegmentsPath, zkWatcher);
if (null != listener) {
getLogSegmentNamesResult.whenComplete(new ReadLogSegmentsTask(logSegmentsPath, this));
}
return zkGetLogSegmentNames(logSegmentsPath, zkWatcher);
}
Aggregations