Class GryoMapper.Builder
- java.lang.Object
-
- org.apache.tinkerpop.gremlin.structure.io.gryo.GryoMapper.Builder
-
- All Implemented Interfaces:
Mapper.Builder<GryoMapper.Builder>
- Enclosing class:
- GryoMapper
public static class GryoMapper.Builder extends Object implements Mapper.Builder<GryoMapper.Builder>
A builder to construct aGryoMapperinstance.
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description GryoMapper.BuilderaddCustom(Class... custom)Register custom classes to serializes with gryo using default serialization.GryoMapper.BuilderaddCustom(Class clazz, Function<org.apache.tinkerpop.shaded.kryo.Kryo,org.apache.tinkerpop.shaded.kryo.Serializer> functionOfKryo)Register a custom class to serialize with a custom serializer as returned from aFunction.GryoMapper.BuilderaddCustom(Class clazz, SerializerShim serializer)Register custom class to serialize with a custom serialization shim.GryoMapper.BuilderaddCustom(Class clazz, org.apache.tinkerpop.shaded.kryo.Serializer serializer)Register custom class to serialize with a custom serialization class.GryoMapper.BuilderaddRegistry(IoRegistry registry)Adds a vendor suppliedIoRegistryto theMapper.Builderwhich enables it to check for vendor custom serializers to add to theMapper.GryoMapper.BuilderclassResolver(Supplier<org.apache.tinkerpop.shaded.kryo.ClassResolver> classResolverSupplier)Provides a custom KryoClassResolverto be supplied to aKryoinstance.GryoMappercreate()Creates aGryoMapper.GryoMapper.BuilderjavaSerializationAllowed(boolean javaSerializationAllowed)When set tofalse, every registration whose serializer is Kryo'sJavaSerializeris dropped, closing the native Java deserialization sink those registrations carry.GryoMapper.BuilderreferenceTracking(boolean referenceTracking)By default, each appearance of an object in the graph after the first is stored as an integer ordinal.GryoMapper.BuilderregistrationRequired(boolean registrationRequired)When set totrue, all classes serialized by theKryoinstances created from thisGryoMappermust have their classes known up front and registered appropriately through this builder.GryoMapper.Builderversion(GryoVersion version)The version of Gryo to use in the mapper.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.apache.tinkerpop.gremlin.structure.io.Mapper.Builder
addRegistries
-
-
-
-
Method Detail
-
addRegistry
public GryoMapper.Builder addRegistry(IoRegistry registry)
Adds a vendor suppliedIoRegistryto theMapper.Builderwhich enables it to check for vendor custom serializers to add to theMapper. AllIoimplementations should expose this method via thisMapper.Builderso that it is compatible withGraph.io(org.apache.tinkerpop.gremlin.structure.io.Io.Builder<I>). Successive calls to this method will add multiple registries. Registry order must be respected when doing so. In other words, data written withIoRegistryAadded first andBsecond must be read by aMapperwith that same registry ordering. Attempting to addBbeforeAwill result in errors.- Specified by:
addRegistryin interfaceMapper.Builder<GryoMapper.Builder>
-
version
public GryoMapper.Builder version(GryoVersion version)
The version of Gryo to use in the mapper. Defaults to 1.0. Calls to this method will reset values specified toaddCustom(Class, Function)and related overloads.
-
classResolver
public GryoMapper.Builder classResolver(Supplier<org.apache.tinkerpop.shaded.kryo.ClassResolver> classResolverSupplier)
Provides a custom KryoClassResolverto be supplied to aKryoinstance. If this value is not supplied then it will default to theClassResolverof the providedGryoVersion. To ensure compatibility with Gryo it is highly recommended that objects passed to this method extend that class. If theClassResolverimplementation share state, then theSuppliershould typically create new instances when requested, as theSupplierwill be called for eachKryoinstance created.
-
addCustom
public GryoMapper.Builder addCustom(Class... custom)
Register custom classes to serializes with gryo using default serialization. Note that calling this method for a class that is already registered will override that registration.
-
addCustom
public GryoMapper.Builder addCustom(Class clazz, org.apache.tinkerpop.shaded.kryo.Serializer serializer)
Register custom class to serialize with a custom serialization class. Note that calling this method for a class that is already registered will override that registration.
-
addCustom
public GryoMapper.Builder addCustom(Class clazz, SerializerShim serializer)
Register custom class to serialize with a custom serialization shim.
-
addCustom
public GryoMapper.Builder addCustom(Class clazz, Function<org.apache.tinkerpop.shaded.kryo.Kryo,org.apache.tinkerpop.shaded.kryo.Serializer> functionOfKryo)
Register a custom class to serialize with a custom serializer as returned from aFunction. Note that calling this method for a class that is already registered will override that registration.
-
registrationRequired
public GryoMapper.Builder registrationRequired(boolean registrationRequired)
When set totrue, all classes serialized by theKryoinstances created from thisGryoMappermust have their classes known up front and registered appropriately through this builder. By default this value istrue. This approach is more efficient than setting the value tofalse. It must also staytruewhenjavaSerializationAllowed(boolean)isfalse, ascreate()rejects that combination.- Parameters:
registrationRequired- set totrueif the classes should be registered up front orfalseotherwise- See Also:
javaSerializationAllowed(boolean)
-
javaSerializationAllowed
public GryoMapper.Builder javaSerializationAllowed(boolean javaSerializationAllowed)
When set tofalse, every registration whose serializer is Kryo'sJavaSerializeris dropped, closing the native Java deserialization sink those registrations carry. This builder defaults the value totrue, while the paths that read graph documents set it tofalsefor the caller, namelyio(),GryoReader,GryoWriter,GryoIoand the Hadoop Gryo formats, so a builder obtained from one of those arrives hardened already. Dropping the registrations narrows what a Gryo document can do while decoding rather than making an untrusted document safe in general, as other registered types still resolve a class named in the stream. That serializer reads by way ofjava.io.ObjectInputStream.readObject(), which reconstructs and runs an arbitrarySerializableobject graph while decoding, before the graph layer can accept or reject anything. The affected types are mostlyTraversalStrategyimplementations that a graph document does not need; a stream that carries one now fails with an unregistered class id. Registrations contributed through anIoRegistryoraddCustom(...)are covered on the same terms, including those whose serializer is aFunctionor a class default that resolves to aJavaSerializer. This requiresregistrationRequired(boolean)to staytrue, whichcreate()enforces. Without it a stream may name a class as a string rather than by registered id, and Kryo then resolves that class implicitly with its default serializer, which is aJavaSerializerfor any type declaring one. Callers that need the full fidelity for trusted, in-process work should leave this value attrue. A supplied mapper is used as given, soGryoPool, which builds its own and is what OLAP relies on, keeps these registrations and is deliberately out of scope.- Parameters:
javaSerializationAllowed- set tofalseto drop theJavaSerializerregistrations ortrueto keep them- See Also:
registrationRequired(boolean)
-
referenceTracking
public GryoMapper.Builder referenceTracking(boolean referenceTracking)
By default, each appearance of an object in the graph after the first is stored as an integer ordinal. This allows multiple references to the same object and cyclic graphs to be serialized. This has a small amount of overhead and can be disabled to save space if it is not needed.- Parameters:
referenceTracking- set totrueto enable andfalseotherwise
-
create
public GryoMapper create()
Creates aGryoMapper.- Throws:
IllegalStateException- ifjavaSerializationAllowed(boolean)isfalsewhileregistrationRequired(boolean)isfalse, a combination that would not hold theJavaSerializerregistrations out
-
-