Search in sources :

Example 1 with SerializedCacheValue

use of org.apache.geode.cache.SerializedCacheValue in project geode by apache.

the class FilterProfile method getInterestedClients.

/**
   * get the clients interested in the given event that are attached to this server.
   * 
   * @param event the entry event being applied to the cache
   * @param akc allKeyClients collection
   * @param koi keysOfInterest collection
   * @param pats patternsOfInterest collection
   * @param foi filtersOfInterest collection
   * @return a set of the clients interested in the event
   */
private Set getInterestedClients(EntryEvent event, Set akc, Map<Object, Set> koi, Map<Object, Map<Object, Pattern>> pats, Map<Object, Map> foi) {
    Set result = null;
    if (akc != null) {
        result = new HashSet(akc);
        if (logger.isDebugEnabled()) {
            logger.debug("these clients matched for all-keys: {}", akc);
        }
    }
    if (koi != null) {
        for (Iterator it = koi.entrySet().iterator(); it.hasNext(); ) {
            Map.Entry entry = (Map.Entry) it.next();
            Set keys = (Set) entry.getValue();
            if (keys.contains(event.getKey())) {
                Object clientID = entry.getKey();
                if (result == null)
                    result = new HashSet();
                result.add(clientID);
                if (logger.isDebugEnabled()) {
                    logger.debug("client {} matched for key list (size {})", clientID, koi.get(clientID).size());
                }
            }
        }
    }
    if (pats != null && (event.getKey() instanceof String)) {
        for (Iterator it = pats.entrySet().iterator(); it.hasNext(); ) {
            Map.Entry entry = (Map.Entry) it.next();
            String stringKey = (String) event.getKey();
            Map<Object, Pattern> interestList = (Map<Object, Pattern>) entry.getValue();
            for (Pattern keyPattern : interestList.values()) {
                if (keyPattern.matcher(stringKey).matches()) {
                    Object clientID = entry.getKey();
                    if (result == null)
                        result = new HashSet();
                    result.add(clientID);
                    if (logger.isDebugEnabled()) {
                        logger.debug("client {} matched for pattern ({})", clientID, pats.get(clientID));
                    }
                    break;
                }
            }
        }
    }
    if (foi != null && foi.size() > 0) {
        Object value;
        boolean serialized;
        {
            SerializedCacheValue<?> serValue = event.getSerializedNewValue();
            serialized = (serValue != null);
            if (!serialized) {
                value = event.getNewValue();
            } else {
                value = serValue.getSerializedValue();
            }
        }
        InterestEvent iev = new InterestEvent(event.getKey(), value, !serialized);
        Operation op = event.getOperation();
        for (Iterator it = foi.entrySet().iterator(); it.hasNext(); ) {
            Map.Entry entry = (Map.Entry) it.next();
            Map<String, InterestFilter> interestList = (Map<String, InterestFilter>) entry.getValue();
            for (InterestFilter filter : interestList.values()) {
                if ((op.isCreate() && filter.notifyOnCreate(iev)) || (op.isUpdate() && filter.notifyOnUpdate(iev)) || (op.isDestroy() && filter.notifyOnDestroy(iev)) || (op.isInvalidate() && filter.notifyOnInvalidate(iev))) {
                    Object clientID = entry.getKey();
                    if (result == null)
                        result = new HashSet();
                    result.add(clientID);
                    if (logger.isDebugEnabled()) {
                        logger.debug("client {} matched for filter ({})", clientID, getFiltersOfInterest().get(clientID));
                    }
                    break;
                }
            }
        }
    }
    return result;
}
Also used : Pattern(java.util.regex.Pattern) Set(java.util.Set) CopyOnWriteHashSet(org.apache.geode.internal.CopyOnWriteHashSet) TreeSet(java.util.TreeSet) HashSet(java.util.HashSet) Operation(org.apache.geode.cache.Operation) SerializedCacheValue(org.apache.geode.cache.SerializedCacheValue) Iterator(java.util.Iterator) CopyOnWriteHashMap(org.apache.geode.internal.util.concurrent.CopyOnWriteHashMap) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) CopyOnWriteHashSet(org.apache.geode.internal.CopyOnWriteHashSet) HashSet(java.util.HashSet)

Example 2 with SerializedCacheValue

use of org.apache.geode.cache.SerializedCacheValue in project geode by apache.

the class GatewayDeltaForwarderCacheListener method afterCreate.

@SuppressWarnings("unchecked")
public void afterCreate(EntryEvent<String, GatewayDelta> event) {
    // gateway delta region
    if (event.getCallbackArgument() == null) {
        if (this.cache.getLogger().fineEnabled()) {
            StringBuilder builder = new StringBuilder();
            builder.append("GatewayDeltaForwarderCacheListener: Received create event for ").append(event.getKey()).append("->").append(event.getNewValue()).append(" that originated in the local site. Sending it to the remote site.");
            this.cache.getLogger().fine(builder.toString());
        }
        // Distribute the create event to the gateway hub(s)
        String regionName = event.getRegion().getFullPath();
        String sessionId = event.getKey();
        SerializedCacheValue scv = event.getSerializedNewValue();
        if (scv == null) {
            getGatewayDeltaRegion().put(sessionId, new GatewayDeltaCreateEvent(regionName, sessionId, EntryEventImpl.serialize(event.getNewValue())));
        } else {
            System.out.println("GatewayDeltaForwarderCacheListener event.getSerializedNewValue().getSerializedValue(): " + event.getSerializedNewValue().getSerializedValue());
            getGatewayDeltaRegion().put(sessionId, new GatewayDeltaCreateEvent(regionName, sessionId, scv.getSerializedValue()));
        }
    } else {
        if (this.cache.getLogger().fineEnabled()) {
            StringBuilder builder = new StringBuilder();
            builder.append("GatewayDeltaForwarderCacheListener: Received create event for ").append(event.getKey()).append("->").append(event.getNewValue()).append(" that originated in the remote site.");
            this.cache.getLogger().fine(builder.toString());
        }
    }
}
Also used : SerializedCacheValue(org.apache.geode.cache.SerializedCacheValue)

Aggregations

SerializedCacheValue (org.apache.geode.cache.SerializedCacheValue)2 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Iterator (java.util.Iterator)1 Map (java.util.Map)1 Set (java.util.Set)1 TreeSet (java.util.TreeSet)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 Pattern (java.util.regex.Pattern)1 Operation (org.apache.geode.cache.Operation)1 CopyOnWriteHashSet (org.apache.geode.internal.CopyOnWriteHashSet)1 CopyOnWriteHashMap (org.apache.geode.internal.util.concurrent.CopyOnWriteHashMap)1