Class PersistRegistry


  • public class PersistRegistry
    extends Object
    A registry of PersistCodec instances for a particular protocol.
    • Constructor Detail

      • PersistRegistry

        public PersistRegistry()
    • Method Detail

      • getCodec

        public <T> PersistCodec<T,​? extends T,​? extends com.google.protobuf.Message> getCodec​(Class<T> type)
        Get the codec for this protocol that encodes a particular type (or subclasses) and decodes to that same type (or a subclass).
        Parameters:
        type - the type to retrieve a codec for
        Returns:
        an appropriate codec for that type, or null if no suitable codec exists
      • getCodec

        public <S,​T extends S> PersistCodec<? super S,​? extends T,​? extends com.google.protobuf.Message> getCodec​(Class<S> upperBound,
                                                                                                                                    Class<T> lowerBound)
        Get the codec for this protocol that encodes instances of a particular type (or subclasses) and decodes to another type (or a subclass).
        Parameters:
        upperBound - the type that the encoder will accept
        lowerBound - the type that the decoder will return
        Returns:
        an appropriate codec for that type, or null if no suitable codec exists
      • registerCodec

        public <S,​T extends S> void registerCodec​(Class<S> upperTypeBound,
                                                        Class<T> lowerTypeBound,
                                                        PersistCodec<S,​T,​?> codec)
        Register a codec. Called by individual protocols. Warning: not threadsafe. Callers should ensure that registration is protected by external synchronization.
        Parameters:
        upperTypeBound - the least-specific type supported by the codec
        lowerTypeBound - the most-specific type supported by the codec
        codec - the codec itself