Package io.deephaven.util.channel
Interface SeekableChannelContext
- All Superinterfaces:
AutoCloseable
,SafeCloseable
- All Known Implementing Classes:
BaseSeekableChannelContext
Context object for reading and writing to channels created by
SeekableChannelsProvider
.
The context object can hold SafeCloseable
resources corresponding to String
keys, which can be
plugged into the context by calling the getCachedResource(String, Supplier)
method. These resources will be
closed when the context is closed.
-
Nested Class Summary
-
Field Summary
-
Method Summary
Modifier and TypeMethodDescriptiondefault void
close()
Release any resources associated with this context.ensureContext
(SeekableChannelsProvider provider, SeekableChannelContext context) A pattern that allows callers to ensure a valid context has been created forprovider
.<T extends SafeCloseable>
TgetCachedResource
(String key, Supplier<T> resourceFactory) If this instance holds a resource corresponding to the given key, return it.
-
Field Details
-
NULL
-
-
Method Details
-
ensureContext
static SeekableChannelContext.ContextHolder ensureContext(SeekableChannelsProvider provider, SeekableChannelContext context) A pattern that allows callers to ensure a valid context has been created forprovider
. In the case where the givencontext
is compatible with
provider
, a no-op holder around thatcontext
will be returned. Otherwise, a holder with a newSeekableChannelsProvider.makeSingleUseContext()
will be returned. The returned holder should ideally be used in a try-with-resources construction.- Parameters:
provider
- the providercontext
- the context- Returns:
- the context holder
-
getCachedResource
If this instance holds a resource corresponding to the given key, return it. Otherwise, use the resource factory to create a new resource, store it, and return it. This method can return anull
if the factory returns anull
. -
close
default void close()Release any resources associated with this context. The context should not be used afterward.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceSafeCloseable
-