|
@@ -40,11 +40,11 @@ import org.slf4j.LoggerFactory;
|
|
|
class WatchManager {
|
|
|
private static final Logger LOG = LoggerFactory.getLogger(WatchManager.class);
|
|
|
|
|
|
- private final HashMap<String, HashSet<Watcher>> watchTable =
|
|
|
- new HashMap<String, HashSet<Watcher>>();
|
|
|
+ private final Map<String, Set<Watcher>> watchTable =
|
|
|
+ new HashMap<String, Set<Watcher>>();
|
|
|
|
|
|
- private final HashMap<Watcher, HashSet<String>> watch2Paths =
|
|
|
- new HashMap<Watcher, HashSet<String>>();
|
|
|
+ private final Map<Watcher, Set<String>> watch2Paths =
|
|
|
+ new HashMap<Watcher, Set<String>>();
|
|
|
|
|
|
synchronized int size(){
|
|
|
int result = 0;
|
|
@@ -55,7 +55,7 @@ class WatchManager {
|
|
|
}
|
|
|
|
|
|
synchronized void addWatch(String path, Watcher watcher) {
|
|
|
- HashSet<Watcher> list = watchTable.get(path);
|
|
|
+ Set<Watcher> list = watchTable.get(path);
|
|
|
if (list == null) {
|
|
|
// don't waste memory if there are few watches on a node
|
|
|
// rehash when the 4th entry is added, doubling size thereafter
|
|
@@ -65,7 +65,7 @@ class WatchManager {
|
|
|
}
|
|
|
list.add(watcher);
|
|
|
|
|
|
- HashSet<String> paths = watch2Paths.get(watcher);
|
|
|
+ Set<String> paths = watch2Paths.get(watcher);
|
|
|
if (paths == null) {
|
|
|
// cnxns typically have many watches, so use default cap here
|
|
|
paths = new HashSet<String>();
|
|
@@ -75,12 +75,12 @@ class WatchManager {
|
|
|
}
|
|
|
|
|
|
synchronized void removeWatcher(Watcher watcher) {
|
|
|
- HashSet<String> paths = watch2Paths.remove(watcher);
|
|
|
+ Set<String> paths = watch2Paths.remove(watcher);
|
|
|
if (paths == null) {
|
|
|
return;
|
|
|
}
|
|
|
for (String p : paths) {
|
|
|
- HashSet<Watcher> list = watchTable.get(p);
|
|
|
+ Set<Watcher> list = watchTable.get(p);
|
|
|
if (list != null) {
|
|
|
list.remove(watcher);
|
|
|
if (list.size() == 0) {
|
|
@@ -97,7 +97,7 @@ class WatchManager {
|
|
|
Set<Watcher> triggerWatch(String path, EventType type, Set<Watcher> supress) {
|
|
|
WatchedEvent e = new WatchedEvent(type,
|
|
|
KeeperState.SyncConnected, path);
|
|
|
- HashSet<Watcher> watchers;
|
|
|
+ Set<Watcher> watchers;
|
|
|
synchronized (this) {
|
|
|
watchers = watchTable.remove(path);
|
|
|
if (watchers == null || watchers.isEmpty()) {
|
|
@@ -109,7 +109,7 @@ class WatchManager {
|
|
|
return null;
|
|
|
}
|
|
|
for (Watcher w : watchers) {
|
|
|
- HashSet<String> paths = watch2Paths.get(w);
|
|
|
+ Set<String> paths = watch2Paths.get(w);
|
|
|
if (paths != null) {
|
|
|
paths.remove(path);
|
|
|
}
|
|
@@ -135,7 +135,7 @@ class WatchManager {
|
|
|
.append(watchTable.size()).append(" paths\n");
|
|
|
|
|
|
int total = 0;
|
|
|
- for (HashSet<String> paths : watch2Paths.values()) {
|
|
|
+ for (Set<String> paths : watch2Paths.values()) {
|
|
|
total += paths.size();
|
|
|
}
|
|
|
sb.append("Total watches:").append(total);
|
|
@@ -151,7 +151,7 @@ class WatchManager {
|
|
|
*/
|
|
|
synchronized void dumpWatches(PrintWriter pwriter, boolean byPath) {
|
|
|
if (byPath) {
|
|
|
- for (Entry<String, HashSet<Watcher>> e : watchTable.entrySet()) {
|
|
|
+ for (Entry<String, Set<Watcher>> e : watchTable.entrySet()) {
|
|
|
pwriter.println(e.getKey());
|
|
|
for (Watcher w : e.getValue()) {
|
|
|
pwriter.print("\t0x");
|
|
@@ -160,7 +160,7 @@ class WatchManager {
|
|
|
}
|
|
|
}
|
|
|
} else {
|
|
|
- for (Entry<Watcher, HashSet<String>> e : watch2Paths.entrySet()) {
|
|
|
+ for (Entry<Watcher, Set<String>> e : watch2Paths.entrySet()) {
|
|
|
pwriter.print("0x");
|
|
|
pwriter.println(Long.toHexString(((ServerCnxn)e.getKey()).getSessionId()));
|
|
|
for (String path : e.getValue()) {
|
|
@@ -181,7 +181,7 @@ class WatchManager {
|
|
|
* @return true if the watcher exists, false otherwise
|
|
|
*/
|
|
|
synchronized boolean containsWatcher(String path, Watcher watcher) {
|
|
|
- HashSet<String> paths = watch2Paths.get(watcher);
|
|
|
+ Set<String> paths = watch2Paths.get(watcher);
|
|
|
if (paths == null || !paths.contains(path)) {
|
|
|
return false;
|
|
|
}
|
|
@@ -198,12 +198,12 @@ class WatchManager {
|
|
|
* @return true if the watcher successfully removed, false otherwise
|
|
|
*/
|
|
|
synchronized boolean removeWatcher(String path, Watcher watcher) {
|
|
|
- HashSet<String> paths = watch2Paths.get(watcher);
|
|
|
+ Set<String> paths = watch2Paths.get(watcher);
|
|
|
if (paths == null || !paths.remove(path)) {
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
- HashSet<Watcher> list = watchTable.get(path);
|
|
|
+ Set<Watcher> list = watchTable.get(path);
|
|
|
if (list == null || !list.remove(watcher)) {
|
|
|
return false;
|
|
|
}
|
|
@@ -223,9 +223,9 @@ class WatchManager {
|
|
|
*/
|
|
|
synchronized WatchesReport getWatches() {
|
|
|
Map<Long, Set<String>> id2paths = new HashMap<Long, Set<String>>();
|
|
|
- for (Entry<Watcher, HashSet<String>> e: watch2Paths.entrySet()) {
|
|
|
+ for (Entry<Watcher, Set<String>> e: watch2Paths.entrySet()) {
|
|
|
Long id = ((ServerCnxn) e.getKey()).getSessionId();
|
|
|
- HashSet<String> paths = new HashSet<String>(e.getValue());
|
|
|
+ Set<String> paths = new HashSet<String>(e.getValue());
|
|
|
id2paths.put(id, paths);
|
|
|
}
|
|
|
return new WatchesReport(id2paths);
|
|
@@ -239,7 +239,7 @@ class WatchManager {
|
|
|
*/
|
|
|
synchronized WatchesPathReport getWatchesByPath() {
|
|
|
Map<String, Set<Long>> path2ids = new HashMap<String, Set<Long>>();
|
|
|
- for (Entry<String, HashSet<Watcher>> e : watchTable.entrySet()) {
|
|
|
+ for (Entry<String, Set<Watcher>> e : watchTable.entrySet()) {
|
|
|
Set<Long> ids = new HashSet<Long>(e.getValue().size());
|
|
|
path2ids.put(e.getKey(), ids);
|
|
|
for (Watcher watcher : e.getValue()) {
|
|
@@ -257,7 +257,7 @@ class WatchManager {
|
|
|
*/
|
|
|
synchronized WatchesSummary getWatchesSummary() {
|
|
|
int totalWatches = 0;
|
|
|
- for (HashSet<String> paths : watch2Paths.values()) {
|
|
|
+ for (Set<String> paths : watch2Paths.values()) {
|
|
|
totalWatches += paths.size();
|
|
|
}
|
|
|
return new WatchesSummary (watch2Paths.size(), watchTable.size(),
|