Class Hop


  • public class Hop
    extends Object

    Hops are the components of routes. They are instantiated from a HopBlueprint or using the factory method parse(String). A hop is resolved to a recipient, from a set of primitives, either a string primitive that is to be matched verbatim to a service address, or a RoutingPolicy directive.

    Author:
    bratseth
    • Constructor Detail

      • Hop

        public Hop()
        Constructs an empty hop. You will need to add directives to the selector to make this usable.
      • Hop

        public Hop​(Hop hop)
        Implements the copy constructor.
        Parameters:
        hop - The hop to copy.
    • Method Detail

      • parse

        public static Hop parse​(String str)
        Parses the given string as a single hop. The toString() method is compatible with this parser.
        Parameters:
        str - The string to parse.
        Returns:
        A hop that corresponds to the string.
      • hasDirectives

        public boolean hasDirectives()
        Returns whether or not there are any directives contained in this hop.
        Returns:
        True if there is at least one directive.
      • getNumDirectives

        public int getNumDirectives()
        Returns the number of directives contained in this hop.
        Returns:
        The number of directives.
      • getDirective

        public HopDirective getDirective​(int i)
        Returns the directive at the given index.
        Parameters:
        i - The index of the directive to return.
        Returns:
        The item.
      • addDirective

        public Hop addDirective​(HopDirective directive)
        Adds a new directive to this hop.
        Parameters:
        directive - The directive to add.
        Returns:
        This, to allow chaining.
      • setDirective

        public Hop setDirective​(int i,
                                HopDirective directive)
        Sets the directive at a given index.
        Parameters:
        i - The index at which to set the directive.
        directive - The directive to set.
        Returns:
        This, to allow chaining.
      • removeDirective

        public HopDirective removeDirective​(int i)

        Removes the directive at the given index.

        Parameters:
        i - The index of the directive to remove.
        Returns:
        The removed directive.
      • clearDirectives

        public Hop clearDirectives()

        Clears all directives from this hop.

        Returns:
        This, to allow chaining.
      • getIgnoreResult

        public boolean getIgnoreResult()

        Returns whether or not to ignore the result when routing through this hop.

        Returns:
        True to ignore the result.
      • setIgnoreResult

        public Hop setIgnoreResult​(boolean ignoreResult)

        Sets whether or not to ignore the result when routing through this hop.

        Parameters:
        ignoreResult - Whether or not to ignore the result.
        Returns:
        This, to allow chaining.
      • matches

        public boolean matches​(Hop hop)

        Returns true whether this hop matches another. This respects policy directives matching any other.

        Parameters:
        hop - The hop to compare to.
        Returns:
        True if this matches the argument, false otherwise.
      • toDebugString

        public String toDebugString()

        Returns a string representation of this that can be debugged but not parsed.

        Returns:
        The debug string.
      • getServiceName

        public String getServiceName()

        Returns the service name referenced by this hop. This is the concatenation of all selector primitives, but with no ignore-result prefix.

        Returns:
        The service name.
      • toString

        public String toString​(int fromIncluding,
                               int toNotIncluding)

        Returns a string concatenation of a subset of the selector primitives contained in this.

        Parameters:
        fromIncluding - The index of the first primitive to include.
        toNotIncluding - The index after the last primitive to include.
        Returns:
        The string concatenation.
      • getPrefix

        public String getPrefix​(int toNotIncluding)

        Returns the prefix of this hop's selector to, but not including, the given index.

        Parameters:
        toNotIncluding - The index to which to generate prefix.
        Returns:
        The prefix before the index.
      • getSuffix

        public String getSuffix​(int fromNotIncluding)

        Returns the suffix of this hop's selector from, but not including, the given index.

        Parameters:
        fromNotIncluding - The index from which to generate suffix.
        Returns:
        The suffix after the index.
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object