Class RoutingTableSpec

java.lang.Object
com.yahoo.messagebus.routing.RoutingTableSpec

public class RoutingTableSpec extends Object
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 Details

    • RoutingTableSpec

      public RoutingTableSpec(String protocol)
      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

      public RoutingTableSpec(String protocol, boolean verify)
      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

      public RoutingTableSpec(RoutingTableSpec obj)
      Implements the copy constructor.
      Parameters:
      obj - The object to copy.
  • Method Details

    • getProtocol

      public String 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

      public boolean hasHop(String hopName)
      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

      public HopSpec getHop(int i)
      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

      public RoutingTableSpec addHop(HopSpec hop)
      Adds the given hop spec to this.
      Parameters:
      hop - The hop to add.
      Returns:
      This, to allow chaining.
    • setHop

      public RoutingTableSpec setHop(int i, HopSpec hop)
      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

      public HopSpec removeHop(int i)
      Removes the hop spec at the given index.
      Parameters:
      i - The index of the hop to remove.
      Returns:
      The removed hop.
    • clearHops

      public RoutingTableSpec 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

      public boolean hasRoute(String routeName)
      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

      public RouteSpec getRoute(int i)
      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

      public RoutingTableSpec addRoute(RouteSpec route)
      Adds a route spec to this.
      Parameters:
      route - The route to add.
      Returns:
      This, to allow chaining.
    • setRoute

      public RoutingTableSpec setRoute(int i, RouteSpec route)
      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

      public RouteSpec removeRoute(int i)
      Removes a route spec at a given index.
      Parameters:
      i - The index of the route to remove.
      Returns:
      The removed route.
    • clearRoutes

      public RoutingTableSpec clearRoutes()
      Clears the list of routes that are contained in this.
      Returns:
      This, to allow chaining.
    • addHop

      public RoutingTableSpec addHop(String name, String selector, List<String> recipients)
      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

      public RoutingTableSpec addRoute(String name, List<String> hops)
      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

      public boolean verify(ApplicationSpec app, List<String> errors)
      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

      public void toConfig(StringBuilder cfg, String prefix)
      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

      public String toString()
      Overrides:
      toString in class Object
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object