01: /*
02: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright
03: * notice. All rights reserved.
04: */
05: package com.tc.objectserver.lockmanager.api;
06:
07: import com.tc.net.groups.NodeID;
08: import com.tc.object.lockmanager.api.LockContext;
09:
10: import java.util.Collections;
11: import java.util.HashMap;
12: import java.util.HashSet;
13: import java.util.Map;
14: import java.util.Set;
15:
16: public class NotifiedWaiters {
17:
18: private final Map notifiedSets = new HashMap();
19:
20: public String toString() {
21: synchronized (notifiedSets) {
22: return "NotifiedWaiters[" + notifiedSets + "]";
23: }
24: }
25:
26: public boolean isEmpty() {
27: return notifiedSets.isEmpty();
28: }
29:
30: public void addNotification(LockContext context) {
31: synchronized (notifiedSets) {
32: getOrCreateSetFor(context.getNodeID()).add(context);
33: }
34: }
35:
36: public Set getNotifiedFor(NodeID nodeID) {
37: synchronized (notifiedSets) {
38: Set rv = getSetFor(nodeID);
39: return (rv == null) ? Collections.EMPTY_SET : rv;
40: }
41: }
42:
43: private Set getSetFor(NodeID nodeID) {
44: return (Set) notifiedSets.get(nodeID);
45: }
46:
47: private Set getOrCreateSetFor(NodeID nodeID) {
48: Set rv = getSetFor(nodeID);
49: if (rv == null) {
50: rv = new HashSet();
51: notifiedSets.put(nodeID, rv);
52: }
53: return rv;
54: }
55:
56: }
|