+++ /dev/null
-// Copyright 2000-2005 the Contributors, as shown in the revision logs.
-// Licensed under the Apache Public Source License 2.0 ("the License").
-// You may not use this file except in compliance with the License.
-
-package org.ibex.jinetd;
-import org.ibex.util.*;
-import java.io.*;
-import java.util.*;
-
-public class Watched extends File {
-
- // Instance //////////////////////////////////////////////////////////////////////////////
-
- private Hashtable cache = new Hashtable();
- long lastModifiedAtLastScan = -1;
- public final String path;
- public final String part;
-
- public Watcher watcher() { return ((Watched)all.get(getParent())).watcher(); }
- public Watched slash(String part) { return get(this.path + File.separatorChar + part); }
- public void scan() throws IOException {
- if (!exists()) { return; }
- if (lastModifiedAtLastScan != lastModified()) { watcher().changed(this); lastModifiedAtLastScan = lastModified(); }
- if (!isDirectory()) { return; }
- Vec removals = new Vec();
- for(Iterator i = cache.values().iterator(); i.hasNext();) {
- Watched w = ((Watched)i.next());
- if (w.exists()) w.scan();
- else { watcher().changed(w); removals.addElement(w.path.substring(this.path.length() + 1)); }
- }
- for(int i=0; i<removals.size(); i++) cache.remove(removals.elementAt(i));
- String[] kids = list();
- if (kids == null) return;
- for(int i=0; i<kids.length; i++) {
- Watched kid = (Watched)cache.get(kids[i]);
- if (kid == null) {
- kid = slash(kids[i]);
- if (kid == null) continue;
- cache.put(kids[i], kid);
- watcher().changed(kid);
- kid.scan();
- } else {
- kid.scan();
- }
- }
- }
-
-
- // Pooling //////////////////////////////////////////////////////////////////////////////
-
- private static WeakHashMap all = new WeakHashMap();
- protected Watched(String path) {
- super(path);
- this.path = path;
- this.part = path.substring(path.lastIndexOf(File.separatorChar) + 1);
- all.put(path, this);
- }
- private static Watched get(String path) {
- Watched ret = (Watched)all.get(path);
- if (ret == null) ret = new Watched(path);
- return ret;
- }
-}