Class FileDataBufferStore
TODO: Address "missed" pooling opportunities if/when they contribute significantly to server GC: (1) Buffer duplicate views. (2) Buffer read-only views. (3) Messages.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final class
Message implementation to wrap a stored buffer and associated boundaries. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final int
Null pending position value foracceptBufferByIndex(PooledObjectReference, int, ByteBuffer, int)
. -
Constructor Summary
ConstructorsConstructorDescriptionFileDataBufferStore
(FileAccessor fileAccessor, ByteOrder byteOrder) Construct a non-writable store.FileDataBufferStore
(FileAccessor fileAccessor, ByteOrder byteOrder, long initialSize, boolean writable) Construct an optionally-writable store. -
Method Summary
Modifier and TypeMethodDescriptionfinal void
acceptBufferByIndex
(PooledObjectReference<DataBufferHolder> holderRef, int bufferIndex, ByteBuffer inputBuffer, int pendingPosition) Accept a buffer for writing through to the store and underlying file, extending the size as needed.Disable release tracking if enabled, and get the release tracker.Enable release tracking if not already enabled, and get the release tracker.void
Ensure the underlying file exists.final void
ensureSize
(long requiredSize) Make sure size is large enough to accommodate a request.final void
force()
Ensure that all contents written to the store have been persisted.getMessageViewByOffset
(long startOffset, int minimumLength) Present a Message view of the implied buffer, with views positioned accordingly.final long
Force an update to the size if possible, and fetch the result.void
Make previously-accepted pending data part of the visible region of the store.provideBufferReferenceByIndex
(int bufferIndex, int requiredLimit) Get an acquiredPooledObjectReference
to the specified buffer'sDataBufferHolder
, and ensure that the current buffer (seeDataBufferHolder.getCurrent()
) is filled enough to accommodate the supplied limit.final void
Release any resources held for caching purposes.void
Release resources associated with previously-accepted pending data, and truncate the pending region of the underlying file.final long
size()
Get the current known visible size of the file data backing this store, in bytes.final String
toString()
-
Field Details
-
NULL_PENDING_POSITION
public static final int NULL_PENDING_POSITIONNull pending position value foracceptBufferByIndex(PooledObjectReference, int, ByteBuffer, int)
.- See Also:
-
-
Constructor Details
-
FileDataBufferStore
Construct a non-writable store.- Parameters:
fileAccessor
- An accessor for the file (or file region) that we're presenting a buffered view ofbyteOrder
- The byte order that should be used for all buffers in this store
-
FileDataBufferStore
public FileDataBufferStore(@NotNull FileAccessor fileAccessor, @NotNull ByteOrder byteOrder, long initialSize, boolean writable) Construct an optionally-writable store.- Parameters:
fileAccessor
- An accessor for the file (or file region) that we're presenting a buffered view ofbyteOrder
- The byte order that should be used for all buffers in this storeinitialSize
- Initially known visible size of the underlying file (or file region)writable
- Whether this store should allow writing (buffer accept)
-
-
Method Details
-
toString
-
releaseCachedResources
public final void releaseCachedResources()Release any resources held for caching purposes. This is primarily intended for applications that know they will no longer use a given data store.
This is perfectly safe for concurrent use in read-only applications, although it may result in repeated reads that would otherwise be unnecessary, and may cause repeated reads to be recorded as first time reads by the performance instrumentation sub-system.
Writers should be careful to avoid having outstanding buffers before invoking this.
-
size
public final long size()Get the current known visible size of the file data backing this store, in bytes.- Returns:
- The current known visible size of the file data backing this store, in bytes.
-
getUpdatedSize
public final long getUpdatedSize()Force an update to the size if possible, and fetch the result.- Returns:
- The resulting size
-
ensureSize
public final void ensureSize(long requiredSize) Make sure size is large enough to accommodate a request. Call before proceeding with any request.- Parameters:
requiredSize
- The size required by the caller in order to make progress
-
force
public final void force()Ensure that all contents written to the store have been persisted. -
ensureFileExists
public void ensureFileExists()Ensure the underlying file exists. -
getMessageViewByOffset
public final FileDataBufferStore.StoredBufferMessage getMessageViewByOffset(long startOffset, int minimumLength) Present a Message view of the implied buffer, with views positioned accordingly. The result should be "released" using Message.finished(), per the usual usage of Message objects.- Parameters:
startOffset
- 0 <= startOffsetminimumLength
- 0 < minimumLength <= getBufferSize()- Returns:
- A Message for use in transmission via an IOJob.
-
provideBufferReferenceByIndex
public final PooledObjectReference<DataBufferHolder> provideBufferReferenceByIndex(int bufferIndex, int requiredLimit) Get an acquired
PooledObjectReference
to the specified buffer'sDataBufferHolder
, and ensure that the current buffer (seeDataBufferHolder.getCurrent()
) is filled enough to accommodate the supplied limit.The referent's current view will be positioned for reading all available data, and should only be accessed via positional "get" methods - hand a read-only view (see
DataBufferHolder.readOnlyView()
) to untrusted code, or a writable view (seeDataBufferHolder.writableView()
) to code that will write new contents for a later call toacceptBufferByIndex(PooledObjectReference, int, ByteBuffer, int)
.The caller is responsible for calling
PooledObjectReference.release()
on the returned reference when it's done.- Parameters:
bufferIndex
- The buffer's index.requiredLimit
- The limit required by the caller.- Returns:
- An acquired
PooledObjectReference
to a non-nullDataBufferHolder
whose current view hascapacity == getBufferSize()
and0 <= requiredLimit <= limit
-
enableReleaseTracking
Enable release tracking if not already enabled, and get the release tracker.- Returns:
- The release tracker
-
disableReleaseTracking
Disable release tracking if enabled, and get the release tracker.- Returns:
- The release tracker, possibly null
-
acceptBufferByIndex
public final void acceptBufferByIndex(PooledObjectReference<DataBufferHolder> holderRef, int bufferIndex, ByteBuffer inputBuffer, int pendingPosition) Accept a buffer for writing through to the store and underlying file, extending the size as needed. The buffer must be positioned to read the region to be accepted, must be a duplicate of holderRef's current referent, and *must* no longer be accessed externally unless through a view/duplicate. The holderRef must have been acquired by or on-behalf-of the caller, and must not be released concurrently with this invocation.
This method does not release holderRef on behalf of the caller - the caller very well may create another duplicate to fill, for example.
pendingPosition must be
NULL_PENDING_POSITION
or a value such that inputBuffer.position() <= pendingPosition < inputBuffer.limit(). Such content is provisionally accepted but not made visible to readers untilpromotePending()
is invoked.- Parameters:
holderRef
- The pooled reference corresponding to the supplied buffer index (only used for verification)bufferIndex
- The buffer's indexinputBuffer
- The ByteBuffer to acceptpendingPosition
- If non-null, the position from which to treat inputBuffer's contents as pending
-
promotePending
public void promotePending()Make previously-accepted pending data part of the visible region of the store. -
revertPending
public void revertPending()Release resources associated with previously-accepted pending data, and truncate the pending region of the underlying file.
-