Search in sources :

Example 21 with HeapDataOutputStream

use of org.apache.geode.internal.HeapDataOutputStream in project geode by apache.

the class DiskInitFile method pmidToBytes.

private byte[] pmidToBytes(PersistentMemberID id) {
    try {
        HeapDataOutputStream hdos = new HeapDataOutputStream(Version.CURRENT);
        InternalDataSerializer.invokeToData(id, hdos);
        return hdos.toByteArray();
    } catch (IOException ex) {
        throw new DiskAccessException(LocalizedStrings.DiskInitFile_FAILED_INIT_FILE_WRITE_BECAUSE_0.toLocalizedString(ex), this.parent);
    }
}
Also used : HeapDataOutputStream(org.apache.geode.internal.HeapDataOutputStream) DiskAccessException(org.apache.geode.cache.DiskAccessException) IOException(java.io.IOException)

Example 22 with HeapDataOutputStream

use of org.apache.geode.internal.HeapDataOutputStream in project geode by apache.

the class DiskInitFile method writeRegionConfig.

private void writeRegionConfig(DiskRegionView drv) {
    try {
        int len = estimateByteSize(drv.getPartitionName());
        int comprLen = estimateByteSize(drv.getCompressorClassName());
        HeapDataOutputStream bb = new HeapDataOutputStream(1 + DR_ID_MAX_BYTES + 1 + 1 + 4 + 4 + 4 + 1 + 1 + 4 + len + 4 + 1 + 1 + 1, Version.CURRENT);
        bb.write(IFREC_REGION_CONFIG_ID_90);
        writeDiskRegionID(bb, drv.getId());
        bb.write(drv.getLruAlgorithm());
        bb.write(drv.getLruAction());
        bb.writeInt(drv.getLruLimit());
        bb.writeInt(drv.getConcurrencyLevel());
        bb.writeInt(drv.getInitialCapacity());
        bb.writeFloat(drv.getLoadFactor());
        bb.write((byte) (drv.getStatisticsEnabled() ? 1 : 0));
        bb.write((byte) (drv.isBucket() ? 1 : 0));
        final EnumSet<DiskRegionFlag> flags = drv.getFlags();
        bb.writeUTF(drv.getPartitionName());
        bb.writeInt(drv.getStartingBucketId());
        bb.writeUTF(drv.getCompressorClassName() == null ? "" : drv.getCompressorClassName());
        bb.writeBoolean(flags.contains(DiskRegionFlag.IS_WITH_VERSIONING));
        // TODO the offheap flag needs to be in a new version
        bb.writeBoolean(drv.getOffHeap());
        bb.write(END_OF_RECORD_ID);
        // don't do stats for these small records
        writeIFRecord(bb, false);
    } catch (IOException ex) {
        DiskAccessException dae = new DiskAccessException(LocalizedStrings.DiskInitFile_FAILED_INIT_FILE_WRITE_BECAUSE_0.toLocalizedString(ex), this.parent);
        if (!this.compactInProgress) {
            this.parent.handleDiskAccessException(dae);
        }
        throw dae;
    }
}
Also used : HeapDataOutputStream(org.apache.geode.internal.HeapDataOutputStream) DiskAccessException(org.apache.geode.cache.DiskAccessException) IOException(java.io.IOException)

Example 23 with HeapDataOutputStream

use of org.apache.geode.internal.HeapDataOutputStream in project geode by apache.

the class EventID method getMembershipId.

/**
   * Convert a ClientProxyMembershipID distribted member ID array into one usable by EventIDs
   * 
   * @param client the client's ID
   * @return a byte array that may be used in EventID formation
   */
public static byte[] getMembershipId(ClientProxyMembershipID client) {
    try {
        HeapDataOutputStream hdos = new HeapDataOutputStream(256, Version.CURRENT);
        ((InternalDistributedMember) client.getDistributedMember()).writeEssentialData(hdos);
        return hdos.toByteArray();
    } catch (IOException ioe) {
        throw new InternalGemFireException(LocalizedStrings.ClientProxyMembershipID_UNABLE_TO_SERIALIZE_IDENTITY.toLocalizedString(), ioe);
    }
}
Also used : InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) InternalGemFireException(org.apache.geode.InternalGemFireException) HeapDataOutputStream(org.apache.geode.internal.HeapDataOutputStream) IOException(java.io.IOException)

Example 24 with HeapDataOutputStream

use of org.apache.geode.internal.HeapDataOutputStream in project geode by apache.

the class MultiVMRegionTestCase method getCCRegionVersionVector.

