1 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 ; 10 import java.util.HashMap ; 11 import java.util.HashSet ; 12 import java.util.Map ; 13 import java.util.Set ; 14 15 public class NotifiedWaiters { 16 17 private final Map notifiedSets = new HashMap (); 18 19 public String 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 getNotifiedFor(ChannelID channelID) { 36 synchronized (notifiedSets) { 37 Set rv = getSetFor(channelID); 38 return (rv == null) ? Collections.EMPTY_SET : rv; 39 } 40 } 41 42 private Set getSetFor(ChannelID channelID) { 43 return (Set ) notifiedSets.get(channelID); 44 } 45 46 private Set getOrCreateSetFor(ChannelID channelID) { 47 Set rv = getSetFor(channelID); 48 if (rv == null) { 49 rv = new HashSet (); 50 notifiedSets.put(channelID, rv); 51 } 52 return rv; 53 } 54 55 56 } 57 | Popular Tags |