Interface StateRouter<T>

All Known Implementing Classes:
AbstractStateRouter, AppScriptStateRouter, AppStateRouter, ConditionStateRouter, ListenableStateRouter, MeshRuleRouter, MockInvokersSelector, ProviderAppStateRouter, ScriptStateRouter, ServiceStateRouter, StandardMeshRuleRouter, TagStateRouter, TailStateRouter

public interface StateRouter<T>
State Router. (SPI, Prototype, ThreadSafe)

Routing It is recommended to implement StateRouter by extending AbstractStateRouter

Since:
3.0
See Also:
  • Method Summary

    Modifier and Type
    Method
    Description
    Build Router's Current State Snapshot for QoS
    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(BitList, URL, Invocation, boolean, Holder) 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.
    void
    notify(BitList<Invoker<T>> invokers)
    Notify the router the invoker list.
    route(BitList<Invoker<T>> invokers, org.apache.dubbo.common.URL url, Invocation invocation, boolean needToPrintMessage, org.apache.dubbo.common.utils.Holder<RouterSnapshotNode<T>> nodeHolder)
    Filter invokers with current routing rule and only return the invokers that comply with the rule.
    void
    Notify next router node to current router.
    default void
     
  • Method Details

    • getUrl

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

      BitList<Invoker<T>> route(BitList<Invoker<T>> invokers, org.apache.dubbo.common.URL url, Invocation invocation, boolean needToPrintMessage, org.apache.dubbo.common.utils.Holder<RouterSnapshotNode<T>> nodeHolder) throws RpcException
      Filter invokers with current routing rule and only return the invokers that comply with the rule. Caching address lists in BitMap mode improves routing performance.
      Parameters:
      invokers - invoker bit 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
      Since:
      3.0
    • 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(BitList, URL, Invocation, boolean, Holder) 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
    • notify

      void notify(BitList<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(BitList, URL, Invocation, boolean, Holder) gets called. No need to notify next node.
      Parameters:
      invokers - invoker list
    • buildSnapshot

      String buildSnapshot()
      Build Router's Current State Snapshot for QoS
      Returns:
      Current State
    • stop

      default void stop()
    • setNextRouter

      void setNextRouter(StateRouter<T> nextRouter)
      Notify next router node to current router.
      Parameters:
      nextRouter - next router node