Search in sources :

Example 1 with AtomixIOException

use of io.atomix.utils.AtomixIOException in project atomix by atomix.

the class FileSnapshot method complete.

@Override
public Snapshot complete() {
    checkNotNull(file.temporaryFile(), "no temporary snapshot file to read from");
    Buffer buffer = FileBuffer.allocate(file.temporaryFile(), SnapshotDescriptor.BYTES);
    try (SnapshotDescriptor descriptor = new SnapshotDescriptor(buffer)) {
        descriptor.lock();
    }
    try {
        persistTemporaryFile();
    } catch (IOException e) {
        throw new AtomixIOException(e);
    }
    file.clearTemporaryFile();
    return super.complete();
}
Also used : Buffer(io.atomix.storage.buffer.Buffer) FileBuffer(io.atomix.storage.buffer.FileBuffer) AtomixIOException(io.atomix.utils.AtomixIOException) IOException(java.io.IOException) AtomixIOException(io.atomix.utils.AtomixIOException)

Example 2 with AtomixIOException

use of io.atomix.utils.AtomixIOException in project atomix by atomix.

the class MappedBytes method allocate.

/**
 * Allocates a mapped buffer.
 * <p>
 * Memory will be mapped by opening and expanding the given {@link File} to the desired {@code count} and mapping the
 * file contents into memory via {@link FileChannel#map(FileChannel.MapMode, long, long)}.
 *
 * @param file The file to map into memory. If the file doesn't exist it will be automatically created.
 * @param mode The mode with which to map the file.
 * @param size The count of the buffer to allocate (in bytes).
 * @return The mapped buffer.
 * @throws NullPointerException     If {@code file} is {@code null}
 * @throws IllegalArgumentException If {@code count} is greater than {@link Integer#MAX_VALUE}
 * @see #allocate(File, int)
 */
public static MappedBytes allocate(File file, FileChannel.MapMode mode, int size) {
    try {
        RandomAccessFile randomAccessFile = new RandomAccessFile(file, parseMode(mode));
        MappedByteBuffer buffer = randomAccessFile.getChannel().map(mode, 0, size);
        return new MappedBytes(file, randomAccessFile, buffer, mode);
    } catch (IOException e) {
        throw new AtomixIOException(e);
    }
}
Also used : RandomAccessFile(java.io.RandomAccessFile) MappedByteBuffer(java.nio.MappedByteBuffer) AtomixIOException(io.atomix.utils.AtomixIOException) IOException(java.io.IOException) AtomixIOException(io.atomix.utils.AtomixIOException)

Aggregations

AtomixIOException (io.atomix.utils.AtomixIOException)2 IOException (java.io.IOException)2 Buffer (io.atomix.storage.buffer.Buffer)1 FileBuffer (io.atomix.storage.buffer.FileBuffer)1 RandomAccessFile (java.io.RandomAccessFile)1 MappedByteBuffer (java.nio.MappedByteBuffer)1