Interface Topic<T>


public interface Topic<T>
Represents a system-wide topic which can be used as a place to publish and subscribe to messages. The simple operations. Instances of Topic are considered to be lightweight and do not necessairly hold resources on their own, but rather provide a means to open a connection to the underlying topic service. Both the subscribe(Consumer) and getPublisher() methods return types Created by patricktwohig on 7/20/17.
  • Field Details

    • VALID_NAME_PATTERN

      static final Pattern VALID_NAME_PATTERN
  • Method Details

    • subscribe

      Topic.Subscription subscribe(Consumer<T> tConsumer)
      Listens for incoming messages on this Topic.
      Parameters:
      tConsumer - a Consumer<T> that will accept incoming messages.
      Returns:
      a Runnable which can be used to cancel the subscription.
    • subscribeNext

      default Topic.Subscription subscribeNext(Consumer<T> consumer, Consumer<Exception> exceptionConsumer)
      Similar to subscribe(Consumer), this will subscribe to messages. However, this will automatically invoke Topic.Subscription.close() once the first message has been processed. One of either Consumer will be called, at most, once.
      Parameters:
      consumer - the Consumer<T> which will accept the next message
      exceptionConsumer - a Consumer<Exception> instance which will handle possible exceptions invoking Topic.Subscription.close()
      Returns:
      a Topic.Subscription instance. Invoking Topic.Subscription.close() a second time on this is guaranteed to have no ill-effects
    • getPublisher

      Topic.Publisher<T> getPublisher()
      Opens a connection to the underlying topic service and allows for the publication of messages on a particuilar topic.
    • getSubtopicNamed

      Topic<T> getSubtopicNamed(String name)
      Returns a subtopic with the provided name. The sub-topic's name will be appended to this topic's name. Events published to this topic will
      Parameters:
      name -
      Returns:
    • checkValidName

      static String checkValidName(String name)
      Checks if the supplied Topic name is valid.
      Parameters:
      name - the name to check
      Returns:
      the value passed to the function
      Throws:
      IllegalArgumentException - if the name is not valid