Search in sources :

Example 11 with StorageException

use of io.atomix.storage.StorageException in project atomix by atomix.

the class MappableJournalSegmentWriter method map.

/**
 * Maps the segment writer into memory, returning the mapped buffer.
 *
 * @return the buffer that was mapped into memory
 */
MappedByteBuffer map() {
    if (writer instanceof MappedJournalSegmentWriter) {
        return ((MappedJournalSegmentWriter<E>) writer).buffer();
    }
    try {
        JournalWriter<E> writer = this.writer;
        MappedByteBuffer buffer = channel.map(FileChannel.MapMode.READ_WRITE, 0, segment.descriptor().maxSegmentSize());
        this.writer = new MappedJournalSegmentWriter<>(buffer, segment, maxEntrySize, index, namespace);
        writer.close();
        return buffer;
    } catch (IOException e) {
        throw new StorageException(e);
    }
}
Also used : MappedByteBuffer(java.nio.MappedByteBuffer) IOException(java.io.IOException) StorageException(io.atomix.storage.StorageException)

Aggregations

StorageException (io.atomix.storage.StorageException)11 IOException (java.io.IOException)10 File (java.io.File)3 RandomAccessFile (java.io.RandomAccessFile)3 ByteBuffer (java.nio.ByteBuffer)3 FileChannel (java.nio.channels.FileChannel)3 CRC32 (java.util.zip.CRC32)3 Checksum (java.util.zip.Checksum)3 BufferUnderflowException (java.nio.BufferUnderflowException)2 KryoException (com.esotericsoftware.kryo.KryoException)1 BackupOperation (io.atomix.protocols.log.protocol.BackupOperation)1 LogEntry (io.atomix.protocols.log.protocol.LogEntry)1 Position (io.atomix.storage.journal.index.Position)1 BufferOverflowException (java.nio.BufferOverflowException)1 MappedByteBuffer (java.nio.MappedByteBuffer)1 TreeMap (java.util.TreeMap)1