Class SimpleProtocol

  • All Implemented Interfaces:
    Protocol

    public class SimpleProtocol
    extends java.lang.Object
    implements Protocol
    Author:
    Simon Thoresen Hult
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static interface  SimpleProtocol.PolicyFactory
      Defines a policy factory interface that tests can use to register arbitrary policies with this protocol.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static int MESSAGE  
      static com.yahoo.text.Utf8String NAME  
      static int REPLY  
    • Constructor Summary

      Constructors 
      Constructor Description
      SimpleProtocol()  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void addPolicyFactory​(java.lang.String name, SimpleProtocol.PolicyFactory factory)
      Registers a policy factory with this protocol under a given name.
      RoutingPolicy createPolicy​(java.lang.String name, java.lang.String param)
      Create a policy of the named type with the named param passed to the constructor of that policy.
      Routable decode​(com.yahoo.component.Version version, byte[] data)
      Decodes the protocol specific data into a routable of the correct type.
      byte[] encode​(com.yahoo.component.Version version, Routable routable)
      Encodes the protocol specific data of a routable into a byte array.
      java.lang.String getName()
      Returns a global unique name for this protocol.
      • Methods inherited from class java.lang.Object

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

      • SimpleProtocol

        public SimpleProtocol()
    • Method Detail

      • getName

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

        public RoutingPolicy createPolicy​(java.lang.String name,
                                          java.lang.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.
      • 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​(java.lang.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.