Class TopicBinding<T extends Trait>


  • public final class TopicBinding<T extends Trait>
    extends java.lang.Object
    Contains computed information about the resolved MQTT topic bindings of an operation.

    Smithy models can contain a number of MQTT topics that are formed by the publish and subscribe traits. Each of these traits resolves to a single MQTT topic.

    This class abstracts away the process of computing the payload of an MQTT operation. Each topic binding provides the following information:

    • The operation in the model that created the binding.
    • The MQTT topic.
    • The payload shape that forms the payload of the topic.
    • The optionally present input structure of the operation, which provides information like topic label bindings.

    @smithy.mqtt#publish topics

    Operations marked with @smithy.mqtt#publish resolve to a single topic that is defined by topic property of the trait.

    subscribe topics

    Operations marked with subscribe resolve to a single topic that is defined by the topic property of the trait.

    Payload resolution

    The payload binding of a topic binding can be resolved to either no payload (e.g., publish operations with no input shape), a structure payload, or a member of a structure. The target of a specific event shape member can be used as a payload in subscribe operations where an event member is marked with the eventPayload trait.
    • Method Detail

      • getOperationMqttTrait

        public static java.util.Optional<? extends Trait> getOperationMqttTrait​(Shape operation)
        Finds the MQTT binding trait associated with an operation.
        Parameters:
        operation - Operation to check.
        Returns:
        Returns the optionally found MQTT binding trait.
      • getMqttTrait

        public T getMqttTrait()
        Gets the trait that formed the binding of the operation to MQTT for this topic.

        The provided trait will be either an instance of PublishTrait or SubscribeTrait.

        Returns:
        Returns the MQTT trait binding.
      • getOperation

        public OperationShape getOperation()
        Gets the operation shape related to the topic bindings.
        Returns:
        Returns the operation that has topic bindings.
      • getTopic

        public Topic getTopic()
        Gets the resolved topic of the binding.
        Returns:
        Returns the resolved topic.
      • getInput

        @Deprecated
        public java.util.Optional<StructureShape> getInput()
        Deprecated.
        Use getInputShape instead.
        Gets the input shape related to this operation.
        Returns:
        Returns the optional input shape.
      • getInputShape

        public StructureShape getInputShape()
        Gets the input shape related to this operation.
        Returns:
        Returns the input shape.
      • getPayloadShape

        public java.util.Optional<Shape> getPayloadShape()
        Gets the payload shape of the topic.

        The payload shape is either a structure for a single-event event stream, or a union for a multi-event event stream.

        Returns:
        Returns the optional payload target.
      • conflictsWith

        public boolean conflictsWith​(TopicBinding<?> other)
        Returns true if the topic binding conflicts with another.

        A topic binding is considered conflicting if both bindings have conflicting topics determined through Topic.conflictsWith(software.amazon.smithy.mqtt.traits.Topic) and the topic bindings utilize a different payload. If both topics do not have a payload then they are not conflicting. If both topics have a payload, but they target the same shape, then they are not conflicting.

        Parameters:
        other - Other topic binding to compare against.
        Returns:
        Returns true if the topic bindings conflict.
      • equals

        public boolean equals​(java.lang.Object o)
        Overrides:
        equals in class java.lang.Object
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object