Class SimpleProtocol

  • All Implemented Interfaces:
    Protocol

    public class SimpleProtocol
    extends Object
    implements Protocol
    Author:
    Simon Thoresen Hult
    • Constructor Detail

      • SimpleProtocol

        public SimpleProtocol()
    • Method Detail

      • getName

        public String getName()
        Description copied from interface: Protocol
        Returns a global unique name for this protocol.
        Specified by:
        getName in interface Protocol
      • createPolicy

        public RoutingPolicy createPolicy​(String name,
                                          String param)
        Description copied from interface: Protocol
        Create a policy of the named type with the named param passed to the constructor of that policy.
        Specified by:
        createPolicy in interface Protocol
        Parameters:
        name - the name of the policy to create
        param - the parameter to that policy's constructor
        Returns:
        the created policy
      • decode

        public Routable decode​(com.yahoo.component.Version version,
                               byte[] data)
        Description copied from interface: Protocol
        Decodes the protocol specific data into a routable of the correct type.
        Specified by:
        decode in interface Protocol
        Parameters:
        version - the version of the serialized routable
        data - the payload to decode from
        Returns:
        the decoded routable, or null if it could not be decoded
      • encode

        public byte[] encode​(com.yahoo.component.Version version,
                             Routable routable)
        Description copied from interface: Protocol
        Encodes the protocol specific data of a routable into a byte array.
        Specified by:
        encode in interface Protocol
        Parameters:
        version - the version to encode for
        routable - the routable to encode
        Returns:
        the encoded data
      • addPolicyFactory

        public void addPolicyFactory​(String name,
                                     SimpleProtocol.PolicyFactory factory)
        Registers a policy factory with this protocol under a given name. Whenever a policy is requested that matches this name, the factory is invoked.
        Parameters:
        name - The name of the policy.
        factory - The policy factory.