Package io.deephaven.util.channel
Interface SeekableChannelContext
- All Superinterfaces:
AutoCloseable,Function<Supplier<SafeCloseable>,,SafeCloseable> SafeCloseable
- All Known Implementing Classes:
BaseSeekableChannelContext
public interface SeekableChannelContext
extends Function<Supplier<SafeCloseable>,SafeCloseable>, SafeCloseable
Context object for reading and writing to channels created by
SeekableChannelsProvider.
The context object can hold a SafeCloseable resource, which can be plugged into the context by calling the
apply(Supplier) method. The resource will be closed when the context is closed.
-
Nested Class Summary
Nested Classes -
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescription@Nullable SafeCloseableapply(Supplier<SafeCloseable> resourceFactory) If this instance holds a resource, return it.default voidclose()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.
-
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 givencontextis compatible withprovider, a no-op holder around thatcontextwill 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
-
apply
If this instance holds a resource, return it. Otherwise, use the resource factory to create a new resource, store it, and return it. This method can return anullif the factory returns anull.- Specified by:
applyin interfaceFunction<Supplier<SafeCloseable>,SafeCloseable>
-
close
default void close()Release any resources associated with this context. The context should not be used afterward.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceSafeCloseable
-