/**
   * Since version vectors aren't java.io.Serializable we use DataSerializer to return a serialized
   * form of the vector
   */
public static byte[] getCCRegionVersionVector() throws Exception {
    Object id = getMemberId();
    int vm = VM.getCurrentVMNum();
    org.apache.geode.test.dunit.LogWriterUtils.getLogWriter().info("vm" + vm + " with id " + id + " copying " + CCRegion.getVersionVector().fullToString());
    RegionVersionVector vector = CCRegion.getVersionVector().getCloneForTransmission();
    org.apache.geode.test.dunit.LogWriterUtils.getLogWriter().info("clone is " + vector);
    HeapDataOutputStream dos = new HeapDataOutputStream(3000, Version.CURRENT);
    DataSerializer.writeObject(vector, dos);
    byte[] bytes = dos.toByteArray();
    org.apache.geode.test.dunit.LogWriterUtils.getLogWriter().info("serialized size is " + bytes.length);
    return bytes;
}
Also used : HeapDataOutputStream(org.apache.geode.internal.HeapDataOutputStream) StoredObject(org.apache.geode.internal.offheap.StoredObject) RegionVersionVector(org.apache.geode.internal.cache.versions.RegionVersionVector)

Example 25 with HeapDataOutputStream

use of org.apache.geode.internal.HeapDataOutputStream in project geode by apache.

the class DiskOfflineCompactionJUnitTest method getRVVSize.

static int getRVVSize(int drMapSize, int[] numOfMemberPerDR, boolean gcRVV) {
    // if there's one member in rvv, total size is 9 bytes:
    // 0: OPLOG_RVV. 1: drMap.size()==1, 2: disRegionId, 3: getRVVTrusted
    // 4: memberToVersion.size()==1, 5: memberid, 6-7: versionHolder 8: END_OF_RECORD_ID
    // but not every diskRegion has a member in RVV
    HeapDataOutputStream out = new HeapDataOutputStream(Version.CURRENT);
    RegionVersionHolder dummyHolder = new RegionVersionHolder(1);
    try {
        dummyHolder.toData(out);
    } catch (IOException e) {
    }
    int holderSize = out.size();
    out.close();
    int size = 1;
    size++;
    /* drMap.size */
    for (int i = 0; i < drMapSize; i++) {
        size++;
        /* disRegionId */
        if (gcRVV) {
            size++;
            /* numOfMember, i.e. memberToVersion.size */
            if (numOfMemberPerDR != null && numOfMemberPerDR[i] > 0) {
                for (int j = 0; j < numOfMemberPerDR[i]; j++) {
                    size++;
                    /* memberid */
                    size++;
                /* gcversion */
                }
            }
        } else {
            size++;
            /* getRVVTrusted */
            size++;
            /* numOfMember, i.e. memberToVersion.size */
            if (numOfMemberPerDR != null && numOfMemberPerDR[i] > 0) {
                for (int j = 0; j < numOfMemberPerDR[i]; j++) {
                    size++;
                    /* memberid */
                    size += holderSize;
                }
            }
        }
    }
    size++;
    /* END_OF_RECORD_ID */
    return size;
}
Also used : HeapDataOutputStream(org.apache.geode.internal.HeapDataOutputStream) RegionVersionHolder(org.apache.geode.internal.cache.versions.RegionVersionHolder) IOException(java.io.IOException)

Aggregations

HeapDataOutputStream (org.apache.geode.internal.HeapDataOutputStream)134 Test (org.junit.Test)55 IOException (java.io.IOException)40 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)36 SerializationTest (org.apache.geode.test.junit.categories.SerializationTest)33 DataInputStream (java.io.DataInputStream)29 ByteArrayInputStream (java.io.ByteArrayInputStream)23 UnitTest (org.apache.geode.test.junit.categories.UnitTest)15 DiskAccessException (org.apache.geode.cache.DiskAccessException)12 InternalDistributedMember (org.apache.geode.distributed.internal.membership.InternalDistributedMember)11 PdxSerializerObject (org.apache.geode.internal.PdxSerializerObject)10 JsonGenerator (com.fasterxml.jackson.core.JsonGenerator)8 Version (org.apache.geode.internal.Version)8 DataInput (java.io.DataInput)7 SerializableCallable (org.apache.geode.test.dunit.SerializableCallable)7 OutputStream (java.io.OutputStream)6 Properties (java.util.Properties)6 ByteBuffer (java.nio.ByteBuffer)5 HashMap (java.util.HashMap)5 InternalGemFireException (org.apache.geode.InternalGemFireException)5