Class SimpleProtocol

java.lang.Object
com.yahoo.messagebus.test.SimpleProtocol
All Implemented Interfaces:
Protocol

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

    Nested Classes
    Modifier and Type
    Class
    Description
    static interface 
    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 final int
     
    static final com.yahoo.text.Utf8String
     
    static final int
     
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Registers a policy factory with this protocol under a given name.
    createPolicy(String name, String param)
    Create a policy of the named type with the named param passed to the constructor of that policy.
    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.
    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
  • Field Details

  • Constructor Details

    • SimpleProtocol

      public SimpleProtocol()
  • Method Details

    • 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.