Class DefaultIdStrategy


  • public final class DefaultIdStrategy
    extends IdStrategy
    The FQCN(fully qualified class name) will serve as the id (string). Does not need any registration in the user-code (works out-of-the-box). The size of serialized representation may be not very efficient.
    • Field Detail

      • pojoMapping

        final java.util.concurrent.ConcurrentHashMap<java.lang.String,​HasSchema<?>> pojoMapping
      • enumMapping

        final java.util.concurrent.ConcurrentHashMap<java.lang.String,​EnumIO<?>> enumMapping
      • delegateMapping

        final java.util.concurrent.ConcurrentHashMap<java.lang.String,​HasDelegate<?>> delegateMapping
    • Constructor Detail

      • DefaultIdStrategy

        public DefaultIdStrategy()
      • DefaultIdStrategy

        public DefaultIdStrategy​(IdStrategy primaryGroup,
                                 int groupId)
      • DefaultIdStrategy

        public DefaultIdStrategy​(int flags)
      • DefaultIdStrategy

        public DefaultIdStrategy​(int flags,
                                 IdStrategy primaryGroup,
                                 int groupId)
    • Method Detail

      • registerPojo

        public <T> boolean registerPojo​(java.lang.Class<T> typeClass,
                                        Schema<T> schema)
        Registers a pojo. Returns true if registration is successful or if the same exact schema was previously registered. Used by RuntimeSchema.register(Class, Schema).
      • registerPojo

        public <T> boolean registerPojo​(java.lang.Class<T> typeClass)
        Registers a pojo. Returns true if registration is successful or if the same exact schema was previously registered.
      • registerEnum

        public <T extends java.lang.Enum<T>> boolean registerEnum​(java.lang.Class<T> enumClass)
        Registers an enum. Returns true if registration is successful.
      • registerDelegate

        public <T> boolean registerDelegate​(Delegate<T> delegate)
        Registers a delegate. Returns true if registration is successful.
      • registerDelegate

        public <T> boolean registerDelegate​(java.lang.String className,
                                            Delegate<T> delegate)
        Registers a delegate by specifying the class name. Returns true if registration is successful.
      • registerCollection

        public boolean registerCollection​(CollectionSchema.MessageFactory factory)
        Registers a collection. Returns true if registration is successful.
      • registerMap

        public boolean registerMap​(MapSchema.MessageFactory factory)
        Registers a map. Returns true if registration is successful.
      • isDelegateRegistered

        public boolean isDelegateRegistered​(java.lang.Class<?> typeClass)
        Description copied from class: IdStrategy
        Returns true if there is a Delegate explicitly registered for the typeClass.
        Specified by:
        isDelegateRegistered in class IdStrategy
      • isRegistered

        public boolean isRegistered​(java.lang.Class<?> typeClass)
        Description copied from class: IdStrategy
        Returns true if the typeClass is explicitly registered.
        Specified by:
        isRegistered in class IdStrategy
      • getSchemaWrapper

        private <T> HasSchema<T> getSchemaWrapper​(java.lang.String className,
                                                  boolean load)
      • getSchemaWrapper

        public <T> HasSchema<T> getSchemaWrapper​(java.lang.Class<T> typeClass,
                                                 boolean create)
        Description copied from class: IdStrategy
        Returns the schema wrapper. The caller is responsible that the typeClass is a pojo (e.g not an enum/array/etc).
        Specified by:
        getSchemaWrapper in class IdStrategy
      • getEnumIO

        private EnumIO<? extends java.lang.Enum<?>> getEnumIO​(java.lang.String className,
                                                              boolean load)
      • getEnumIO

        protected EnumIO<? extends java.lang.Enum<?>> getEnumIO​(java.lang.Class<?> enumClass)
        Description copied from class: IdStrategy
        Returns the EnumIO. The callers (internal field factories) are responsible that the class provided is an enum class.
        Specified by:
        getEnumIO in class IdStrategy
      • writeCollectionIdTo

        protected void writeCollectionIdTo​(Output output,
                                           int fieldNumber,
                                           java.lang.Class<?> clazz)
                                    throws java.io.IOException
        Specified by:
        writeCollectionIdTo in class IdStrategy
        Throws:
        java.io.IOException
      • transferCollectionId

        protected void transferCollectionId​(Input input,
                                            Output output,
                                            int fieldNumber)
                                     throws java.io.IOException
        Specified by:
        transferCollectionId in class IdStrategy
        Throws:
        java.io.IOException
      • writeMapIdTo

        protected void writeMapIdTo​(Output output,
                                    int fieldNumber,
                                    java.lang.Class<?> clazz)
                             throws java.io.IOException
        Specified by:
        writeMapIdTo in class IdStrategy
        Throws:
        java.io.IOException
      • transferMapId

        protected void transferMapId​(Input input,
                                     Output output,
                                     int fieldNumber)
                              throws java.io.IOException
        Specified by:
        transferMapId in class IdStrategy
        Throws:
        java.io.IOException
      • writeEnumIdTo

        protected void writeEnumIdTo​(Output output,
                                     int fieldNumber,
                                     java.lang.Class<?> clazz)
                              throws java.io.IOException
        Specified by:
        writeEnumIdTo in class IdStrategy
        Throws:
        java.io.IOException
      • transferEnumId

        protected void transferEnumId​(Input input,
                                      Output output,
                                      int fieldNumber)
                               throws java.io.IOException
        Specified by:
        transferEnumId in class IdStrategy
        Throws:
        java.io.IOException
      • tryWriteDelegateIdTo

        protected <T> HasDelegate<T> tryWriteDelegateIdTo​(Output output,
                                                          int fieldNumber,
                                                          java.lang.Class<T> clazz)
                                                   throws java.io.IOException
        Description copied from class: IdStrategy
        If this method returns null, the clazz was not registered as a delegate.
        Specified by:
        tryWriteDelegateIdTo in class IdStrategy
        Throws:
        java.io.IOException
      • tryWritePojoIdTo

        protected <T> HasSchema<T> tryWritePojoIdTo​(Output output,
                                                    int fieldNumber,
                                                    java.lang.Class<T> clazz,
                                                    boolean registered)
                                             throws java.io.IOException
        Specified by:
        tryWritePojoIdTo in class IdStrategy
        Throws:
        java.io.IOException
      • writePojoIdTo

        protected <T> HasSchema<T> writePojoIdTo​(Output output,
                                                 int fieldNumber,
                                                 java.lang.Class<T> clazz)
                                          throws java.io.IOException
        Specified by:
        writePojoIdTo in class IdStrategy
        Throws:
        java.io.IOException
      • resolvePojoFrom

        protected <T> HasSchema<T> resolvePojoFrom​(Input input,
                                                   int fieldNumber)
                                            throws java.io.IOException
        Specified by:
        resolvePojoFrom in class IdStrategy
        Throws:
        java.io.IOException
      • writeMessageIdTo

        protected <T> Schema<T> writeMessageIdTo​(Output output,
                                                 int fieldNumber,
                                                 Message<T> message)
                                          throws java.io.IOException
        Specified by:
        writeMessageIdTo in class IdStrategy
        Throws:
        java.io.IOException
      • writeArrayIdTo

        protected void writeArrayIdTo​(Output output,
                                      java.lang.Class<?> componentType)
                               throws java.io.IOException
        Specified by:
        writeArrayIdTo in class IdStrategy
        Throws:
        java.io.IOException
      • transferArrayId

        protected void transferArrayId​(Input input,
                                       Output output,
                                       int fieldNumber,
                                       boolean mapped)
                                throws java.io.IOException
        Specified by:
        transferArrayId in class IdStrategy
        Throws:
        java.io.IOException
      • resolveArrayComponentTypeFrom

        protected java.lang.Class<?> resolveArrayComponentTypeFrom​(Input input,
                                                                   boolean mapped)
                                                            throws java.io.IOException
        Specified by:
        resolveArrayComponentTypeFrom in class IdStrategy
        Throws:
        java.io.IOException
      • resolveClass

        static java.lang.Class<?> resolveClass​(java.lang.String className)
      • writeClassIdTo

        protected void writeClassIdTo​(Output output,
                                      java.lang.Class<?> componentType,
                                      boolean array)
                               throws java.io.IOException
        Specified by:
        writeClassIdTo in class IdStrategy
        Throws:
        java.io.IOException
      • transferClassId

        protected void transferClassId​(Input input,
                                       Output output,
                                       int fieldNumber,
                                       boolean mapped,
                                       boolean array)
                                throws java.io.IOException
        Specified by:
        transferClassId in class IdStrategy
        Throws:
        java.io.IOException
      • resolveClassFrom

        protected java.lang.Class<?> resolveClassFrom​(Input input,
                                                      boolean mapped,
                                                      boolean array)
                                               throws java.io.IOException
        Specified by:
        resolveClassFrom in class IdStrategy
        Throws:
        java.io.IOException