Interface ResourceChangeListener

  • @ConsumerType
    public interface ResourceChangeListener
    Listener for resource change events.

    ResourceChangeListener objects are registered with the Framework service registry and are notified with ResourceChange objects when a change occurs.

    ResourceChangeListener objects can inspect the received ResourceChange objects to determine the type of change, location and other properties.

    ResourceChangeListener objects must be registered with a service property PATHS whose value is the list of resource paths for which the listener is interested in getting change events.

    By default a resource listener gets only local events which means events caused by changes persisted on the same instance as this listener is registered. If the resource listener is interested in external events, the implementation should implement the ExternalResourceChangeListener interface, but still register the service as a ResourceChangeListener service.

    1.0.0 (Sling API Bundle 2.11.0)
    • Field Detail

      • PATHS

        static final java.lang.String PATHS

        Array of paths or glob patterns - required.

        A path is either absolute or relative. If it's a relative path, the relative path will be appended to all search paths of the resource resolver.

        If the whole tree of all search paths should be observed, the special value . should be used.

        A glob pattern must start with the glob: prefix (e.g. glob:**/*.html). The following rules are used to interpret glob patterns:

        • The * character matches zero or more characters of a name component without crossing directory boundaries.
        • The ** characters match zero or more characters crossing directory boundaries.
        • If the pattern is relative (does not start with a slash), the relative path will be appended to all search paths of the resource resolver.

        In general, it can't be guaranteed that the underlying implementation of the resources will send a remove event for each removed resource. For example if the root of a tree, like /foo is removed, the underlying implementation might only send a single remove event for /foo but not for any child resources. Therefore if a listener is interested in resource remove events, it might get remove events for resources that not directly match the specified pattern/filters. For example if a listener is registered for /foo/bar and /foo is removed, the listener will get a remove event for /foo. The same is true if any pattern is used and any parent of a matching resource is removed. If a listener is interested in remove events, it will get a remove of any parent resource from the specified paths or patterns. The listener must handle these events accordingly.

        If one of the paths is a sub resource of another specified path, the sub path is ignored.

        If this property is missing or invalid, the listener is ignored. The type of the property must either be String, or a String array.

        See Also:
        Constant Field Values
      • CHANGES

        static final java.lang.String CHANGES
        Array of change types - optional. If this property is missing, added, removed and changed events for resources and added and removed events for resource providers are reported. If this property is invalid, the listener is ignored. The type of the property must either be String, or a String array. Valid values are the constants from this class whose names are starting with CHANGE_. They map to one of the values of ResourceChange.ChangeType.
        See Also:
        Constant Field Values

        static final java.lang.String PROPERTY_NAMES_HINT
        An optional hint indicating to the underlying implementation that for changes regarding properties (added/removed/changed) the listener is only interested in those property names listed inhere. If the underlying implementation supports this, events for property names that are not enlisted here will not be delivered, however events concerning resources are not affected by this hint. This is only a hint, a change listener registering with this property must be prepared that the underlying implementation is not able to filter based on this property. In this case the listener gets all events as defined with the other properties.
        See Also:
        Constant Field Values
    • Method Detail

      • onChange

        void onChange​(@NotNull
                      @NotNull java.util.List<ResourceChange> changes)
        Report resource changes based on the filter properties of this listener.

        Starting with version 1.2 of this API, an instance of ResoureChangeList is passed as the parameter to allow passing additional information.

        changes - The changes list. This list is immutable.