use of org.apache.geode.internal.CopyOnWriteHashSet in project geode by apache.
the class LocatorHelper method addExchangedLocators.
/**
* This method adds the map of locatorsinfo sent by other locator to this locator's allLocatorInfo
*
* @param locators
* @param locatorListener
*/
public static boolean addExchangedLocators(Map<Integer, Set<DistributionLocatorId>> locators, LocatorMembershipListener locatorListener) {
ConcurrentHashMap<Integer, Set<DistributionLocatorId>> allLocators = (ConcurrentHashMap<Integer, Set<DistributionLocatorId>>) locatorListener.getAllLocatorsInfo();
if (!allLocators.equals(locators)) {
for (Map.Entry<Integer, Set<DistributionLocatorId>> entry : locators.entrySet()) {
Set<DistributionLocatorId> existingValue = allLocators.putIfAbsent(entry.getKey(), new CopyOnWriteHashSet<DistributionLocatorId>(entry.getValue()));
if (existingValue != null) {
Set<DistributionLocatorId> localLocators = allLocators.get(entry.getKey());
if (!localLocators.equals(entry.getValue())) {
entry.getValue().removeAll(localLocators);
for (DistributionLocatorId locator : entry.getValue()) {
localLocators.add(locator);
addServerLocator(entry.getKey(), locatorListener, locator);
locatorListener.locatorJoined(entry.getKey(), locator, null);
}
}
} else {
for (DistributionLocatorId locator : entry.getValue()) {
addServerLocator(entry.getKey(), locatorListener, locator);
locatorListener.locatorJoined(entry.getKey(), locator, null);
}
}
}
return true;
}
return false;
}
use of org.apache.geode.internal.CopyOnWriteHashSet in project geode by apache.
the class FilterProfile method registerClientInterestList.
/**
* Registers interest in a set of keys for a client
*
* @param keys The list of keys in which to register interest
* @param updatesAsInvalidates whether to send invalidations instead of updates
* @return the registered keys
*/
public Set registerClientInterestList(Object inputClientID, List keys, boolean updatesAsInvalidates) {
Long clientID = getClientIDForMaps(inputClientID);
Set keysRegistered = new HashSet(keys);
synchronized (interestListLock) {
Map<Object, Set> koi = updatesAsInvalidates ? getKeysOfInterestInv() : getKeysOfInterest();
CopyOnWriteHashSet interestList = (CopyOnWriteHashSet) koi.get(clientID);
if (interestList == null) {
interestList = new CopyOnWriteHashSet();
koi.put(clientID, interestList);
} else {
// Get the list of keys that will be registered new, not already registered.
keysRegistered.removeAll(interestList.getSnapshot());
}
interestList.addAll(keys);
if (this.region != null && this.isLocalProfile) {
sendProfileOperation(clientID, operationType.REGISTER_KEYS, keys, updatesAsInvalidates);
}
}
// synchronized
return keysRegistered;
}
use of org.apache.geode.internal.CopyOnWriteHashSet in project geode by apache.
the class FilterProfile method unregisterClientInterestList.
/**
* Unregisters interest in given keys for the given client
*
* @param inputClientID The fully-qualified name of the region in which to unregister interest
* @param keys The list of keys in which to unregister interest
* @return the unregistered keys
*/
public Set unregisterClientInterestList(Object inputClientID, List keys) {
Long clientID = getClientIDForMaps(inputClientID);
Set keysUnregistered = new HashSet(keys);
Set keysNotUnregistered = new HashSet(keys);
synchronized (interestListLock) {
CopyOnWriteHashSet interestList = (CopyOnWriteHashSet) getKeysOfInterest().get(clientID);
if (interestList != null) {
// Get the list of keys that are not registered but in unregister set.
keysNotUnregistered.removeAll(interestList.getSnapshot());
interestList.removeAll(keys);
if (interestList.isEmpty()) {
getKeysOfInterest().remove(clientID);
}
}
interestList = (CopyOnWriteHashSet) getKeysOfInterestInv().get(clientID);
if (interestList != null) {
keysNotUnregistered.removeAll(interestList.getSnapshot());
interestList.removeAll(keys);
if (interestList.isEmpty()) {
getKeysOfInterestInv().remove(clientID);
}
}
if (this.region != null && this.isLocalProfile) {
sendProfileOperation(clientID, operationType.UNREGISTER_KEYS, keys, false);
}
}
// synchronized
// Get the keys that are not unregistered.
keysUnregistered.removeAll(keysNotUnregistered);
return keysUnregistered;
}
use of org.apache.geode.internal.CopyOnWriteHashSet in project geode by apache.
the class FilterProfile method registerKeyInMap.
private void registerKeyInMap(Object interest, Set keysRegistered, Long clientID, Map<Object, Set> koi) {
Set interestList = koi.get(clientID);
if (interestList == null) {
interestList = new CopyOnWriteHashSet();
koi.put(clientID, interestList);
}
interestList.add(interest);
keysRegistered.add(interest);
}
Aggregations