Search in sources :

Example 56 with Kryo

use of com.esotericsoftware.kryo.Kryo in project flink by apache.

the class WritableComparator 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 57 with Kryo

use of com.esotericsoftware.kryo.Kryo in project flink by apache.

the class WritableSerializer 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(typeClass);
    }
}
Also used : StdInstantiatorStrategy(org.objenesis.strategy.StdInstantiatorStrategy) Kryo(com.esotericsoftware.kryo.Kryo)

Example 58 with Kryo

use of com.esotericsoftware.kryo.Kryo in project storm by apache.

the class BlowfishTupleSerializerTest method testEncryptsAndDecryptsMessage.

/**
     * Reads a string encrypted by another instance with a shared key
     */
@Test
public void testEncryptsAndDecryptsMessage() {
    String testText = "Tetraodontidae is a family of primarily marine and estuarine fish of the order" + " Tetraodontiformes. The family includes many familiar species, which are" + " variously called pufferfish, puffers, balloonfish, blowfish, bubblefish," + " globefish, swellfish, toadfish, toadies, honey toads, sugar toads, and sea" + " squab.[1] They are morphologically similar to the closely related" + " porcupinefish, which have large external spines (unlike the thinner, hidden" + " spines of Tetraodontidae, which are only visible when the fish has puffed up)." + " The scientific name refers to the four large teeth, fused into an upper and" + " lower plate, which are used for crushing the shells of crustaceans and" + " mollusks, their natural prey.";
    Kryo kryo = new Kryo();
    String arbitraryKey = "7dd6fb3203878381b08f9c89d25ed105";
    Map stormConf = ImmutableMap.of(BlowfishTupleSerializer.SECRET_KEY, arbitraryKey);
    BlowfishTupleSerializer writerBTS = new BlowfishTupleSerializer(kryo, stormConf);
    BlowfishTupleSerializer readerBTS = new BlowfishTupleSerializer(kryo, stormConf);
    int bufferSize = 1024;
    Output output = new Output(bufferSize, bufferSize);
    Input input = new Input(bufferSize);
    String[] stringList = testText.split(" ");
    ListDelegate delegate = new ListDelegate();
    delegate.addAll(Arrays.asList(stringList));
    writerBTS.write(kryo, output, delegate);
    input.setBuffer(output.getBuffer());
    ListDelegate outDelegate = readerBTS.read(kryo, input, ListDelegate.class);
    Assert.assertEquals(testText, Joiner.on(" ").join(outDelegate.toArray()));
}
Also used : Input(com.esotericsoftware.kryo.io.Input) Output(com.esotericsoftware.kryo.io.Output) ListDelegate(org.apache.storm.utils.ListDelegate) ImmutableMap(com.google.common.collect.ImmutableMap) Map(java.util.Map) HashMap(java.util.HashMap) Kryo(com.esotericsoftware.kryo.Kryo) Test(org.junit.Test)

Example 59 with Kryo

use of com.esotericsoftware.kryo.Kryo in project flink by apache.

the class AvroSerializer 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);
        // register Avro types.
        this.kryo.register(GenericData.Array.class, new Serializers.SpecificInstanceCollectionSerializerForArrayList());
        this.kryo.register(Utf8.class);
        this.kryo.register(GenericData.EnumSymbol.class);
        this.kryo.register(GenericData.Fixed.class);
        this.kryo.register(GenericData.StringType.class);
        this.kryo.setAsmEnabled(true);
        this.kryo.register(type);
    }
}
Also used : StdInstantiatorStrategy(org.objenesis.strategy.StdInstantiatorStrategy) GenericData(org.apache.avro.generic.GenericData) Serializers(org.apache.flink.api.java.typeutils.runtime.kryo.Serializers) Kryo(com.esotericsoftware.kryo.Kryo)

Example 60 with Kryo

use of com.esotericsoftware.kryo.Kryo in project flink by apache.

the class ValueComparator 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)

Aggregations

Kryo (com.esotericsoftware.kryo.Kryo)94 Input (com.esotericsoftware.kryo.io.Input)37 Output (com.esotericsoftware.kryo.io.Output)34 Test (org.junit.Test)26 ByteArrayOutputStream (java.io.ByteArrayOutputStream)21 ByteArrayInputStream (java.io.ByteArrayInputStream)17 StdInstantiatorStrategy (org.objenesis.strategy.StdInstantiatorStrategy)14 File (java.io.File)10 CollectorTestSink (org.apache.apex.malhar.lib.testbench.CollectorTestSink)10 List (java.util.List)9 Map (java.util.Map)8 Test (org.testng.annotations.Test)8 ArrayList (java.util.ArrayList)7 Path (org.apache.hadoop.fs.Path)7 BigIntegerSerializer (com.esotericsoftware.kryo.serializers.DefaultSerializers.BigIntegerSerializer)5 FileNotFoundException (java.io.FileNotFoundException)5 IOException (java.io.IOException)5 BaseTest (org.broadinstitute.hellbender.utils.test.BaseTest)5 DefaultPartition (com.datatorrent.api.DefaultPartition)4 CountDownLatch (java.util.concurrent.CountDownLatch)4