Search in sources :

Example 1 with StdInstantiatorStrategy

use of org.objenesis.strategy.StdInstantiatorStrategy in project storm by apache.

the class KinesisConnectionInfo method getKryoDeserializedObject.

private Object getKryoDeserializedObject(final byte[] ser) {
    final Kryo kryo = new Kryo();
    final Input input = new Input(new ByteArrayInputStream(ser));
    kryo.setInstantiatorStrategy(new StdInstantiatorStrategy());
    return kryo.readClassAndObject(input);
}
Also used : Input(com.esotericsoftware.kryo.io.Input) StdInstantiatorStrategy(org.objenesis.strategy.StdInstantiatorStrategy) ByteArrayInputStream(java.io.ByteArrayInputStream) Kryo(com.esotericsoftware.kryo.Kryo)

Example 2 with StdInstantiatorStrategy

use of org.objenesis.strategy.StdInstantiatorStrategy in project Paper by pilgr.

the class DbStoragePlainFile method createKryoInstance.

private Kryo createKryoInstance() {
    Kryo kryo = new Kryo();
    kryo.register(PaperTable.class);
    kryo.setDefaultSerializer(CompatibleFieldSerializer.class);
    kryo.setReferences(false);
    // Serialize Arrays$ArrayList
    //noinspection ArraysAsListWithZeroOrOneArgument
    kryo.register(Arrays.asList("").getClass(), new ArraysAsListSerializer());
    UnmodifiableCollectionsSerializer.registerSerializers(kryo);
    SynchronizedCollectionsSerializer.registerSerializers(kryo);
    // Serialize inner AbstractList$SubAbstractListRandomAccess
    kryo.addDefaultSerializer(new ArrayList<>().subList(0, 0).getClass(), new NoArgCollectionSerializer());
    // Serialize AbstractList$SubAbstractList
    kryo.addDefaultSerializer(new LinkedList<>().subList(0, 0).getClass(), new NoArgCollectionSerializer());
    // To keep backward compatibility don't change the order of serializers above
    // UUID support
    kryo.register(UUID.class, new UUIDSerializer());
    for (Class<?> clazz : mCustomSerializers.keySet()) kryo.register(clazz, mCustomSerializers.get(clazz));
    kryo.setInstantiatorStrategy(new Kryo.DefaultInstantiatorStrategy(new StdInstantiatorStrategy()));
    return kryo;
}
Also used : NoArgCollectionSerializer(io.paperdb.serializer.NoArgCollectionSerializer) StdInstantiatorStrategy(org.objenesis.strategy.StdInstantiatorStrategy) UUIDSerializer(de.javakaffee.kryoserializers.UUIDSerializer) ArraysAsListSerializer(de.javakaffee.kryoserializers.ArraysAsListSerializer) Kryo(com.esotericsoftware.kryo.Kryo)

Example 3 with StdInstantiatorStrategy

use of org.objenesis.strategy.StdInstantiatorStrategy in project flink by apache.

the class ValueSerializer method checkKryoInitialized.

private void checkKryoInitialized() {
    if (this.kryo == null) {
        this.kryo = new Kryo();
        Kryo.DefaultInstantiatorStrategy instantiatorStrategy = new Kryo.DefaultInstantiatorStrategy();
        instantiatorStrategy.setFallbackInstantiatorStrategy(new StdInstantiatorStrategy());
        kryo.setInstantiatorStrategy(instantiatorStrategy);
        this.kryo.setAsmEnabled(true);
        this.kryo.register(type);
    }
}
Also used : StdInstantiatorStrategy(org.objenesis.strategy.StdInstantiatorStrategy) Kryo(com.esotericsoftware.kryo.Kryo)

Example 4 with StdInstantiatorStrategy

use of org.objenesis.strategy.StdInstantiatorStrategy in project flink by apache.

the class KryoSerializer method getKryoInstance.

// --------------------------------------------------------------------------------------------
/**
	 * Returns the Chill Kryo Serializer which is implictly added to the classpath via flink-runtime.
	 * Falls back to the default Kryo serializer if it can't be found.
	 * @return The Kryo serializer instance.
	 */
