Package com.yahoo.messagebus.routing
Class RoutingTableSpec
java.lang.Object
com.yahoo.messagebus.routing.RoutingTableSpec
Along with the
RoutingSpec
, RouteSpec
and HopSpec
, this holds the routing specifications for
all protocols. The only way a client can configure or alter the settings of a message bus instance is through these
classes.
This class contains the spec for a single routing table, which corresponds to exactly one protocol.
- Author:
- Simon Thoresen Hult
-
Constructor Summary
ConstructorDescriptionImplements the copy constructor.RoutingTableSpec
(com.yahoo.text.Utf8String protocol) Creates a new routing table specification for a named protocol.RoutingTableSpec
(String protocol) Creates a new routing table specification for a named protocol.RoutingTableSpec
(String protocol, boolean verify) Creates a new routing table specification for a named protocol. -
Method Summary
Modifier and TypeMethodDescriptionAdds the given hop spec to this.A convenience function to add a new hop to this routing table.Adds a route spec to this.A convenience function to add a new route to this routing table.Clears the list of hop specs contained in this.Clears the list of routes that are contained in this.boolean
getHop
(int i) Returns the hop spec at the given index.int
Returns the number of hops that are contained in this table.int
Returns the number of route specs contained in this.Returns the name of the protocol that this is the routing table for.getRoute
(int i) Returns the route spec at the given index.int
hashCode()
boolean
Returns whether or not there is a named hop spec contained in this.boolean
hasHops()
Returns whether or not there are any hop specs contained in this.boolean
Returns whether or not there is a named route spec contained in this.boolean
Returns whether or not there are any route specs contained in this.removeHop
(int i) Removes the hop spec at the given index.removeRoute
(int i) Removes a route spec at a given index.Sets the hop spec at the given index.Sets the route spec at the given index.void
sort()
Sorts the hops and routes of this table by name.void
toConfig
(StringBuilder cfg, String prefix) Appends the content of this to the given config string builder.toString()
boolean
verify
(ApplicationSpec app, List<String> errors) Verifies the content of this against the given application.
-
Constructor Details
-
RoutingTableSpec
Creates a new routing table specification for a named protocol.- Parameters:
protocol
- The name of the protocol that this belongs to.
-
RoutingTableSpec
public RoutingTableSpec(com.yahoo.text.Utf8String protocol) Creates a new routing table specification for a named protocol.- Parameters:
protocol
- The name of the protocol that this belongs to.
-
RoutingTableSpec
Creates a new routing table specification for a named protocol.- Parameters:
protocol
- The name of the protocol that this belongs to.verify
- Whether or not this should be verified.
-
RoutingTableSpec
Implements the copy constructor.- Parameters:
obj
- The object to copy.
-
-
Method Details
-
getProtocol
Returns the name of the protocol that this is the routing table for.- Returns:
- The protocol name.
-
hasHops
public boolean hasHops()Returns whether or not there are any hop specs contained in this.- Returns:
- True if there is at least one hop.
-
hasHop
Returns whether or not there is a named hop spec contained in this.- Parameters:
hopName
- The hop name to check for.- Returns:
- True if the hop exists.
-
getNumHops
public int getNumHops()Returns the number of hops that are contained in this table.- Returns:
- The number of hops.
-
getHop
Returns the hop spec at the given index.- Parameters:
i
- The index of the hop to return.- Returns:
- The hop at the given position.
-
addHop
Adds the given hop spec to this.- Parameters:
hop
- The hop to add.- Returns:
- This, to allow chaining.
-
setHop
Sets the hop spec at the given index.- Parameters:
i
- The index at which to set the hop.hop
- The hop to set.- Returns:
- This, to allow chaining.
-
removeHop
Removes the hop spec at the given index.- Parameters:
i
- The index of the hop to remove.- Returns:
- The removed hop.
-
clearHops
Clears the list of hop specs contained in this.- Returns:
- This, to allow chaining.
-
hasRoutes
public boolean hasRoutes()Returns whether or not there are any route specs contained in this.- Returns:
- True if there is at least one route.
-
hasRoute
Returns whether or not there is a named route spec contained in this.- Parameters:
routeName
- The hop name to check for.- Returns:
- True if the hop exists.
-
getNumRoutes
public int getNumRoutes()Returns the number of route specs contained in this.- Returns:
- The number of routes.
-
getRoute
Returns the route spec at the given index.- Parameters:
i
- The index of the route to return.- Returns:
- The route at the given index.
-
addRoute
Adds a route spec to this.- Parameters:
route
- The route to add.- Returns:
- This, to allow chaining.
-
setRoute
Sets the route spec at the given index.- Parameters:
i
- The index at which to set the route.route
- The route to set.- Returns:
- This, to allow chaining.
-
removeRoute
Removes a route spec at a given index.- Parameters:
i
- The index of the route to remove.- Returns:
- The removed route.
-
clearRoutes
Clears the list of routes that are contained in this.- Returns:
- This, to allow chaining.
-
addHop
A convenience function to add a new hop to this routing table.- Parameters:
name
- A protocol-unique name for this hop.selector
- A string that represents the selector for this hop.recipients
- A list of recipients for this hop.- Returns:
- This, to allow chaining.
-
addRoute
A convenience function to add a new route to this routing table.- Parameters:
name
- A protocol-unique name for this route.hops
- A list of hops for this route.- Returns:
- This, to allow chaining.
-
verify
Verifies the content of this against the given application.- Parameters:
app
- The application to verify against.errors
- The list of errors found.- Returns:
- True if no errors where found.
-
sort
public void sort()Sorts the hops and routes of this table by name. This is useful for generating a stable config for testing. -
toConfig
Appends the content of this to the given config string builder.- Parameters:
cfg
- The config to add to.prefix
- The prefix to use for each add.
-
toString
-
equals
-
hashCode
public int hashCode()
-