Search in sources :

Example 1 with CopyOnWriteHashSet

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;
}
Also used : HashSet(java.util.HashSet) CopyOnWriteHashSet(org.apache.geode.internal.CopyOnWriteHashSet) Set(java.util.Set) DistributionLocatorId(org.apache.geode.internal.admin.remote.DistributionLocatorId) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap)

Example 2 with CopyOnWriteHashSet

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;
}
Also used : Set(java.util.Set) CopyOnWriteHashSet(org.apache.geode.internal.CopyOnWriteHashSet) TreeSet(java.util.TreeSet) HashSet(java.util.HashSet) CopyOnWriteHashSet(org.apache.geode.internal.CopyOnWriteHashSet) CopyOnWriteHashSet(org.apache.geode.internal.CopyOnWriteHashSet) HashSet(java.util.HashSet)

Example 3 with CopyOnWriteHashSet

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;
}
Also used : Set(java.util.Set) CopyOnWriteHashSet(org.apache.geode.internal.CopyOnWriteHashSet) TreeSet(java.util.TreeSet) HashSet(java.util.HashSet) CopyOnWriteHashSet(org.apache.geode.internal.CopyOnWriteHashSet) CopyOnWriteHashSet(org.apache.geode.internal.CopyOnWriteHashSet) HashSet(java.util.HashSet)

Example 4 with CopyOnWriteHashSet

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);
}
Also used : Set(java.util.Set) CopyOnWriteHashSet(org.apache.geode.internal.CopyOnWriteHashSet) TreeSet(java.util.TreeSet) HashSet(java.util.HashSet) CopyOnWriteHashSet(org.apache.geode.internal.CopyOnWriteHashSet)

Aggregations

HashSet (java.util.HashSet)4 Set (java.util.Set)4 CopyOnWriteHashSet (org.apache.geode.internal.CopyOnWriteHashSet)4 TreeSet (java.util.TreeSet)3 Map (java.util.Map)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 ConcurrentMap (java.util.concurrent.ConcurrentMap)1 DistributionLocatorId (org.apache.geode.internal.admin.remote.DistributionLocatorId)1