private Kryo getKryoInstance() {
    try {
        // check if ScalaKryoInstantiator is in class path (coming from Twitter's Chill library).
        // This will be true if Flink's Scala API is used.
        Class<?> chillInstantiatorClazz = Class.forName("com.twitter.chill.ScalaKryoInstantiator");
        Object chillInstantiator = chillInstantiatorClazz.newInstance();
        // obtain a Kryo instance through Twitter Chill
        Method m = chillInstantiatorClazz.getMethod("newKryo");
        return (Kryo) m.invoke(chillInstantiator);
    } catch (ClassNotFoundException | InstantiationException | NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
        LOG.warn("Falling back to default Kryo serializer because Chill serializer couldn't be found.", e);
        Kryo.DefaultInstantiatorStrategy initStrategy = new Kryo.DefaultInstantiatorStrategy();
        initStrategy.setFallbackInstantiatorStrategy(new StdInstantiatorStrategy());
        Kryo kryo = new Kryo();
        kryo.setInstantiatorStrategy(initStrategy);
        return kryo;
    }
}
Also used : Method(java.lang.reflect.Method) InvocationTargetException(java.lang.reflect.InvocationTargetException) StdInstantiatorStrategy(org.objenesis.strategy.StdInstantiatorStrategy) Kryo(com.esotericsoftware.kryo.Kryo)

Example 5 with StdInstantiatorStrategy

use of org.objenesis.strategy.StdInstantiatorStrategy in project sling by apache.

the class KryoContentSerializer method importFromStream.

@Override
public void importFromStream(ResourceResolver resourceResolver, InputStream stream) throws DistributionException {
    Kryo kryo = new Kryo();
    kryo.setInstantiatorStrategy(new Kryo.DefaultInstantiatorStrategy(new StdInstantiatorStrategy()));
    kryo.addDefaultSerializer(Resource.class, new ResourceSerializer(null));
    kryo.addDefaultSerializer(InputStream.class, new InputStreamSerializer());
    try {
        Input input = new Input(stream);
        @SuppressWarnings("unchecked") LinkedList<Resource> resources = (LinkedList<Resource>) kryo.readObject(input, LinkedList.class);
        input.close();
        for (Resource resource : resources) {
            persistResource(resourceResolver, resource);
        }
        resourceResolver.commit();
    } catch (Exception e) {
        throw new DistributionException(e);
    }
}
Also used : Input(com.esotericsoftware.kryo.io.Input) StdInstantiatorStrategy(org.objenesis.strategy.StdInstantiatorStrategy) Resource(org.apache.sling.api.resource.Resource) SyntheticResource(org.apache.sling.api.resource.SyntheticResource) DistributionException(org.apache.sling.distribution.common.DistributionException) Kryo(com.esotericsoftware.kryo.Kryo) LinkedList(java.util.LinkedList) DistributionException(org.apache.sling.distribution.common.DistributionException) PersistenceException(org.apache.sling.api.resource.PersistenceException) IOException(java.io.IOException)

Aggregations

Kryo (com.esotericsoftware.kryo.Kryo)13 StdInstantiatorStrategy (org.objenesis.strategy.StdInstantiatorStrategy)13 Input (com.esotericsoftware.kryo.io.Input)4 Output (com.esotericsoftware.kryo.io.Output)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 LinkedList (java.util.LinkedList)2 Resource (org.apache.sling.api.resource.Resource)2 SyntheticResource (org.apache.sling.api.resource.SyntheticResource)2 ArraysAsListSerializer (de.javakaffee.kryoserializers.ArraysAsListSerializer)1 UUIDSerializer (de.javakaffee.kryoserializers.UUIDSerializer)1 NoArgCollectionSerializer (io.paperdb.serializer.NoArgCollectionSerializer)1 IOException (java.io.IOException)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Method (java.lang.reflect.Method)1 GenericData (org.apache.avro.generic.GenericData)1 Serializers (org.apache.flink.api.java.typeutils.runtime.kryo.Serializers)1 PersistenceException (org.apache.sling.api.resource.PersistenceException)1 DistributionException (org.apache.sling.distribution.common.DistributionException)1 DistributionExportFilter (org.apache.sling.distribution.serialization.DistributionExportFilter)1