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:
Readerthat are wrappers aroundInputStream.ChannelDataInputwhen the channel come from anInputStream.ChannelDataInputwhen the channel has been explicitly given to the constructor.
-
Field Summary
FieldsModifier and TypeFieldDescription(package private) final byteBitwise combination ofStorageConnector.CASCADE_ON_CLOSE,StorageConnector.CASCADE_ON_RESETorStorageConnector.CLEAR_ON_RESET.(package private) boolean(package private) ObjectTheStorageConnector.storageviewed as another kind of object.private StorageConnector.Coupled[]The other views that are consumingview, ornullif none.(package private) final StorageConnector.CoupledThe object thatviewis wrapping. -
Constructor Summary
ConstructorsConstructorDescriptionCreates a wrapper forStorageConnector.storage.Coupled(StorageConnector.Coupled wrapperFor, byte cascade) Creates a wrapper for a view wrapping the givenCoupledinstance. -
Method Summary
Modifier and TypeMethodDescription(package private) final voidappend(TreeTable.Node appendTo, Map<Class<?>, StorageConnector.Coupled> views) Formats the currentCoupledand all its children as a tree in the given tree table node.(package private) final boolean(package private) final boolean(package private) final voidDeclares as invalid all unsynchronizedCoupledinstances which are used, directly or indirectly, by this instance.(package private) final voidDeclares as invalid all unsynchronizedCoupledinstances which are using, directly or indirectly, this instance.(package private) final voidprotect(Map<AutoCloseable, Boolean> toClose) Identifies the other views to not close if we don't want to close theviewwrapped by thisCoupled.(package private) final booleanreset()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.storageviewed 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.storageis already an instance ofDataInput, this entry will be given an instance ofChannelImageInputStreamif 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 asDataInputif it can be casted, ornullotherwise.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 thatviewis wrapping. For example ifviewis anInputStreamReader, thenwrapperFor.viewis anInputStream. This field isnullifview==StorageConnector.storage. -
wrappedBy
The other views that are consumingview, ornullif none. For each element in this array,wrappedBy[i].wrapperFor == this. -
cascade
final byte cascadeBitwise combination ofStorageConnector.CASCADE_ON_CLOSE,StorageConnector.CASCADE_ON_RESETorStorageConnector.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 aCoupledinstance for another view wrappingstorage. -
Coupled
Coupled(StorageConnector.Coupled wrapperFor, byte cascade) Creates a wrapper for a view wrapping the givenCoupledinstance. Caller is responsible to set theviewfield after this constructor call.- Parameters:
wrapperFor- the object thatviewwill wrap, ornullif none.cascade- bitwise combination ofStorageConnector.CASCADE_ON_CLOSE,StorageConnector.CASCADE_ON_RESETorStorageConnector.CLEAR_ON_RESET.
-
-
Method Details
-
cascadeOnClose
final boolean cascadeOnClose()trueif after closing theview, we need to also close thewrapperFor. Should betruewhen the view is anImageInputStreambecause Java I/OFileCacheImageInputStream.close()does not close the underlying stream. For most other kinds of view, should befalse. -
cascadeOnReset
final boolean cascadeOnReset()trueif calls toreset()should cascade towrapperFor. This isfalseif any change in the position ofviewis immediately reflected in the position ofwrapperFor, and vice-versa. -
invalidateSources
final void invalidateSources()Declares as invalid all unsynchronizedCoupledinstances 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 unsynchronizedCoupledinstances 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 theviewwrapped 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:
trueif some kind of reset has been performed. Note that it does means that the viewisValidistrue.- Throws:
IOException
-
toString
Returns a string representation for debugging purpose. -
append
Formats the currentCoupledand 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.viewsmap. Will be read only.
-