Package com.illumon.iris.db.v2.locations
Class LazyFileAccessor
java.lang.Object
com.illumon.iris.db.v2.locations.LazyFileAccessor
- All Implemented Interfaces:
com.fishlib.base.log.LogOutputAppendable
,FileAccessor
,NamedImplementation
public class LazyFileAccessor extends Object implements FileAccessor
Lazily-initialized FileAccessor implementation.
Defers initialization costs, e.g. file handle allocation or size-buffer reading whenever possible.
-
Field Summary
-
Constructor Summary
Constructors Constructor Description LazyFileAccessor(Supplier<FileAccessor> factory)
-
Method Summary
Modifier and Type Method Description com.fishlib.base.log.LogOutput
append(com.fishlib.base.log.LogOutput logOutput)
void
force()
Make sure any previous writes to the underlying file through this file accessor are persisted, synchronously.String
getImplementationName()
Get a name for the implementing class.FileAccessor
getOffsetView(long startOffset)
Get an offset view into this FileAccessor.int
read(ByteBuffer buffer, long position)
Fill the supplied buffer with data starting at the supplied offset (position) into this file accessor.long
size(long requiredSize)
Request an up-to-date size value for the file data space backing this accessor.String
toString()
void
truncate(long size)
Truncate the file data space backing this accessor to the supplied size.int
write(ByteBuffer buffer, long position)
Write the supplied buffer (from buffer.position(), inclusive, to buffer.limit(), exclusive), starting at the supplied offset (position) into this file accessor.
-
Constructor Details
-
Method Details
-
size
public final long size(long requiredSize)Description copied from interface:FileAccessor
Request an up-to-date size value for the file data space backing this accessor.- Specified by:
size
in interfaceFileAccessor
- Parameters:
requiredSize
- Hint about the minimum size the caller would like as a result- Returns:
- The size of the file data space backing this accessor
-
read
Description copied from interface:FileAccessor
Fill the supplied buffer with data starting at the supplied offset (position) into this file accessor. A successful invocation will fill the buffer from buffer.position(), inclusive, to at least buffer.limit(), exclusive, possibly up to buffer.capacity(), exclusive.- Specified by:
read
in interfaceFileAccessor
- Parameters:
buffer
- A buffer with state appropriate for a call to FileChannel.read()position
- The start position in this file accessor's data space to read from- Returns:
- The number of bytes read, or -1 on error
-
write
Description copied from interface:FileAccessor
Write the supplied buffer (from buffer.position(), inclusive, to buffer.limit(), exclusive), starting at the supplied offset (position) into this file accessor.- Specified by:
write
in interfaceFileAccessor
- Parameters:
buffer
- A buffer with state appropriate for a call to FileChannel.write()position
- The start position in this file accessor's data space to write to- Returns:
- The number of bytes written, or -1 on error
-
truncate
public void truncate(long size)Description copied from interface:FileAccessor
Truncate the file data space backing this accessor to the supplied size.- Specified by:
truncate
in interfaceFileAccessor
- Parameters:
size
- The new size
-
force
public void force()Description copied from interface:FileAccessor
Make sure any previous writes to the underlying file through this file accessor are persisted, synchronously.- Specified by:
force
in interfaceFileAccessor
-
getOffsetView
Description copied from interface:FileAccessor
Get an offset view into this FileAccessor.- Specified by:
getOffsetView
in interfaceFileAccessor
- Parameters:
startOffset
- The offset- Returns:
- The new offset view accessor
-
getImplementationName
Description copied from interface:NamedImplementation
Get a name for the implementing class. Useful for abstract classes that implement
LogOutputAppendable
or overridetoString
.The default implementation is correct, but not suitable for high-frequency usage.
- Specified by:
getImplementationName
in interfaceNamedImplementation
- Returns:
- A name for the implementing class
-
append
public com.fishlib.base.log.LogOutput append(@NotNull com.fishlib.base.log.LogOutput logOutput)- Specified by:
append
in interfacecom.fishlib.base.log.LogOutputAppendable
-
toString
-