Search in sources :

Example 81 with HeapDataOutputStream

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

the class DiskInitFile method writeIFRecord.

private void writeIFRecord(byte b, long regionId, String fileName) {
    assert lock.isHeldByCurrentThread();
    try {
        int hdosSize = 1 + DR_ID_MAX_BYTES + estimateByteSize(fileName) + 1;
        if (hdosSize < 32) {
            hdosSize = 32;
        }
        HeapDataOutputStream hdos = new HeapDataOutputStream(hdosSize, Version.CURRENT);
        hdos.write(b);
        writeDiskRegionID(hdos, regionId);
        hdos.writeUTF(fileName);
        hdos.write(END_OF_RECORD_ID);
        writeIFRecord(hdos, true);
    } 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 82 with HeapDataOutputStream

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

the class DiskInitFile method writeCanonicalId.

private void writeCanonicalId(int id, Object object) {
    try {
        HeapDataOutputStream hdos = new HeapDataOutputStream(32, Version.CURRENT);
        hdos.write(IFREC_ADD_CANONICAL_MEMBER_ID);
        hdos.writeInt(id);
        DataSerializer.writeObject(object, hdos);
        hdos.write(END_OF_RECORD_ID);
        writeIFRecord(hdos, true);
    } 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 83 with HeapDataOutputStream

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

the class DiskInitFile method writePRDestroy.

private void writePRDestroy(String name) {
    try {
        int nameLength = estimateByteSize(name);
        HeapDataOutputStream hdos = new HeapDataOutputStream(1 + nameLength + 4 + 1, Version.CURRENT);
        hdos.write(IFREC_PR_DESTROY);
        hdos.writeUTF(name);
        hdos.write(END_OF_RECORD_ID);
        writeIFRecord(hdos, 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 84 with HeapDataOutputStream

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

the class DiskInitFile method writePRCreate.

private void writePRCreate(String name, PRPersistentConfig config) {
    try {
        int nameLength = estimateByteSize(name);
        String colocatedWith = config.getColocatedWith();
        colocatedWith = colocatedWith == null ? "" : colocatedWith;
        int colocatedLength = estimateByteSize(colocatedWith);
        HeapDataOutputStream hdos = new HeapDataOutputStream(1 + nameLength + 4 + colocatedLength + 1, Version.CURRENT);
        hdos.write(IFREC_PR_CREATE);
        hdos.writeUTF(name);
        hdos.writeInt(config.getTotalNumBuckets());
        hdos.writeUTF(colocatedWith);
        hdos.write(END_OF_RECORD_ID);
        writeIFRecord(hdos, 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 85 with HeapDataOutputStream

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

the class DiskInitFile method writeIFRecord.

private void writeIFRecord(byte b, long regionId, String fileName, Object compactorInfo) {
    assert lock.isHeldByCurrentThread();
    try {
        int hdosSize = 1 + DR_ID_MAX_BYTES + estimateByteSize(fileName) + 1;
        if (hdosSize < 32) {
            hdosSize = 32;
        }
        HeapDataOutputStream hdos = new HeapDataOutputStream(hdosSize, Version.CURRENT);
        hdos.write(b);
        writeDiskRegionID(hdos, regionId);
        hdos.writeUTF(fileName);
        // TODO - plum the correct compactor info to this point, to optimize
        // serialization
        DataSerializer.writeObject(compactorInfo, hdos);
        hdos.write(END_OF_RECORD_ID);
        writeIFRecord(hdos, true);
    } 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)

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