Interface ResourceEventHandler<T>

  • Type Parameters:
    T - resource

    public interface ResourceEventHandler<T>
    ResourceEventHandler can handle notifications for events that happen to a resource. The events are information only, so you can't return an error.
    • Method Summary

      All Methods Instance Methods Abstract Methods Default Methods Deprecated Methods 
      Modifier and Type Method Description
      void onAdd​(T obj)
      Called when an object is added.
      default void onBeforeList​(String lastSyncResourceVersion)
      Called once per list/watch cycle, before the list operation is initiated.
      void onDelete​(T obj, boolean deletedFinalStateUnknown)
      Gets the final state of the item if it is known, otherwise it would get an object of the DeletedFinalStateUnknown.
      default void onList​(String resourceVersion, boolean remainedEmpty)
      Called after a listing is completed.
      default void onNothing()
      Deprecated.
      - use onList(String, boolean) and check if the cache remained empty
      void onUpdate​(T oldObj, T newObj)
      Called when an object is modified.
    • Method Detail

      • onNothing

        @Deprecated
        default void onNothing()
        Deprecated.
        - use onList(String, boolean) and check if the cache remained empty
        Called after an empty list is retrieved on start or after an HTTP GONE when the Store is empty

        Should not be implemented with long-running logic as that may lead to memory issues.

      • onBeforeList

        default void onBeforeList​(String lastSyncResourceVersion)
        Called once per list/watch cycle, before the list operation is initiated. This fires for the initial list and for every fresh re-list — whether triggered by an HTTP GONE or by any other watch failure that goes through the reconnect path — but not for retry attempts that follow a transient failure within the same cycle (i.e. before the matching onList(String, boolean) has been delivered).

        In the window between this callback and the matching onList(String, boolean):

        • resources already deleted on the server may still be present in the cache — deletions detected by the list are not reconciled into the cache until just before onList is called.
        • the last sync resource version reported here remains frozen for the duration of the list. On a re-list, onAdd / onUpdate events can still be emitted from the in-flight list pages with resource versions newer than lastSyncResourceVersion; on the initial list the additions are instead deferred and delivered as a single batch just before onList(String, boolean).

        Should not be implemented with long-running logic as that may lead to memory issues.

        This method is not called for re-sync.

        Parameters:
        lastSyncResourceVersion - the latest resource version known prior to the list operation, or null if no list has completed yet
      • onList

        default void onList​(String resourceVersion,
                            boolean remainedEmpty)
        Called after a listing is completed. By default calls onNothing() when remainedEmpty is true.

        Should not be implemented with long-running logic as that may lead to memory issues.

        This method is not called for re-sync.

        Parameters:
        resourceVersion - the latest resource version known to the list operation
        remainedEmpty - will be true if the cache remained empty prior to and after the list operation meaning no other events would have been emitted as part of the relist
      • onAdd

        void onAdd​(T obj)
        Called when an object is added.

        Should not be implemented with long-running logic as that may lead to memory issues.

        Parameters:
        obj - object
      • onUpdate

        void onUpdate​(T oldObj,
                      T newObj)
        Called when an object is modified. Note that oldObj is the last known state of the object -- it is possible that several changes were combined together, so you can't use this to see every single change. It is also called when a sync happens - oldObj will be the same as newObj.

        Should not be implemented with long-running logic as that may lead to memory issues.

        Parameters:
        oldObj - old object
        newObj - new object
      • onDelete

        void onDelete​(T obj,
                      boolean deletedFinalStateUnknown)
        Gets the final state of the item if it is known, otherwise it would get an object of the DeletedFinalStateUnknown. This can happen if the watch is closed and misses the delete event and we don't notice the deletion until the subsequent re-list.

        Should not be implemented with long-running logic as that may lead to memory issues.

        Parameters:
        obj - object to delete
        deletedFinalStateUnknown - get final state of item if it is known or not.