Class LoomTopic<T>

java.lang.Object
com.loomcache.client.LoomTopic<T>
Type Parameters:
T - the type of messages published to the topic

public final class LoomTopic<T> extends Object
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 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

      public @Nullable TopicSequenceLostException 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

      public void publish(T message)
      Publishes a message to this topic.
    • subscribe

      public int subscribe(Consumer<T> listener)
      Subscribe to messages on this topic using polling.
    • 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 the consecutiveErrors threshold. Safe to call more than once (subsequent calls are a no-op once subscriptions is empty).

      Not intended as a public subscribe/unsubscribe replacement — callers still manage individual subscriptions via subscribe(Consumer) and unsubscribe(int).

      Since:
      1.4
    • activeSubscriptionCount

      public int activeSubscriptionCount()
      Returns:
      the number of active subscriptions on this topic (for observability and tests).