Package io.protostuff.runtime
Class IncrementalIdStrategy
java.lang.Object
io.protostuff.runtime.IdStrategy
io.protostuff.runtime.NumericIdStrategy
io.protostuff.runtime.IncrementalIdStrategy
The ids are generated (incremental) on the fly and you can optionally register classes by reserving the first x ids
via
IncrementalIdStrategy.Registry
. To minimize overhead, ArrayList
s are used for the id mapping rather than
ConcurrentHashMap
. This optimization has a disadvantage though. Ids will not be unlimited. You'll have to
specificy a max id for the 4 types (pojo, enum, collection, map)-
Nested Class Summary
Nested ClassesModifier and TypeClassDescription(package private) static class
static class
To useIncrementalIdStrategy
without registering anything, set the system property: "-Dprotostuff.runtime.id_strategy_factory=io.protostuff.runtime.IncrementalIdStrategy$Factory"(package private) static final class
(package private) static class
(package private) static final class
static class
This Registry is only way to register your pojos/enums/collections/maps/delegates.(package private) static final class
(package private) static final class
(package private) static final class
Nested classes/interfaces inherited from class io.protostuff.runtime.NumericIdStrategy
NumericIdStrategy.RegisteredDelegate<T>
Nested classes/interfaces inherited from class io.protostuff.runtime.IdStrategy
IdStrategy.UnknownTypeException, IdStrategy.Wrapper
-
Field Summary
FieldsModifier and TypeFieldDescription(package private) final AtomicInteger
(package private) final int
(package private) final ConcurrentHashMap
<Class<?>, IncrementalIdStrategy.RuntimeCollectionFactory> (package private) final ArrayList
<IncrementalIdStrategy.RuntimeCollectionFactory> (package private) final IdentityHashMap
<Class<?>, NumericIdStrategy.RegisteredDelegate<?>> (package private) final ArrayList
<NumericIdStrategy.RegisteredDelegate<?>> (package private) final AtomicInteger
(package private) final int
(package private) final ConcurrentHashMap
<Class<?>, IncrementalIdStrategy.RuntimeEnumIO> (package private) final ArrayList
<IncrementalIdStrategy.RuntimeEnumIO> (package private) final AtomicInteger
(package private) final int
(package private) final ConcurrentHashMap
<Class<?>, IncrementalIdStrategy.RuntimeMapFactory> (package private) final ArrayList
<IncrementalIdStrategy.RuntimeMapFactory> (package private) final AtomicInteger
(package private) final int
(package private) final ConcurrentHashMap
<Class<?>, IncrementalIdStrategy.BaseHS<?>> (package private) final ArrayList
<IncrementalIdStrategy.BaseHS<?>> Fields inherited from class io.protostuff.runtime.NumericIdStrategy
CID_BIGDECIMAL, CID_BIGINTEGER, CID_BOOL, CID_BYTE, CID_BYTE_ARRAY, CID_BYTES, CID_CHAR, CID_CLASS, CID_COLLECTION, CID_DATE, CID_DELEGATE, CID_DOUBLE, CID_ENUM, CID_ENUM_MAP, CID_ENUM_SET, CID_FLOAT, CID_INT32, CID_INT64, CID_MAP, CID_OBJECT, CID_POJO, CID_SHORT, CID_STRING
Fields inherited from class io.protostuff.runtime.IdStrategy
ARRAY_BIGDECIMAL_SCHEMA, ARRAY_BIGINTEGER_SCHEMA, ARRAY_BOOL_BOXED_SCHEMA, ARRAY_BOOL_DERIVED_SCHEMA, ARRAY_BOOL_PRIMITIVE_SCHEMA, ARRAY_BYTEARRAY_SCHEMA, ARRAY_BYTESTRING_SCHEMA, ARRAY_CHAR_BOXED_SCHEMA, ARRAY_CHAR_DERIVED_SCHEMA, ARRAY_CHAR_PRIMITIVE_SCHEMA, ARRAY_DATE_SCHEMA, ARRAY_DOUBLE_BOXED_SCHEMA, ARRAY_DOUBLE_DERIVED_SCHEMA, ARRAY_DOUBLE_PRIMITIVE_SCHEMA, ARRAY_ELEMENT_SCHEMA, ARRAY_FLOAT_BOXED_SCHEMA, ARRAY_FLOAT_DERIVED_SCHEMA, ARRAY_FLOAT_PRIMITIVE_SCHEMA, ARRAY_INT32_BOXED_SCHEMA, ARRAY_INT32_DERIVED_SCHEMA, ARRAY_INT32_PRIMITIVE_SCHEMA, ARRAY_INT64_BOXED_SCHEMA, ARRAY_INT64_DERIVED_SCHEMA, ARRAY_INT64_PRIMITIVE_SCHEMA, ARRAY_PIPE_SCHEMA, ARRAY_SCHEMA, ARRAY_SHORT_BOXED_SCHEMA, ARRAY_SHORT_DERIVED_SCHEMA, ARRAY_SHORT_PRIMITIVE_SCHEMA, ARRAY_STRING_SCHEMA, AUTO_LOAD_POLYMORPHIC_CLASSES, CLASS_ELEMENT_SCHEMA, CLASS_PIPE_SCHEMA, CLASS_SCHEMA, COLLECTION_PIPE_SCHEMA, COLLECTION_SCHEMA, COLLECTION_SCHEMA_ON_REPEATED_FIELDS, DEFAULT_FLAGS, DYNAMIC_VALUE_PIPE_SCHEMA, DYNAMIC_VALUE_SCHEMA, ENTRY_PIPE_SCHEMA, ENTRY_SCHEMA, ENUMS_BY_NAME, flags, groupId, MAP_PIPE_SCHEMA, MAP_SCHEMA, MORPH_COLLECTION_INTERFACES, MORPH_MAP_INTERFACES, MORPH_NON_FINAL_POJOS, NUMBER_ELEMENT_SCHEMA, OBJECT_ELEMENT_SCHEMA, OBJECT_PIPE_SCHEMA, OBJECT_SCHEMA, POJO_SCHEMA_ON_COLLECTION_FIELDS, POJO_SCHEMA_ON_MAP_FIELDS, POLYMORPHIC_COLLECTION_PIPE_SCHEMA, POLYMORPHIC_COLLECTION_SCHEMA, POLYMORPHIC_ENUM_ELEMENT_SCHEMA, POLYMORPHIC_MAP_PIPE_SCHEMA, POLYMORPHIC_MAP_SCHEMA, POLYMORPHIC_POJO_ELEMENT_SCHEMA, POLYMORPHIC_THROWABLE_ELEMENT_SCHEMA, PRESERVE_NULL_ELEMENTS, preserveNull, primaryGroup
-
Constructor Summary
ConstructorsConstructorDescriptionIncrementalIdStrategy
(int collectionIdMax, int collectionIdStart, int mapIdMax, int mapIdStart, int enumIdMax, int enumIdStart, int pojoIdMax, int pojoIdStart) IncrementalIdStrategy
(int flags, IdStrategy primaryGroup, int groupId, int collectionIdMax, int collectionIdStart, int mapIdMax, int mapIdStart, int enumIdMax, int enumIdStart, int pojoIdMax, int pojoIdStart) -
Method Summary
Modifier and TypeMethodDescriptionprotected Class
<?> collectionClass
(int id) protected Class
<?> delegateClass
(int id) protected Class
<?> enumClass
(int id) private <T> IncrementalIdStrategy.BaseHS
<T> protected CollectionSchema.MessageFactory
getCollectionFactory
(Class<?> clazz) Returns theCollectionSchema.MessageFactory
.<T> Delegate
<T> getDelegate
(Class<? super T> typeClass) Returns thedelegate
.<T> HasDelegate
<T> getDelegateWrapper
(Class<? super T> typeClass) Returns thedelegate
.protected int
Returns theEnumIO
.protected int
protected MapSchema.MessageFactory
getMapFactory
(Class<?> clazz) Returns theMapSchema.MessageFactory
.protected NumericIdStrategy.RegisteredDelegate
<?> getRegisteredDelegate
(Class<?> clazz) getRuntimeCollectionFactory
(Class<?> clazz) getRuntimeEnumIO
(Class<?> enumClass) getRuntimeMapFactory
(Class<?> clazz) <T> HasSchema
<T> getSchemaWrapper
(Class<T> typeClass, boolean create) Returns theschema wrapper
.boolean
isDelegateRegistered
(Class<?> typeClass) Returns true if there is aDelegate
explicitly registered for thetypeClass
.boolean
isRegistered
(Class<?> typeClass) Returns true if thetypeClass
is explicitly registered.protected Class
<?> mapClass
(int id) protected Class
<?> pojoClass
(int id) protected CollectionSchema.MessageFactory
resolveCollectionFrom
(Input input) protected <T> HasDelegate
<T> resolveDelegateFrom
(Input input) protected EnumIO
<?> resolveEnumFrom
(Input input) protected MapSchema.MessageFactory
resolveMapFrom
(Input input) protected <T> HasSchema
<T> resolvePojoFrom
(Input input, int fieldNumber) protected void
transferCollectionId
(Input input, Output output, int fieldNumber) protected <T> HasDelegate
<T> transferDelegateId
(Input input, Output output, int fieldNumber) protected void
transferEnumId
(Input input, Output output, int fieldNumber) protected void
transferMapId
(Input input, Output output, int fieldNumber) protected <T> HasSchema
<T> transferPojoId
(Input input, Output output, int fieldNumber) protected <T> HasDelegate
<T> tryWriteDelegateIdTo
(Output output, int fieldNumber, Class<T> clazz) If this method returns null, the clazz was not registered as a delegate.protected <T> HasSchema
<T> tryWritePojoIdTo
(Output output, int fieldNumber, Class<T> clazz, boolean registered) protected void
writeCollectionIdTo
(Output output, int fieldNumber, Class<?> clazz) protected void
writeEnumIdTo
(Output output, int fieldNumber, Class<?> clazz) protected void
writeMapIdTo
(Output output, int fieldNumber, Class<?> clazz) protected <T> Schema
<T> writeMessageIdTo
(Output output, int fieldNumber, Message<T> message) protected <T> HasSchema
<T> writePojoIdTo
(Output output, int fieldNumber, Class<T> clazz) Methods inherited from class io.protostuff.runtime.NumericIdStrategy
grow, newList, resolveArrayComponentTypeFrom, resolveClassFrom, transferArrayId, transferClassId, writeArrayIdTo, writeClassIdTo
Methods inherited from class io.protostuff.runtime.IdStrategy
createMessageInstance, newSchema
-
Field Details
-
collectionMapping
-
collections
-
mapMapping
-
maps
-
enumMapping
-
enums
-
pojoMapping
-
pojos
-
delegateMapping
-
delegates
-
pojoId
-
enumId
-
collectionId
-
mapId
-
pojoIdStart
final int pojoIdStart -
enumIdStart
final int enumIdStart -
collectionIdStart
final int collectionIdStart -
mapIdStart
final int mapIdStart
-
-
Constructor Details
-
IncrementalIdStrategy
public IncrementalIdStrategy(int collectionIdMax, int collectionIdStart, int mapIdMax, int mapIdStart, int enumIdMax, int enumIdStart, int pojoIdMax, int pojoIdStart) -
IncrementalIdStrategy
public IncrementalIdStrategy(int flags, IdStrategy primaryGroup, int groupId, int collectionIdMax, int collectionIdStart, int mapIdMax, int mapIdStart, int enumIdMax, int enumIdStart, int pojoIdMax, int pojoIdStart)
-
-
Method Details
-
isRegistered
Description copied from class:IdStrategy
Returns true if thetypeClass
is explicitly registered.- Specified by:
isRegistered
in classIdStrategy
-
getBaseHS
-
getSchemaWrapper
Description copied from class:IdStrategy
Returns theschema wrapper
. The caller is responsible that the typeClass is a pojo (e.g not an enum/array/etc).- Specified by:
getSchemaWrapper
in classIdStrategy
-
getRuntimeEnumIO
-
getEnumIO
Description copied from class:IdStrategy
Returns theEnumIO
. The callers (internal field factories) are responsible that the class provided is an enum class.- Specified by:
getEnumIO
in classIdStrategy
-
getRuntimeCollectionFactory
-
getCollectionFactory
Description copied from class:IdStrategy
Returns theCollectionSchema.MessageFactory
. The callers (internal field factories) are responsible that the class provided implementsCollection
.- Specified by:
getCollectionFactory
in classIdStrategy
-
getRuntimeMapFactory
-
getMapFactory
Description copied from class:IdStrategy
Returns theMapSchema.MessageFactory
. The callers (internal field factories}) are responsible that the class provided implementsMap
.- Specified by:
getMapFactory
in classIdStrategy
-
writeCollectionIdTo
protected void writeCollectionIdTo(Output output, int fieldNumber, Class<?> clazz) throws IOException - Specified by:
writeCollectionIdTo
in classIdStrategy
- Throws:
IOException
-
transferCollectionId
- Specified by:
transferCollectionId
in classIdStrategy
- Throws:
IOException
-
resolveCollectionFrom
- Specified by:
resolveCollectionFrom
in classIdStrategy
- Throws:
IOException
-
writeMapIdTo
- Specified by:
writeMapIdTo
in classIdStrategy
- Throws:
IOException
-
transferMapId
- Specified by:
transferMapId
in classIdStrategy
- Throws:
IOException
-
resolveMapFrom
- Specified by:
resolveMapFrom
in classIdStrategy
- Throws:
IOException
-
writeEnumIdTo
- Specified by:
writeEnumIdTo
in classIdStrategy
- Throws:
IOException
-
transferEnumId
- Specified by:
transferEnumId
in classIdStrategy
- Throws:
IOException
-
resolveEnumFrom
- Specified by:
resolveEnumFrom
in classIdStrategy
- Throws:
IOException
-
isDelegateRegistered
Description copied from class:IdStrategy
Returns true if there is aDelegate
explicitly registered for thetypeClass
.- Specified by:
isDelegateRegistered
in classIdStrategy
-
getDelegate
Description copied from class:IdStrategy
Returns thedelegate
.- Specified by:
getDelegate
in classIdStrategy
-
getDelegateWrapper
Description copied from class:IdStrategy
Returns thedelegate
.- Specified by:
getDelegateWrapper
in classIdStrategy
-
tryWriteDelegateIdTo
protected <T> HasDelegate<T> tryWriteDelegateIdTo(Output output, int fieldNumber, Class<T> clazz) throws IOException Description copied from class:IdStrategy
If this method returns null, the clazz was not registered as a delegate.- Specified by:
tryWriteDelegateIdTo
in classIdStrategy
- Throws:
IOException
-
transferDelegateId
protected <T> HasDelegate<T> transferDelegateId(Input input, Output output, int fieldNumber) throws IOException - Specified by:
transferDelegateId
in classIdStrategy
- Throws:
IOException
-
resolveDelegateFrom
- Specified by:
resolveDelegateFrom
in classIdStrategy
- Throws:
IOException
-
tryWritePojoIdTo
protected <T> HasSchema<T> tryWritePojoIdTo(Output output, int fieldNumber, Class<T> clazz, boolean registered) throws IOException - Specified by:
tryWritePojoIdTo
in classIdStrategy
- Throws:
IOException
-
writePojoIdTo
protected <T> HasSchema<T> writePojoIdTo(Output output, int fieldNumber, Class<T> clazz) throws IOException - Specified by:
writePojoIdTo
in classIdStrategy
- Throws:
IOException
-
transferPojoId
protected <T> HasSchema<T> transferPojoId(Input input, Output output, int fieldNumber) throws IOException - Specified by:
transferPojoId
in classIdStrategy
- Throws:
IOException
-
resolvePojoFrom
- Specified by:
resolvePojoFrom
in classIdStrategy
- Throws:
IOException
-
writeMessageIdTo
protected <T> Schema<T> writeMessageIdTo(Output output, int fieldNumber, Message<T> message) throws IOException - Specified by:
writeMessageIdTo
in classIdStrategy
- Throws:
IOException
-
collectionClass
- Specified by:
collectionClass
in classNumericIdStrategy
-
mapClass
- Specified by:
mapClass
in classNumericIdStrategy
-
enumClass
- Specified by:
enumClass
in classNumericIdStrategy
-
delegateClass
- Specified by:
delegateClass
in classNumericIdStrategy
-
pojoClass
- Specified by:
pojoClass
in classNumericIdStrategy
-
getRegisteredDelegate
- Specified by:
getRegisteredDelegate
in classNumericIdStrategy
-
getEnumId
- Specified by:
getEnumId
in classNumericIdStrategy
-
getId
- Specified by:
getId
in classNumericIdStrategy
-