Search in sources :

Example 1 with DiskVersionTag

use of org.apache.geode.internal.cache.versions.DiskVersionTag in project geode by apache.

the class VersionedObjectList method toData.

void toData(DataOutput out, int startIndex, int numEntries, boolean sendKeys, boolean sendObjects) throws IOException {
    int flags = 0;
    boolean hasObjects = false;
    boolean hasTags = false;
    if (sendKeys && this.hasKeys) {
        flags |= 0x01;
    }
    if (sendObjects && !this.objects.isEmpty()) {
        flags |= 0x02;
        hasObjects = true;
    }
    if (this.versionTags.size() > 0) {
        flags |= 0x04;
        hasTags = true;
        for (VersionTag tag : this.versionTags) {
            if (tag != null) {
                if (tag instanceof DiskVersionTag) {
                    flags |= 0x20;
                }
                break;
            }
        }
    }
    if (this.regionIsVersioned) {
        flags |= 0x08;
    }
    if (this.serializeValues) {
        flags |= 0x10;
    }
    if (logger.isTraceEnabled(LogMarker.VERSIONED_OBJECT_LIST)) {
        logger.trace(LogMarker.VERSIONED_OBJECT_LIST, "serializing {} with flags 0x{} startIndex={} numEntries={}", this, Integer.toHexString(flags), startIndex, numEntries);
    }
    out.writeByte(flags);
    if (sendKeys && hasKeys) {
        int numToWrite = numEntries;
        if (numToWrite + startIndex > this.keys.size()) {
            numToWrite = Math.max(0, this.keys.size() - startIndex);
        }
        InternalDataSerializer.writeUnsignedVL(numToWrite, out);
        int index = startIndex;
        for (int i = 0; i < numToWrite; i++, index++) {
            DataSerializer.writeObject(this.keys.get(index), out);
        }
    }
    if (sendObjects && hasObjects) {
        int numToWrite = numEntries;
        if (numToWrite + startIndex > this.objects.size()) {
            numToWrite = Math.max(0, this.objects.size() - startIndex);
        }
        InternalDataSerializer.writeUnsignedVL(numToWrite, out);
        int idx = 0;
        int index = startIndex;
        for (int i = 0; i < numToWrite; i++, index++) {
            writeObject(this.objects.get(index), idx++, out);
        }
    }
    if (hasTags) {
        int numToWrite = numEntries;
        if (numToWrite + startIndex > this.versionTags.size()) {
            numToWrite = Math.max(0, this.versionTags.size() - startIndex);
        }
        InternalDataSerializer.writeUnsignedVL(numToWrite, out);
        Map<VersionSource, Integer> ids = new HashMap<VersionSource, Integer>(numToWrite);
        int idCount = 0;
        int index = startIndex;
        for (int i = 0; i < numToWrite; i++, index++) {
            VersionTag tag = this.versionTags.get(index);
            if (tag == null) {
                out.writeByte(FLAG_NULL_TAG);
            } else {
                VersionSource id = tag.getMemberID();
                if (id == null) {
                    out.writeByte(FLAG_FULL_TAG);
                    InternalDataSerializer.invokeToData(tag, out);
                } else {
                    Integer idNumber = ids.get(id);
                    if (idNumber == null) {
                        out.writeByte(FLAG_TAG_WITH_NEW_ID);
                        idNumber = Integer.valueOf(idCount++);
                        ids.put(id, idNumber);
                        InternalDataSerializer.invokeToData(tag, out);
                    } else {
                        out.writeByte(FLAG_TAG_WITH_NUMBER_ID);
                        tag.toData(out, false);
                        tag.setMemberID(id);
                        InternalDataSerializer.writeUnsignedVL(idNumber, out);
                    }
                }
            }
        }
    }
}
Also used : HashMap(java.util.HashMap) VersionSource(org.apache.geode.internal.cache.versions.VersionSource) DiskVersionTag(org.apache.geode.internal.cache.versions.DiskVersionTag) VersionTag(org.apache.geode.internal.cache.versions.VersionTag) DiskVersionTag(org.apache.geode.internal.cache.versions.DiskVersionTag)

Aggregations

HashMap (java.util.HashMap)1 DiskVersionTag (org.apache.geode.internal.cache.versions.DiskVersionTag)1 VersionSource (org.apache.geode.internal.cache.versions.VersionSource)1 VersionTag (org.apache.geode.internal.cache.versions.VersionTag)1