Package com.yahoo.messagebus
Class ProtocolRepository
java.lang.Object
com.yahoo.messagebus.ProtocolRepository
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
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidClears the internal cache of routing policies.getProtocol(String name) Returns the protocol whose name matches the given argument.final RoutingPolicygetRoutingPolicy(com.yahoo.text.Utf8String protocolName, String policyName, String policyParam) getRoutingPolicy(String protocolName, String policyName, String policyParam) Creates and returns a routing policy that matches the given arguments.booleanhasProtocol(String name) Returns whether or not this repository contains a protocol with the given name.voidputProtocol(Protocol protocol) Registers a protocol with this repository.
-
Constructor Details
-
ProtocolRepository
public ProtocolRepository()
-
-
Method Details
-
putProtocol
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
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 bygetProtocol(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
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
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 usingputProtocol(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, String policyName, String policyParam) -
clearPolicyCache
public void clearPolicyCache()Clears the internal cache of routing policies.
-