Class Hop
- java.lang.Object
-
- com.yahoo.messagebus.routing.Hop
-
public class Hop extends java.lang.Object
Hops are the components of routes. They are instantiated from a
HopBlueprint
or using the factory methodparse(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 aRoutingPolicy
directive.- Author:
- bratseth
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description Hop
addDirective(HopDirective directive)
Adds a new directive to this hop.Hop
clearDirectives()
Clears all directives from this hop.boolean
equals(java.lang.Object obj)
HopDirective
getDirective(int i)
Returns the directive at the given index.boolean
getIgnoreResult()
Returns whether or not to ignore the result when routing through this hop.int
getNumDirectives()
Returns the number of directives contained in this hop.java.lang.String
getPrefix(int toNotIncluding)
Returns the prefix of this hop's selector to, but not including, the given index.java.lang.String
getServiceName()
Returns the service name referenced by this hop.java.lang.String
getSuffix(int fromNotIncluding)
Returns the suffix of this hop's selector from, but not including, the given index.boolean
hasDirectives()
Returns whether or not there are any directives contained in this hop.int
hashCode()
boolean
matches(Hop hop)
Returns true whether this hop matches another.static Hop
parse(java.lang.String str)
Parses the given string as a single hop.HopDirective
removeDirective(int i)
Removes the directive at the given index.Hop
setDirective(int i, HopDirective directive)
Sets the directive at a given index.Hop
setIgnoreResult(boolean ignoreResult)
Sets whether or not to ignore the result when routing through this hop.java.lang.String
toDebugString()
Returns a string representation of this that can be debugged but not parsed.java.lang.String
toString()
java.lang.String
toString(int fromIncluding, int toNotIncluding)
Returns a string concatenation of a subset of the selector primitives contained in this.
-
-
-
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(java.lang.String str)
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
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 java.lang.String toDebugString()
Returns a string representation of this that can be debugged but not parsed.
- Returns:
- The debug string.
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equals
in classjava.lang.Object
-
getServiceName
public java.lang.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 java.lang.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 java.lang.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 java.lang.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 classjava.lang.Object
-
-