Class LoomTopic<T>
java.lang.Object
com.loomcache.client.LoomTopic<T>
- Type Parameters:
T- the type of messages published to the topic
Client-side distributed topic proxy (publish-subscribe).
Provides publish operations to a distributed topic stored in the LoomCache cluster. Messages published to a topic are broadcast to all subscribers via the client's polling-based subscription loop.
Thread Safety
This class is thread-safe. Multiple threads may publish concurrently; the underlying LoomClient handles synchronization and connection pooling.- Since:
- 1.0
-
Method Summary
Modifier and TypeMethodDescriptionintvoidTear down every active polling subscription owned by this topic.longlong@Nullable TopicSequenceLostExceptionlonglonglongvoidPublishes a message to this topic.intSubscribe to messages on this topic using polling.intsubscribe(Consumer<T> listener, Consumer<TopicSequenceLostException> sequenceLossHandler) Subscribe to messages and receive an explicit callback when retained topic history is lost before this subscription can consume it.booleanunsubscribe(int subscriptionId) Unsubscribe from this topic using the subscription ID.
-
Method Details
-
getDecodeFailureCount
public long getDecodeFailureCount()- Returns:
- count of messages dropped because decoding/type-conversion failed (observability).
-
getListenerFailureCount
public long getListenerFailureCount()- Returns:
- count of messages where the listener threw (observability).
-
getPollFailureCount
public long getPollFailureCount()- Returns:
- count of transient polling failures observed by active subscriptions.
-
getSequenceLossCount
public long getSequenceLossCount()- Returns:
- count of subscriptions stopped because the server reported sequence loss.
-
getLastSequenceLoss
- Returns:
- the most recent sequence-loss exception observed by a subscription, if any.
-
getCurrentPollBackoffMs
public long getCurrentPollBackoffMs()- Returns:
- current capped poll-error backoff in milliseconds, or zero after a healthy poll.
-
publish
Publishes a message to this topic. -
subscribe
-
subscribe
public int subscribe(Consumer<T> listener, Consumer<TopicSequenceLostException> sequenceLossHandler) Subscribe to messages and receive an explicit callback when retained topic history is lost before this subscription can consume it. -
unsubscribe
public boolean unsubscribe(int subscriptionId) Unsubscribe from this topic using the subscription ID. -
closeSubscriptions
public void closeSubscriptions()Tear down every active polling subscription owned by this topic.Invoked by
LoomClient.close()so subscriptions stop spinning promptly when the underlying client is closed, instead of waiting for repeated poll failures to trip theconsecutiveErrorsthreshold. Safe to call more than once (subsequent calls are a no-op oncesubscriptionsis empty).Not intended as a public subscribe/unsubscribe replacement — callers still manage individual subscriptions via
subscribe(Consumer)andunsubscribe(int).- Since:
- 1.4
-
activeSubscriptionCount
public int activeSubscriptionCount()- Returns:
- the number of active subscriptions on this topic (for observability and tests).
-