KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tc > objectserver > lockmanager > api > NotifiedWaiters


1 /*
2  * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
3  */

4 package com.tc.objectserver.lockmanager.api;
5
6 import com.tc.net.protocol.tcm.ChannelID;
7 import com.tc.object.lockmanager.api.LockContext;
8
9 import java.util.Collections JavaDoc;
10 import java.util.HashMap JavaDoc;
11 import java.util.HashSet JavaDoc;
12 import java.util.Map JavaDoc;
13 import java.util.Set JavaDoc;
14
15 public class NotifiedWaiters {
16
17   private final Map JavaDoc notifiedSets = new HashMap JavaDoc();
18
19   public String JavaDoc toString() {
20     synchronized (notifiedSets) {
21       return "NotifiedWaiters[" + notifiedSets + "]";
22     }
23   }
24
25   public boolean isEmpty() {
26     return notifiedSets.isEmpty();
27   }
28
29   public void addNotification(LockContext context) {
30     synchronized (notifiedSets) {
31       getOrCreateSetFor(context.getChannelID()).add(context);
32     }
33   }
34
35   public Set JavaDoc getNotifiedFor(ChannelID channelID) {
36     synchronized (notifiedSets) {
37       Set JavaDoc rv = getSetFor(channelID);
38       return (rv == null) ? Collections.EMPTY_SET : rv;
39     }
40   }
41
42   private Set JavaDoc getSetFor(ChannelID channelID) {
43     return (Set JavaDoc) notifiedSets.get(channelID);
44   }
45
46   private Set JavaDoc getOrCreateSetFor(ChannelID channelID) {
47     Set JavaDoc rv = getSetFor(channelID);
48     if (rv == null) {
49       rv = new HashSet JavaDoc();
50       notifiedSets.put(channelID, rv);
51     }
52     return rv;
53   }
54
55
56 }
57
Popular Tags