Class Hop
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 Summary
-
Method Summary
Modifier and TypeMethodDescriptionaddDirective
(HopDirective directive) Adds a new directive to this hop.Clears all directives from this hop.boolean
getDirective
(int i) Returns the directive at the given index.boolean
Returns whether or not to ignore the result when routing through this hop.int
Returns the number of directives contained in this hop.getPrefix
(int toNotIncluding) Returns the prefix of this hop's selector to, but not including, the given index.Returns the service name referenced by this hop.getSuffix
(int fromNotIncluding) Returns the suffix of this hop's selector from, but not including, the given index.boolean
Returns whether or not there are any directives contained in this hop.int
hashCode()
boolean
Returns true whether this hop matches another.static Hop
Parses the given string as a single hop.removeDirective
(int i) Removes the directive at the given index.setDirective
(int i, HopDirective directive) Sets the directive at a given index.setIgnoreResult
(boolean ignoreResult) Sets whether or not to ignore the result when routing through this hop.Returns a string representation of this that can be debugged but not parsed.toString()
toString
(int fromIncluding, int toNotIncluding) Returns a string concatenation of a subset of the selector primitives contained in this.
-
Constructor Details
-
Hop
public Hop()Constructs an empty hop. You will need to add directives to the selector to make this usable. -
Hop
Implements the copy constructor.- Parameters:
hop
- The hop to copy.
-
-
Method Details
-
parse
Parses the given string as a single hop. ThetoString()
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
Returns the directive at the given index.- Parameters:
i
- The index of the directive to return.- Returns:
- The item.
-
addDirective
Adds a new directive to this hop.- Parameters:
directive
- The directive to add.- Returns:
- This, to allow chaining.
-
setDirective
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
Removes the directive at the given index.
- Parameters:
i
- The index of the directive to remove.- Returns:
- The removed directive.
-
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
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
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
Returns a string representation of this that can be debugged but not parsed.
- Returns:
- The debug string.
-
toString
-
equals
-
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
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
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
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()
-