Class DittoStoreObserver

java.lang.Object
com.ditto.java.DittoStoreObserver
All Implemented Interfaces:
AutoCloseable

public final class DittoStoreObserver extends Object implements AutoCloseable

A store observer that monitors query results and invokes a handler when they change.

Store observers enable reactive data access by automatically notifying your application when the results of a DQL query change. Create a store observer by calling DittoStore.registerObserver(String, DittoCborSerializable.Dictionary, DittoChangeListener).

The store observer remains active until one of the following occurs:

- The [#close()] method is called
- The owning [Ditto] instance goes out of scope

This class implements AutoCloseable for resource management. Use try-with-resources statements for automatic cleanup.

See Also:
  • Method Details

    • getQuery

      public @NonNull String getQuery()

      Returns the DQL query string for this store observer.

      This is the same query string that was passed when registering the observer.

      Returns:
      the DQL query string.
    • getArguments

      public @Nullable DittoCborSerializable.Dictionary getArguments()

      Returns the query arguments for this store observer.

      These are the same query arguments that were passed when registering the observer. If no arguments were provided during registration, this method returns null.

      Returns:
      the query arguments as a DittoCborSerializable.Dictionary, or null if none were provided.
    • isClosed

      public boolean isClosed()

      Returns whether this store observer is closed.

      A store observer is considered closed if:

      Returns:
      true if the store observer is closed; false otherwise.
    • close

      public void close() throws DittoException

      Closes this store observer and stops monitoring for changes.

      After calling this method, the handler that was registered with this store observer will no longer be invoked. This is a no-op if the store observer is already closed or the owning Ditto instance has gone out of scope.

      Specified by:
      close in interface AutoCloseable
      Throws:
      DittoException - if an error occurs during cleanup.
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object