org.apache.tinkerpop.shaded.kryo.Serializer Java Examples

The following examples show how to use org.apache.tinkerpop.shaded.kryo.Serializer. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: GryoMapper.java    From tinkerpop with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a {@code GryoMapper}.
 */
public GryoMapper create() {
    // consult the registry if provided and inject registry entries as custom classes.
    registries.forEach(registry -> {
        final List<Pair<Class, Object>> serializers = registry.find(GryoIo.class);
        serializers.forEach(p -> {
            if (null == p.getValue1())
                addCustom(p.getValue0());
            else if (p.getValue1() instanceof SerializerShim)
                addCustom(p.getValue0(), new ShadedSerializerAdapter((SerializerShim) p.getValue1()));
            else if (p.getValue1() instanceof Serializer)
                addCustom(p.getValue0(), (Serializer) p.getValue1());
            else if (p.getValue1() instanceof Function)
                addCustom(p.getValue0(), (Function<Kryo, Serializer>) p.getValue1());
            else
                throw new IllegalStateException(String.format(
                        "Unexpected value provided by %s for serializable class %s - expected a parameter in [null, %s implementation or Function<%s, %s>], but received %s",
                        registry.getClass().getSimpleName(), p.getValue0().getClass().getCanonicalName(),
                        Serializer.class.getName(), Kryo.class.getSimpleName(),
                        Serializer.class.getSimpleName(), p.getValue1()));
        });
    });

    return new GryoMapper(this);
}
 
Example #2
Source File: GryoTypeReg.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
private GryoTypeReg(final Class<T> clazz,
                    final Serializer<T> shadedSerializer,
                    final SerializerShim<T> serializerShim,
                    final Function<Kryo, Serializer> functionOfShadedKryo,
                    final int id) {
    if (null == clazz) throw new IllegalArgumentException("clazz cannot be null");

    this.clazz = clazz;
    this.shadedSerializer = shadedSerializer;
    this.serializerShim = serializerShim;
    this.functionOfShadedKryo = functionOfShadedKryo;
    this.id = id;

    int serializerCount = 0;
    if (null != this.shadedSerializer)
        serializerCount++;
    if (null != this.serializerShim)
        serializerCount++;
    if (null != this.functionOfShadedKryo)
        serializerCount++;

    if (1 < serializerCount) {
        final String msg = String.format(
                "GryoTypeReg accepts at most one kind of serializer, but multiple " +
                        "serializers were supplied for class %s (id %s).  " +
                        "Shaded serializer: %s.  Shim serializer: %s.  Shaded serializer function: %s.",
                this.clazz.getCanonicalName(), id,
                this.shadedSerializer, this.serializerShim, this.functionOfShadedKryo);
        throw new IllegalArgumentException(msg);
    }
}
 
Example #3
Source File: GryoMapper.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
private GryoTypeReg(final Class<T> clazz,
                    final Serializer<T> shadedSerializer,
                    final SerializerShim<T> serializerShim,
                    final Function<Kryo, Serializer> functionOfShadedKryo,
                    final int id) {
    this.clazz = clazz;
    this.shadedSerializer = shadedSerializer;
    this.serializerShim = serializerShim;
    this.functionOfShadedKryo = functionOfShadedKryo;
    this.id = id;

    int serializerCount = 0;
    if (null != this.shadedSerializer)
        serializerCount++;
    if (null != this.serializerShim)
        serializerCount++;
    if (null != this.functionOfShadedKryo)
        serializerCount++;

    if (1 < serializerCount) {
        final String msg = String.format(
                "GryoTypeReg accepts at most one kind of serializer, but multiple " +
                        "serializers were supplied for class %s (id %s).  " +
                        "Shaded serializer: %s.  Shim serializer: %s.  Shaded serializer function: %s.",
                this.clazz.getCanonicalName(), id,
                this.shadedSerializer, this.serializerShim, this.functionOfShadedKryo);
        throw new IllegalArgumentException(msg);
    }
}
 
Example #4
Source File: GryoTypeReg.java    From tinkerpop with Apache License 2.0 4 votes vote down vote up
static <T> GryoTypeReg<T> of(final Class<T> clazz, final int id, final Serializer<T> shadedSerializer) {
    return new GryoTypeReg<>(clazz, shadedSerializer, null, null, id);
}
 
Example #5
Source File: GryoTypeReg.java    From tinkerpop with Apache License 2.0 4 votes vote down vote up
static <T> GryoTypeReg<T> of(final Class clazz, final int id, final Function<Kryo, Serializer> fct) {
    return new GryoTypeReg<>(clazz, null, null, fct, id);
}
 
Example #6
Source File: GryoTypeReg.java    From tinkerpop with Apache License 2.0 4 votes vote down vote up
@Override
public Serializer<T> getShadedSerializer() {
    return shadedSerializer;
}
 
Example #7
Source File: GryoTypeReg.java    From tinkerpop with Apache License 2.0 4 votes vote down vote up
@Override
public Function<Kryo, Serializer> getFunctionOfShadedKryo() {
    return functionOfShadedKryo;
}
 
Example #8
Source File: GryoMapper.java    From tinkerpop with Apache License 2.0 4 votes vote down vote up
/**
 * 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.
 */
public Builder addCustom(final Class clazz, final Serializer serializer) {
    addOrOverrideRegistration(clazz, id -> GryoTypeReg.of(clazz, id, serializer));
    return this;
}
 
Example #9
Source File: GryoMapper.java    From tinkerpop with Apache License 2.0 4 votes vote down vote up
/**
 * Register a custom class to serialize with a custom serializer as returned from a {@link Function}. Note
 * that calling this method for a class that is already registered will override that registration.
 */
public Builder addCustom(final Class clazz, final Function<Kryo, Serializer> functionOfKryo) {
    addOrOverrideRegistration(clazz, id -> GryoTypeReg.of(clazz, id, functionOfKryo));
    return this;
}
 
Example #10
Source File: GryoMapper.java    From tinkerpop with Apache License 2.0 4 votes vote down vote up
private static <T> GryoTypeReg<T> of(final Class<T> clazz, final int id, final Serializer<T> shadedSerializer) {
    return new GryoTypeReg<>(clazz, shadedSerializer, null, null, id);
}
 
Example #11
Source File: GryoMapper.java    From tinkerpop with Apache License 2.0 4 votes vote down vote up
private static <T> GryoTypeReg<T> of(final Class clazz, final int id, final Function<Kryo, Serializer> fct) {
    return new GryoTypeReg<>(clazz, null, null, fct, id);
}
 
Example #12
Source File: GryoMapper.java    From tinkerpop with Apache License 2.0 4 votes vote down vote up
@Override
public Serializer<T> getShadedSerializer() {
    return shadedSerializer;
}
 
Example #13
Source File: GryoMapper.java    From tinkerpop with Apache License 2.0 4 votes vote down vote up
@Override
public Function<Kryo, Serializer> getFunctionOfShadedKryo() {
    return functionOfShadedKryo;
}
 
Example #14
Source File: TypeRegistration.java    From tinkerpop with Apache License 2.0 2 votes vote down vote up
/**
 * @return the shaded-Kryo serializer that handles this type, if one is defined
 */
Serializer<T> getShadedSerializer();
 
Example #15
Source File: TypeRegistration.java    From tinkerpop with Apache License 2.0 2 votes vote down vote up
/**
 * @return a function that accepts a shaded-Kryo instance and returns a serializer, if such a function is defined
 */
java.util.function.Function<Kryo, Serializer> getFunctionOfShadedKryo();