Class ContentState
- Direct Known Subclasses:
JDBCState
,MemoryState
,VectorMosaicState
,WFSContentState
ContentEntry
.
Data Cache Synchronization Required
The default ContentState implementation maintains cached values on a per transaction basis:
- feature type (
getFeatureType()
- number of features (
getCount()
- spatial extent (
getBounds()
This class is a "data object" used to store values and is not thread safe. It is up to clients of this class to ensure that values are set in a thread-safe / synchronized manner. For example:
ContentState state = ...;
//get the count
int count = state.getCount();
if ( count == -1 ) {
synchronized ( state ) {
count = calculateCount();
state.setCount( count );
}
}
Event Notification
The list of listeners interested in event notification as features are modified and edited is stored as part of ContentState. Each notification is considered to be broadcast from a specific FeatureSource. Since several ContentFeatureStores can be on the same transaction (and thus share a ContentState) the fire methods listed here require you pass in the FeatureSource making the change; this requires that your individual FeatureWriters keep a pointer to the ContentFeatureStore which created them.You may also make use of ContentFeatureSource.canEvent()
value of false
allowing the base
ContentFeatureStore class to take responsibility for sending event notifications.
Transaction Independence
The default ContentState implementation also supports the handling of ContentFeatureSource#canTransaction
value of false
. The implementation asks ContentState to store a Diff
which is used to record any
modifications made until commit is called.
Internally a Transaction.State
is used to notify the implementation of {Transaction.commit()
and
Transaction.rollback()
.
Extension
This class may be extended if your implementaiton wishes to capture additional information per transaction. A database implementation using a JDBCContentState to store a JDBC Connection remains a good example.Subclasses may extend (not override) the following methods:
Subclasses should also overridecopy()
to ensure any additional state they are keeping is correctly
accounted for.- Since:
- 2.6
- Author:
- Jody Garnett (LISASoft), Justin Deoliveira, The Open Planning Project
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected BatchFeatureEvent
Even used for batch notification; used to collect the bounds and feature ids generated over the course of a transaction.protected ReferencedEnvelope
cached bounds of featuresprotected int
cached number of featuresprotected ContentEntry
entry maintaining the stateprotected SimpleFeatureType
cached feature typeprotected List<FeatureListener>
observersprotected DiffTransactionState
Callback used to issue batch feature events when commit/rollback issued on the transaction.protected Transaction
Transaction the state works from. -
Constructor Summary
ConstructorsModifierConstructorDescriptionContentState
(ContentEntry entry) Creates a new state.protected
ContentState
(ContentState state) Creates a new state from a previous one. -
Method Summary
Modifier and TypeMethodDescriptionfinal void
addListener
(FeatureListener listener) Adds a listener for collection events.void
close()
Clears all state.copy()
Copies the state.final void
fireBatchFeatureEvent
(boolean isCommit) Notifies all waiting listeners that a commit has been issued; this notification is also sent to ourfinal void
fireFeatureAdded
(FeatureSource<?, ?> source, Feature feature) Used to issue a Type.ADDED FeatureEvent indicating a new feature being createdfinal void
fireFeatureEvent
(FeatureEvent event) Used to issue a single FeatureEvent.void
fireFeatureRemoved
(FeatureSource<?, ?> source, Feature feature) void
fireFeatureUpdated
(FeatureSource<?, ?> source, Feature feature, ReferencedEnvelope before) Creates a FeatureEvent indicating that the provided feature has been changed.void
flush()
Clears cached state.final ReferencedEnvelope
The cached spatial extent.final int
getCount()
The cached number of features.getEntry()
The entry which maintains the state.final SimpleFeatureType
The cached feature type.The transaction associated with the state.final boolean
Used to quickly test if any listeners are available.final void
removeListener
(FeatureListener listener) Removes a listener for collection events.final void
setBounds
(ReferencedEnvelope bounds) Sets the cached spatial extent.final void
setCount
(int count) Sets the cached number of features.final void
setFeatureType
(SimpleFeatureType featureType) Sets the cached feature type.void
Sets the transaction associated with the state.
-
Field Details
-
tx
Transaction the state works from. -
entry
entry maintaining the state -
featureType
cached feature type -
count
protected int countcached number of features -
bounds
cached bounds of features -
batchFeatureEvent
Even used for batch notification; used to collect the bounds and feature ids generated over the course of a transaction. -
listeners
observers -
transactionState
Callback used to issue batch feature events when commit/rollback issued on the transaction.
-
-
Constructor Details
-
ContentState
Creates a new state.- Parameters:
entry
- The entry for the state.
-
ContentState
Creates a new state from a previous one.All state from the specified state is copied. Therefore subclasses extending this constructor should clone all mutable objects.
- Parameters:
state
- The existing state.
-
-
Method Details
-
getEntry
The entry which maintains the state. -
getTransaction
The transaction associated with the state. -
setTransaction
Sets the transaction associated with the state. -
getFeatureType
The cached feature type. -
setFeatureType
Sets the cached feature type. -
getCount
public final int getCount()The cached number of features. -
setCount
public final void setCount(int count) Sets the cached number of features. -
getBounds
The cached spatial extent. -
setBounds
Sets the cached spatial extent. -
addListener
Adds a listener for collection events.- Parameters:
listener
- The listener to add
-
removeListener
Removes a listener for collection events.- Parameters:
listener
- The listener to remove
-
getBatchFeatureEvent
-
hasListener
public final boolean hasListener()Used to quickly test if any listeners are available. -
fireFeatureUpdated
public void fireFeatureUpdated(FeatureSource<?, ?> source, Feature feature, ReferencedEnvelope before) Creates a FeatureEvent indicating that the provided feature has been changed.This method is provided to simplify event notification for implementors by constructing a FeatureEvent internally (and then only if listeners are interested). You may find it easier to construct your own FeatureEvent using {
hasListener()
to check if you need to fire events at all.- Parameters:
source
- FeatureSource responsible for the changefeature
- The updated featurebefore
- the bounds of the feature before the change
-
fireFeatureAdded
Used to issue a Type.ADDED FeatureEvent indicating a new feature being created -
fireFeatureRemoved
-
fireFeatureEvent
Used to issue a single FeatureEvent.If this content state is used for Transaction.AUTO_COMMIT the notification will be passed to all interested parties.
If not this event will be recored as part of a BatchFeatureEvent that will to be issued using issueBatchFeatureEvent()
-
fireBatchFeatureEvent
public final void fireBatchFeatureEvent(boolean isCommit) Notifies all waiting listeners that a commit has been issued; this notification is also sent to our -
flush
public void flush()Clears cached state.This method does not affect any non-cached state. This method may be extended by subclasses, but not overiden.
-
close
public void close()Clears all state.Any resources that the state holds onto (like a database connection) should be closed or disposes when this method is called. This method may be extended by subclasses, but not overiden.
-
copy
Copies the state.Subclasses should override this method. Any mutable state objects should be cloned.
- Returns:
- A copy of the state.
-