Package org.apache.sis.storage
Class StorageConnector.Coupled
java.lang.Object
org.apache.sis.storage.StorageConnector.Coupled
- Enclosing class:
StorageConnector
Wraps an instance of @link InputStream},
DataInput
, Reader
, etc. together with additional
information about other objects that are coupled with the wrapped object. For example if a Reader
is a
wrapper around the user supplied InputStream
, then those two objects will be wrapped in Coupled
instances together with information about how they are related
One purpose of Coupled
information is to keep trace of objects which will need to be closed by the
StorageConnector.closeAllExcept(Object)
method (for example an InputStreamReader
wrapping
an InputStream
).
Another purpose is to determine which views need to be synchronized if StorageConnector.storage
is
used independently. They are views that may advance storage
position, but not at the same time than the
view
position (typically because the view reads some bytes in advance and stores them in a buffer).
Such coupling may occur when the storage is an InputStream
, an OutputStream
or a
Channel
. The coupled view
can be:
Reader
that are wrappers aroundInputStream
.ChannelDataInput
when the channel come from anInputStream
.ChannelDataInput
when the channel has been explicitly given to the constructor.
-
Field Summary
FieldsModifier and TypeFieldDescription(package private) final byte
Bitwise combination ofStorageConnector.CASCADE_ON_CLOSE
,StorageConnector.CASCADE_ON_RESET
orStorageConnector.CLEAR_ON_RESET
.(package private) boolean
(package private) Object
TheStorageConnector.storage
viewed as another kind of object.private StorageConnector.Coupled[]
The other views that are consumingview
, ornull
if none.(package private) final StorageConnector.Coupled
The object thatview
is wrapping. -
Constructor Summary
ConstructorsConstructorDescriptionCreates a wrapper forStorageConnector.storage
.Coupled
(StorageConnector.Coupled wrapperFor, byte cascade) Creates a wrapper for a view wrapping the givenCoupled
instance. -
Method Summary
Modifier and TypeMethodDescription(package private) final void
append
(TreeTable.Node appendTo, Map<Class<?>, StorageConnector.Coupled> views) Formats the currentCoupled
and all its children as a tree in the given tree table node.(package private) final boolean
(package private) final boolean
(package private) final void
Declares as invalid all unsynchronizedCoupled
instances which are used, directly or indirectly, by this instance.(package private) final void
Declares as invalid all unsynchronizedCoupled
instances which are using, directly or indirectly, this instance.(package private) final void
protect
(Map<AutoCloseable, Boolean> toClose) Identifies the other views to not close if we don't want to close theview
wrapped by thisCoupled
.(package private) final boolean
reset()
Resets the position of all sources of theview
, then the view itself.toString()
Returns a string representation for debugging purpose.
-
Field Details
-
view
Object viewTheStorageConnector.storage
viewed as another kind of object. Supported types are:ByteBuffer
: A read-only view of the buffer over the first bytes of the stream.DataInput
: The input as a data input stream. Unless theStorageConnector.storage
is already an instance ofDataInput
, this entry will be given an instance ofChannelImageInputStream
if possible rather than an arbitrary stream. In particular, we invoke theImageIO.createImageInputStream(Object)
factory method only in last resort because some SIS data stores will want to access the channel and buffer directly.ImageInputStream
: Same asDataInput
if it can be casted, ornull
otherwise.InputStream
: If not explicitly provided, this is a wrapper around the aboveImageInputStream
.Reader
: If not explicitly provided, this is a wrapper around the aboveInputStream
.Connection
: The storage object as a JDBC connection.
-
wrapperFor
The object thatview
is wrapping. For example ifview
is anInputStreamReader
, thenwrapperFor.view
is anInputStream
. This field isnull
ifview
==StorageConnector.storage
. -
wrappedBy
The other views that are consumingview
, ornull
if none. For each element in this array,wrappedBy[i].wrapperFor == this
. -
cascade
final byte cascadeBitwise combination ofStorageConnector.CASCADE_ON_CLOSE
,StorageConnector.CASCADE_ON_RESET
orStorageConnector.CLEAR_ON_RESET
. -
isValid
boolean isValid
-
-
Constructor Details
-
Coupled
Coupled(Object storage) Creates a wrapper forStorageConnector.storage
. This constructor is used when we need to create aCoupled
instance for another view wrappingstorage
. -
Coupled
Coupled(StorageConnector.Coupled wrapperFor, byte cascade) Creates a wrapper for a view wrapping the givenCoupled
instance. Caller is responsible to set theview
field after this constructor call.- Parameters:
wrapperFor
- the object thatview
will wrap, ornull
if none.cascade
- bitwise combination ofStorageConnector.CASCADE_ON_CLOSE
,StorageConnector.CASCADE_ON_RESET
orStorageConnector.CLEAR_ON_RESET
.
-
-
Method Details
-
cascadeOnClose
final boolean cascadeOnClose()true
if after closing theview
, we need to also close thewrapperFor
. Should betrue
when the view is anImageInputStream
because Java I/OFileCacheImageInputStream.close()
does not close the underlying stream. For most other kinds of view, should befalse
. -
cascadeOnReset
final boolean cascadeOnReset()true
if calls toreset()
should cascade towrapperFor
. This isfalse
if any change in the position ofview
is immediately reflected in the position ofwrapperFor
, and vice-versa. -
invalidateSources
final void invalidateSources()Declares as invalid all unsynchronizedCoupled
instances which are used, directly or indirectly, by this instance. This method is invoked beforeStorageConnector.getStorageAs(Class)
returns a view, in order to remember which views would need to be resynchronized if they are requested. -
invalidateUsages
final void invalidateUsages()Declares as invalid all unsynchronizedCoupled
instances which are using, directly or indirectly, this instance. This method is invoked beforeStorageConnector.getStorageAs(Class)
returns a view, in order to remember which views would need to be resynchronized if they are requested. -
protect
Identifies the other views to not close if we don't want to close theview
wrapped by thisCoupled
. This method identifies only the views that use this view; it does not identify the views used by this view. This method is forStorageConnector.closeAllExcept(Object)
internal usage.- Parameters:
toClose
- the map where to write the list of views to not close.
-
reset
Resets the position of all sources of theview
, then the view itself.- Returns:
true
if some kind of reset has been performed. Note that it does means that the viewisValid
istrue
.- Throws:
IOException
-
toString
Returns a string representation for debugging purpose. -
append
Formats the currentCoupled
and all its children as a tree in the given tree table node. This method is used forStorageConnector.toString()
implementation only and may change in any future version.- Parameters:
appendTo
- where to write name, value and children.views
- reference to theStorageConnector.views
map. Will be read only.
-