}
if (files == null) {
return;
}
while (files.hasNext()) {
VirtualFileReference next = files.next();
if (path.push(next.getName())) {
walkSafe(state, vfsKey, next, path);
state.dirs++;
path.pop();
}
}
} else {
long mark = debugCacheLine > 0 ? System.currentTimeMillis() : 0;
String pathString = null;
if (dirCacheSize > 0) { // if skipping questionable dir cache, then skip unused concurrency
pathString = Strings.cat(vfsKey, ":", path.getRealPath(), "[", token, "]");
/* this allows synchronizing on the path String */
synchronized (pathStrings) {
String interned = pathStrings.get(pathString);
if (interned == null) {
pathStrings.put(pathString, pathString);
interned = pathString;
}
pathString = interned;
}
VFSDirCacheLine cacheLine = null;
/* create "directory" cache line if missing */
synchronized (cache) {
cacheLine = cache.get(pathString);
if (cacheLine == null || !cacheLine.isValid()) {
if (log.isTraceEnabled()) {
log.trace("new cache-line for " + pathString + " was " + cacheLine);
}
cacheLine = new VFSDirCacheLine(ref);
cache.put(pathString, cacheLine);
} else {
if (log.isTraceEnabled()) {
log.trace("old cache-line for " + pathString + " = " + cacheLine);
}
cacheHits.incrementAndGet();
cacheHitsMeter.mark();
}
}
/* prevent same query from multiple clients simultaneously */
synchronized (cacheLine) {
/* use cache-line if not empty */
if (!cacheLine.lines.isEmpty()) {
for (FileReference cacheRef : cacheLine.lines) {
if (log.isTraceEnabled()) {
log.trace("cache.send " + ref + " from " + cacheRef + " key=" + pathString);
}
send(cacheRef.encode(hostUuid));
found.incrementAndGet();
fileFindMeter.mark();
}
return;
}
/* otherwise populate cache line */
Iterator<VirtualFileReference> files = ref.listFiles(filter);
if (log.isTraceEnabled()) {
log.trace("asDir=false filter=" + filter + " hostUuid=" + hostUuid + " files=" + files);
}
if (files == null) {
return;
}
while (files.hasNext()) {
VirtualFileReference next = files.next();
FileReference cacheRef = new FileReference(path.getRealPath(), next);
cacheLine.lines.add(cacheRef);
if (log.isTraceEnabled()) {
log.trace("local.send " + cacheRef + " cache to " + pathString + " in " + cacheLine.hashCode());
}
send(cacheRef.encode(hostUuid));
found.incrementAndGet();
fileFindMeter.mark();
}
}
} else {
Iterator<VirtualFileReference> files = ref.listFiles(filter);
if (log.isTraceEnabled()) {
log.trace("asDir=false filter=" + filter + " hostUuid=" + hostUuid + " files=" + files);
}
if (files == null) {
return;
}
while (files.hasNext()) {
VirtualFileReference next = files.next();
FileReference cacheRef = new FileReference(path.getRealPath(), next);
send(cacheRef.encode(hostUuid));
found.incrementAndGet();
fileFindMeter.mark();
}