Class ProtocolRepository


  • public class ProtocolRepository
    extends java.lang.Object
    Implements a thread-safe repository for protocols and their routing policies. This manages an internal cache of routing policies so that similarly referenced policy directives share the same instance of a policy.
    Author:
    Simon Thoresen Hult
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void clearPolicyCache()
      Clears the internal cache of routing policies.
      Protocol getProtocol​(java.lang.String name)
      Returns the protocol whose name matches the given argument.
      RoutingPolicy getRoutingPolicy​(com.yahoo.text.Utf8String protocolName, java.lang.String policyName, java.lang.String policyParam)  
      RoutingPolicy getRoutingPolicy​(java.lang.String protocolName, java.lang.String policyName, java.lang.String policyParam)
      Creates and returns a routing policy that matches the given arguments.
      boolean hasProtocol​(java.lang.String name)
      Returns whether or not this repository contains a protocol with the given name.
      void putProtocol​(Protocol protocol)
      Registers a protocol with this repository.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • ProtocolRepository

        public ProtocolRepository()
    • Method Detail

      • putProtocol

        public void putProtocol​(Protocol protocol)
        Registers a protocol with this repository. This will overwrite any protocol that was registered earlier that has the same name. If this method detects a protocol replacement, it will clear its internal routing policy cache.
        Parameters:
        protocol - The protocol to register.
      • hasProtocol

        public boolean hasProtocol​(java.lang.String name)
        Returns whether or not this repository contains a protocol with the given name. Given the concurrent nature of things, one should not invoke this method followed by getProtocol(String) and expect the return value to be non-null. Instead just get the protocol and compare it to null.
        Parameters:
        name - The name to check for.
        Returns:
        True if the named protocol is registered.
      • getProtocol

        public Protocol getProtocol​(java.lang.String name)
        Returns the protocol whose name matches the given argument. This method will return null if no such protocol has been registered.
        Parameters:
        name - The name of the protocol to return.
        Returns:
        The protocol registered, or null.
      • getRoutingPolicy

        public RoutingPolicy getRoutingPolicy​(java.lang.String protocolName,
                                              java.lang.String policyName,
                                              java.lang.String policyParam)
        Creates and returns a routing policy that matches the given arguments. If a routing policy has been created previously using the exact same parameters, this method will returned that cached instance instead of creating another. Not that when you replace a protocol using putProtocol(Protocol) the policy cache is cleared.
        Parameters:
        protocolName - The name of the protocol whose routing policy to create.
        policyName - The name of the routing policy to create.
        policyParam - The parameter to pass to the routing policy constructor.
        Returns:
        The created routing policy.
      • getRoutingPolicy

        public final RoutingPolicy getRoutingPolicy​(com.yahoo.text.Utf8String protocolName,
                                                    java.lang.String policyName,
                                                    java.lang.String policyParam)
      • clearPolicyCache

        public void clearPolicyCache()
        Clears the internal cache of routing policies.