Interface RoutableFactory

All Known Implementing Classes:
AbstractRoutableFactory, RoutableFactories60.CreateVisitorMessageFactory, RoutableFactories60.CreateVisitorReplyFactory, RoutableFactories60.DestroyVisitorMessageFactory, RoutableFactories60.DestroyVisitorReplyFactory, RoutableFactories60.DocumentIgnoredReplyFactory, RoutableFactories60.DocumentListMessageFactory, RoutableFactories60.DocumentListReplyFactory, RoutableFactories60.DocumentMessageFactory, RoutableFactories60.DocumentReplyFactory, RoutableFactories60.EmptyBucketsMessageFactory, RoutableFactories60.EmptyBucketsReplyFactory, RoutableFactories60.GetBucketListMessageFactory, RoutableFactories60.GetBucketListReplyFactory, RoutableFactories60.GetBucketStateMessageFactory, RoutableFactories60.GetBucketStateReplyFactory, RoutableFactories60.GetDocumentMessageFactory, RoutableFactories60.GetDocumentReplyFactory, RoutableFactories60.MapVisitorMessageFactory, RoutableFactories60.MapVisitorReplyFactory, RoutableFactories60.PutDocumentMessageFactory, RoutableFactories60.PutDocumentReplyFactory, RoutableFactories60.QueryResultMessageFactory, RoutableFactories60.QueryResultReplyFactory, RoutableFactories60.RemoveDocumentMessageFactory, RoutableFactories60.RemoveDocumentReplyFactory, RoutableFactories60.RemoveLocationMessageFactory, RoutableFactories60.RemoveLocationReplyFactory, RoutableFactories60.StatBucketMessageFactory, RoutableFactories60.StatBucketReplyFactory, RoutableFactories60.UpdateDocumentMessageFactory, RoutableFactories60.UpdateDocumentReplyFactory, RoutableFactories60.VisitorInfoMessageFactory, RoutableFactories60.VisitorInfoReplyFactory, RoutableFactories60.WrongDistributionReplyFactory

public interface RoutableFactory

This interface defines the necessary methods of a routable factory that can be plugged into a DocumentProtocol using the DocumentProtocol.putRoutableFactory(int, RoutableFactory, com.yahoo.component.VersionSpecification) method.

Notice that no routable type is passed to the decode(DocumentDeserializer) method, so you may NOT share a factory across multiple routable types. To share serialization logic between factory use a common superclass or composition with a common serialization utility.

Author:
Simon Thoresen Hult
  • Method Summary

    Modifier and Type
    Method
    Description
    com.yahoo.messagebus.Routable
    decode(com.yahoo.document.serialization.DocumentDeserializer in)
    This method decodes the given byte buffer to a routable.
    default byte[]
    encode(int msgType, com.yahoo.messagebus.Routable obj)
    Encode a message type and object payload to a byte array.
    boolean
    encode(com.yahoo.messagebus.Routable obj, com.yahoo.document.serialization.DocumentSerializer out)
    This method encodes the content of the given routable into a byte buffer that can later be decoded using the decode(DocumentDeserializer) method.
  • Method Details

    • encode

      boolean encode(com.yahoo.messagebus.Routable obj, com.yahoo.document.serialization.DocumentSerializer out)

      This method encodes the content of the given routable into a byte buffer that can later be decoded using the decode(DocumentDeserializer) method.

      Return false to signal failure.

      This method is NOT exception safe.

      Parameters:
      obj - The routable to encode.
      out - The buffer to write into.
      Returns:
      True if the routable could be encoded.
    • encode

      default byte[] encode(int msgType, com.yahoo.messagebus.Routable obj)

      Encode a message type and object payload to a byte array. This is an alternative, optional method to encode(Routable, DocumentSerializer), but which defers all buffer management to the callee. This allows protocol implementations to make more efficient use of memory, as they do not have to deal with DocumentSerializer indirections.

      Implementations must ensure that the first 4 bytes of the returned byte array contain a 32-bit integer (in network order) equal to the provided msgType value.

      Parameters:
      msgType - A positive integer indicating the concrete message type of obj.
      obj - The message to encode.
      Returns:
      A byte buffer encapsulating the message type and the serialized representation of obj, or null if encoding failed.
    • decode

      com.yahoo.messagebus.Routable decode(com.yahoo.document.serialization.DocumentDeserializer in)

      This method decodes the given byte buffer to a routable.

      Return false to signal failure.

      This method is NOT exception safe.

      Parameters:
      in - The buffer to read from.
      Returns:
      The decoded routable.