Class FeatureListenerManager


  • public class FeatureListenerManager
    extends Object
    This class is used by DataStore implementations to provide FeatureListener support for the FeatureSources they create.

    FeatureWriters created by the DataStore will need to make use of this class to provide the required FeatureEvents. This class has been updated to store listeners using weak references in order to cut down on memory leaks.

    Author:
    Jody Garnett, Refractions Research
    • Constructor Detail

      • FeatureListenerManager

        public FeatureListenerManager()
    • Method Detail

      • addFeatureListener

        public void addFeatureListener​(FeatureSource<? extends FeatureType,​? extends Feature> featureSource,
                                       FeatureListener featureListener)
        Used by FeaureSource implementations to provide listener support.
      • removeFeatureListener

        public void removeFeatureListener​(FeatureSource<? extends FeatureType,​? extends Feature> featureSource,
                                          FeatureListener featureListener)
        Used by SimpleFeatureSource implementations to provide listener support.
      • fireFeaturesAdded

        public void fireFeaturesAdded​(String typeName,
                                      Transaction transaction,
                                      ReferencedEnvelope bounds,
                                      boolean commit)
        Notify all listeners that have registered interest for notification on this event type.

        This method is called by:

        • FeatureWriter.next() with FeatureWriter.hasNext() == false
          - when an existing Feature is removed with Tranasaction.AUTO_COMMIT all listeners registered with SimpleFeatureSource of typeName will be notified.
        • FeatureWriter.next()with FeatureWriter.hasNext() == false
          - when an existing Feature is removed with a Transaction all listeners registered with SimpleFeatureSource of typeName and with the same Transaction will be notified.

        NOTE requiring to fire this event at FeatureWriter.next() is quite a gap inherited from an old API when FeatureWriter.write() didn't exist yet. It's a good idea though to fire the event at FeatureWriter.write() instead of FeatureWriter.next() so there are actually changes to notify for.

        Parameters:
        typeName - typeName being modified
        transaction - Transaction used for change
        bounds - BoundingBox of changes (may be null if unknown)
        commit - true if
      • fireEvent

        public void fireEvent​(String typeName,
                              Transaction transaction,
                              FeatureEvent event)
        Provided event will be used as a template for notifying all FeatureSources for the provided typeName.
      • fireFeaturesChanged

        public void fireFeaturesChanged​(String typeName,
                                        Transaction transaction,
                                        ReferencedEnvelope bounds,
                                        boolean commit)
        Notify all listeners that have registered interest for notification on this event type.

        This method is called by:

        • FeatureWriter.next() with FeatureWriter.hasNext() == true
          - when an existing Feature is modified with Tranasaction.AUTO_COMMIT all listeners registered with SimpleFeatureSource of typeName will be notified.
        • FeatureWriter.next()with FeatureWriter.hasNext() == true
          - when an existing Feature is modified, with a Transaction all listeners registered with SimpleFeatureSource of typeName and with the same Transaction will be notified.

        NOTE requiring to fire this event at FeatureWriter.next() is quite a gap inherited from an old API when FeatureWriter.write() didn't exist yet. It's a good idea though to fire the event at FeatureWriter.write() instead of FeatureWriter.next() so there are actually changes to notify for.

        Parameters:
        typeName - typeName being modified
        transaction - Transaction used for change
        bounds - BoundingBox of changes (may be null if unknown)
      • fireChanged

        public void fireChanged​(String typeName,
                                Transaction transaction,
                                boolean commit)
        Notify all listeners that have registered interest for notification on this event type.

        This method is called by:

        • Transaction.commit()
          - when changes have occured on a Transaction all listeners registered with SimpleFeatureSource of typeName will be notified except those with the Same Transaction
        • Transaction.rollback()
          - when changes have been reverted only those listeners registered with SimpleFeatureSource of typeName and with the same Transaction will be notified.
        Parameters:
        typeName - typeName being modified
        transaction - Transaction used for change
        commit - true for commit, false for rollback
      • fireFeaturesRemoved

        public void fireFeaturesRemoved​(String typeName,
                                        Transaction transaction,
                                        ReferencedEnvelope bounds,
                                        boolean commit)
        Notify all listeners that have registered interest for notification on this event type.

        This method is called by:

        • FeatureWrtier.remove() - when an existing Feature is removed with Tranasaction.AUTO_COMMIT all listeners registered with SimpleFeatureSource of typeName will be notified.
        • FeatureWrtier.remove() - when an existing Feature is removed with a Transaction all listeners registered with SimpleFeatureSource of typeName and with the same Transaction will be notified.
        Parameters:
        typeName - typeName being modified
        transaction - Transaction used for change
        bounds - BoundingBox of changes (may be null if unknown)