Interface Router

All Superinterfaces:
Comparable<Router>
All Known Implementing Classes:
AbstractRouter

public interface Router extends Comparable<Router>
Router. (SPI, Prototype, ThreadSafe)

Routing

See Also:
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final int
     
  • Method Summary

    Modifier and Type
    Method
    Description
    default int
     
    int
    Router's priority, used to sort routers.
    org.apache.dubbo.common.URL
    Get the router url.
    boolean
    To decide whether this router should take effect when none of the invoker can match the router rule, which means the route(List, URL, Invocation) would be empty.
    boolean
    To decide whether this router need to execute every time an RPC comes or should only execute when addresses or rule change.
    default <T> void
    notify(List<Invoker<T>> invokers)
    Notify the router the invoker list.
    default <T> List<Invoker<T>>
    route(List<Invoker<T>> invokers, org.apache.dubbo.common.URL url, Invocation invocation)
    Deprecated.
    default <T> RouterResult<Invoker<T>>
    route(List<Invoker<T>> invokers, org.apache.dubbo.common.URL url, Invocation invocation, boolean needToPrintMessage)
    ** This method can return the state of whether routerChain needed to continue route.
    default void
     
  • Field Details

  • Method Details

    • getUrl

      org.apache.dubbo.common.URL getUrl()
      Get the router url.
      Returns:
      url
    • route

      @Deprecated default <T> List<Invoker<T>> route(List<Invoker<T>> invokers, org.apache.dubbo.common.URL url, Invocation invocation) throws RpcException
      Deprecated.
      Filter invokers with current routing rule and only return the invokers that comply with the rule.
      Parameters:
      invokers - invoker list
      url - refer url
      invocation - invocation
      Returns:
      routed invokers
      Throws:
      RpcException
    • route

      default <T> RouterResult<Invoker<T>> route(List<Invoker<T>> invokers, org.apache.dubbo.common.URL url, Invocation invocation, boolean needToPrintMessage) throws RpcException
      ** This method can return the state of whether routerChain needed to continue route. ** Filter invokers with current routing rule and only return the invokers that comply with the rule.
      Parameters:
      invokers - invoker list
      url - refer url
      invocation - invocation
      needToPrintMessage - whether to print router state. Such as `use router branch a`.
      Returns:
      state with route result
      Throws:
      RpcException
    • notify

      default <T> void notify(List<Invoker<T>> invokers)
      Notify the router the invoker list. Invoker list may change from time to time. This method gives the router a chance to prepare before route(List, URL, Invocation) gets called.
      Type Parameters:
      T - invoker's type
      Parameters:
      invokers - invoker list
    • isRuntime

      boolean isRuntime()
      To decide whether this router need to execute every time an RPC comes or should only execute when addresses or rule change.
      Returns:
      true if the router need to execute every time.
    • isForce

      boolean isForce()
      To decide whether this router should take effect when none of the invoker can match the router rule, which means the route(List, URL, Invocation) would be empty. Most of time, most router implementation would default this value to false.
      Returns:
      true to execute if none of invokers matches the current router
    • getPriority

      int getPriority()
      Router's priority, used to sort routers.
      Returns:
      router's priority
    • stop

      default void stop()
    • compareTo

      default int compareTo(Router o)
      Specified by:
      compareTo in interface Comparable<Router>