Interface ServiceUnitStateTableView
- All Superinterfaces:
AutoCloseable,Closeable
- All Known Implementing Classes:
ServiceUnitStateMetadataStoreTableViewImpl,ServiceUnitStateTableViewImpl
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 Summary
Modifier and TypeMethodDescriptionvoidclose()Closes the tableview.Tries to delete the item from the persistent store.entrySet()Returns the entry set of the items in the local tableview.voidflush(long waitDurationInMillis) Tries to flush any batched or buffered updates.Gets one item from the local tableview.Returns service units (namespace bundles) owned by this broker.put(String key, ServiceUnitStateData value) Tries to put the item in the persistent store.voidstart(PulsarService pulsar, BiConsumer<String, ServiceUnitStateData> tailItemListener, BiConsumer<String, ServiceUnitStateData> existingItemListener) Starts the tableview.
-
Method Details
-
start
void start(PulsarService pulsar, BiConsumer<String, ServiceUnitStateData> tailItemListener, BiConsumer<String, throws IOExceptionServiceUnitStateData> existingItemListener) 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 referencetailItemListener- listener to listen tail(newly updated) itemsexistingItemListener- listener to listen existing items- Throws:
IOException- if it fails to init the tableview.
-
close
Closes the tableview.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- 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 putvalue- 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
Set<Map.Entry<String,ServiceUnitStateData>> 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:
ExecutionExceptionInterruptedExceptionTimeoutException
-