Java Code Examples for com.esotericsoftware.kryo.Kryo#DefaultInstantiatorStrategy

The following examples show how to use com.esotericsoftware.kryo.Kryo#DefaultInstantiatorStrategy . 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: ValueSerializer.java    From flink with Apache License 2.0 5 votes vote down vote up
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);

		KryoUtils.applyRegistrations(this.kryo, kryoRegistrations.values());
	}
}
 
Example 2
Source File: ValueSerializer.java    From flink with Apache License 2.0 5 votes vote down vote up
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);

		KryoUtils.applyRegistrations(this.kryo, kryoRegistrations.values());
	}
}
 
Example 3
Source File: KryoSerializer.java    From flink with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the Chill Kryo Serializer which is implicitly 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("org.apache.flink.runtime.types.FlinkScalaKryoInstantiator");
		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;
	}
}
 
Example 4
Source File: ValueComparator.java    From flink with Apache License 2.0 5 votes vote down vote up
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);
	}
}
 
Example 5
Source File: WritableSerializer.java    From flink with Apache License 2.0 5 votes vote down vote up
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);
	}
}
 
Example 6
Source File: WritableComparator.java    From flink with Apache License 2.0 5 votes vote down vote up
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);
	}
}
 
Example 7
Source File: KryoSerializerTest.java    From flink-htm with GNU Affero General Public License v3.0 5 votes vote down vote up
public Kryo createKryo() {
    Kryo.DefaultInstantiatorStrategy initStrategy = new Kryo.DefaultInstantiatorStrategy();

    // use Objenesis to create classes without calling the constructor (Flink's technique)
    //initStrategy.setFallbackInstantiatorStrategy(new StdInstantiatorStrategy());

    Kryo kryo = new Kryo();
    kryo.setInstantiatorStrategy(initStrategy);
    return kryo;
}
 
Example 8
Source File: TreeSerializationTest.java    From swblocks-decisiontree with Apache License 2.0 5 votes vote down vote up
@Test
public void treeNode() {
    final Result<DecisionTreeRuleSet> result = (new CommisionRuleSetSupplier()).get();
    EhSupport.ensure(result.isSuccess(), "Could not create decision tree");
    final DecisionTreeRuleSet ruleSet = result.getData();

    final TreeNode node = DecisionTreeFactory.constructDecisionTree(ruleSet, DecisionTreeType.SINGLE);

    final Kryo kryo = new Kryo();
    // no default no-arg constructors
    kryo.setInstantiatorStrategy(new StdInstantiatorStrategy());

    final InstantiatorStrategy defaultInstantiatorStrategy = new Kryo.DefaultInstantiatorStrategy();
    kryo.getRegistration(ArrayList.class)
            .setInstantiator(defaultInstantiatorStrategy.newInstantiatorOf(ArrayList.class));
    kryo.getRegistration(HashSet.class)
            .setInstantiator(defaultInstantiatorStrategy.newInstantiatorOf(HashSet.class));
    UnmodifiableCollectionsSerializer.registerSerializers(kryo);

    final ByteArrayOutputStream out = new ByteArrayOutputStream();
    final Output output = new Output(out);
    kryo.writeObject(output, node);
    output.flush();
    output.close();

    final ByteArrayInputStream inputStream = new ByteArrayInputStream(out.toByteArray());
    final Input kryoInput = new Input(inputStream);
    final TreeNode tree = kryo.readObject(kryoInput, BaseTreeNode.class);

    final SingleDecisionTreeFactoryTest test = new SingleDecisionTreeFactoryTest();
    test.checkTreeNode(tree, ruleSet);

    assertEquals(node, tree);
}
 
Example 9
Source File: WritableComparator.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
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);
	}
}
 
Example 10
Source File: KryoSerializer.java    From flink with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the Chill Kryo Serializer which is implicitly 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("org.apache.flink.runtime.types.FlinkScalaKryoInstantiator");
		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;
	}
}
 
Example 11
Source File: ValueComparator.java    From flink with Apache License 2.0 5 votes vote down vote up
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);
	}
}
 
Example 12
Source File: WritableSerializer.java    From flink with Apache License 2.0 5 votes vote down vote up
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);
	}
}
 
Example 13
Source File: WritableComparator.java    From flink with Apache License 2.0 5 votes vote down vote up
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);
	}
}
 
Example 14
Source File: ValueSerializer.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
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);

		KryoUtils.applyRegistrations(this.kryo, kryoRegistrations.values());
	}
}
 
Example 15
Source File: KryoSerializer.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the Chill Kryo Serializer which is implicitly 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("org.apache.flink.runtime.types.FlinkScalaKryoInstantiator");
		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;
	}
}
 
Example 16
Source File: ValueComparator.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
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);
	}
}
 
Example 17
Source File: WritableSerializer.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
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);
	}
}
 
Example 18
Source File: OperationInstantiator.java    From artemis-odb-orion with Apache License 2.0 4 votes vote down vote up
public OperationInstantiator() {
	fallback = new Kryo.DefaultInstantiatorStrategy();
}