Interface ServiceUnitStateTableView

All Superinterfaces:
AutoCloseable, Closeable
All Known Implementing Classes:
ServiceUnitStateMetadataStoreTableViewImpl, ServiceUnitStateTableViewImpl

public interface ServiceUnitStateTableView extends Closeable
Given that the ServiceUnitStateChannel event-sources service unit (bundle) ownership states via a persistent store and reacts to ownership changes, the ServiceUnitStateTableView provides an interface to the ServiceUnitStateChannel's persistent store and its locally replicated ownership view (tableview) with listener registration. It initially populates its local table view by scanning existing items in the remote store. The ServiceUnitStateTableView receives notifications whenever ownership states are updated in the remote store, and upon notification, it applies the updates to its local tableview with the listener logic.
  • Method Details

    • start

      void start(PulsarService pulsar, BiConsumer<String,ServiceUnitStateData> tailItemListener, BiConsumer<String,ServiceUnitStateData> existingItemListener) throws IOException
      Starts the tableview. It initially populates its local table view by scanning existing items in the remote store, and it starts listening to service unit ownership changes from the remote store.
      Parameters:
      pulsar - pulsar service reference
      tailItemListener - listener to listen tail(newly updated) items
      existingItemListener - listener to listen existing items
      Throws:
      IOException - if it fails to init the tableview.
    • close

      void close() throws IOException
      Closes the tableview.
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Throws:
      IOException - if it fails to close the tableview.
    • get

      Gets one item from the local tableview.
      Parameters:
      key - the key to get
      Returns:
      value if exists. Otherwise, null.
    • put

      Tries to put the item in the persistent store. If it completes, all peer tableviews (including the local one) will be notified and be eventually consistent with this put value. It ignores put operation if the input value conflicts with the existing one in the persistent store.
      Parameters:
      key - the key to put
      value - the value to put
      Returns:
      a future to track the completion of the operation
    • delete

      Tries to delete the item from the persistent store. All peer tableviews (including the local one) will be notified and be eventually consistent with this deletion. It ignores delete operation if the key is not present in the persistent store.
      Parameters:
      key - the key to delete
      Returns:
      a future to track the completion of the operation
    • entrySet

      Returns the entry set of the items in the local tableview.
      Returns:
      entry set
    • ownedServiceUnits

      Set<NamespaceBundle> ownedServiceUnits()
      Returns service units (namespace bundles) owned by this broker.
      Returns:
      a set of owned service units (namespace bundles)
    • flush

      void flush(long waitDurationInMillis) throws ExecutionException, InterruptedException, TimeoutException
      Tries to flush any batched or buffered updates.
      Parameters:
      waitDurationInMillis - time to wait until complete.
      Throws:
      ExecutionException
      InterruptedException
      TimeoutException