Search in sources :

Example 1 with EventSeqnoHolder

use of org.apache.geode.internal.cache.EventTracker.EventSeqnoHolder in project geode by apache.

the class EventStateHelper method toData.

/**
   * Post 7.1, if changes are made to this method make sure that it is backwards compatible by
   * creating toDataPreXX methods. Also make sure that the callers to this method are backwards
   * compatible by creating toDataPreXX methods for them even if they are not changed. <br>
   * Callers for this method are: <br>
   * {@link CreateRegionReplyMessage#toData(DataOutput)} <br>
   * {@link RegionStateMessage#toData(DataOutput)} <br>
   */
@SuppressWarnings("synthetic-access")
public static void toData(DataOutput dop, Map eventState, boolean isHARegion) throws IOException {
    // For HARegionQueues, the event state map is uses different values
    // than a regular region :(
    InternalDistributedMember myId = InternalDistributedSystem.getAnyInstance().getDistributedMember();
    Map<MemberIdentifier, Map<ThreadIdentifier, Object>> groupedThreadIds = groupThreadIds(eventState);
    List<MemberIdentifier> orderedIds = new LinkedList();
    Map<MemberIdentifier, Integer> seenIds = new HashMap();
    // added in 7.0 for version tag processing in fromData
    myId.writeEssentialData(dop);
    for (MemberIdentifier memberId : groupedThreadIds.keySet()) {
        if (!seenIds.containsKey(memberId)) {
            orderedIds.add(memberId);
            seenIds.put(memberId, Integer.valueOf(seenIds.size()));
        }
    }
    dop.writeInt(seenIds.size());
    for (MemberIdentifier memberId : orderedIds) {
        DataSerializer.writeByteArray(memberId.bytes, dop);
    }
    dop.writeInt(groupedThreadIds.size());
    for (Map.Entry<MemberIdentifier, Map<ThreadIdentifier, Object>> memberIdEntry : groupedThreadIds.entrySet()) {
        MemberIdentifier memberId = memberIdEntry.getKey();
        dop.writeInt(seenIds.get(memberId).intValue());
        Map<ThreadIdentifier, Object> threadIdMap = memberIdEntry.getValue();
        dop.writeInt(threadIdMap.size());
        for (Object next : threadIdMap.entrySet()) {
            Map.Entry entry = (Map.Entry) next;
            ThreadIdentifier key = (ThreadIdentifier) entry.getKey();
            dop.writeLong(key.getThreadID());
            if (isHARegion) {
                DispatchedAndCurrentEvents value = (DispatchedAndCurrentEvents) entry.getValue();
                InternalDataSerializer.invokeToData(value, dop);
            } else {
                EventSeqnoHolder value = (EventSeqnoHolder) entry.getValue();
                InternalDataSerializer.invokeToData(value, dop);
            }
        }
    }
}
Also used : HashMap(java.util.HashMap) ThreadIdentifier(org.apache.geode.internal.cache.ha.ThreadIdentifier) EventSeqnoHolder(org.apache.geode.internal.cache.EventTracker.EventSeqnoHolder) DispatchedAndCurrentEvents(org.apache.geode.internal.cache.ha.HARegionQueue.DispatchedAndCurrentEvents) LinkedList(java.util.LinkedList) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) HashMap(java.util.HashMap) Map(java.util.Map)

Example 2 with EventSeqnoHolder

use of org.apache.geode.internal.cache.EventTracker.EventSeqnoHolder in project geode by apache.

the class EventStateHelper method fromData.

/**
   * Post 7.1, if changes are made to this method make sure that it is backwards compatible by
   * creating fromDataPreXX methods. Also make sure that the callers to this method are backwards
   * compatible by creating fromDataPreXX methods for them even if they are not changed. <br>
   * Callers for this method are: <br>
   * {@link CreateRegionReplyMessage#fromData(DataInput)} <br>
   * {@link RegionStateMessage#fromData(DataInput)} <br>
   */
public static Map fromData(DataInput dip, boolean isHARegion) throws IOException, ClassNotFoundException {
    InternalDistributedMember senderId = InternalDistributedMember.readEssentialData(dip);
    int numIds = dip.readInt();
    Map<Integer, byte[]> numberToMember = new HashMap();
    for (int i = 0; i < numIds; i++) {
        numberToMember.put(Integer.valueOf(i), DataSerializer.readByteArray(dip));
    }
    int size = dip.readInt();
    HashMap eventState = new HashMap(size);
    for (int i = 0; i < size; i++) {
        int idNumber = dip.readInt();
        int subMapSize = dip.readInt();
        for (int j = 0; j < subMapSize; j++) {
            long threadId = dip.readLong();
            ThreadIdentifier key = new ThreadIdentifier(numberToMember.get(idNumber), threadId);
            if (isHARegion) {
                DispatchedAndCurrentEvents value = new DispatchedAndCurrentEvents();
                InternalDataSerializer.invokeFromData(value, dip);
                eventState.put(key, value);
            } else {
                EventSeqnoHolder value = new EventSeqnoHolder();
                InternalDataSerializer.invokeFromData(value, dip);
                eventState.put(key, value);
                if (value.versionTag != null) {
                    value.versionTag.replaceNullIDs(senderId);
                }
            }
        }
    }
    return eventState;
}
Also used : InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) HashMap(java.util.HashMap) ThreadIdentifier(org.apache.geode.internal.cache.ha.ThreadIdentifier) EventSeqnoHolder(org.apache.geode.internal.cache.EventTracker.EventSeqnoHolder) DispatchedAndCurrentEvents(org.apache.geode.internal.cache.ha.HARegionQueue.DispatchedAndCurrentEvents)

Aggregations

HashMap (java.util.HashMap)2 InternalDistributedMember (org.apache.geode.distributed.internal.membership.InternalDistributedMember)2 EventSeqnoHolder (org.apache.geode.internal.cache.EventTracker.EventSeqnoHolder)2 DispatchedAndCurrentEvents (org.apache.geode.internal.cache.ha.HARegionQueue.DispatchedAndCurrentEvents)2 ThreadIdentifier (org.apache.geode.internal.cache.ha.ThreadIdentifier)2 LinkedList (java.util.LinkedList)1 Map (java.util.Map)1