Java Code Examples for com.esotericsoftware.kryo.Kryo.newInstance()

The following are Jave code examples for showing how to use newInstance() of the com.esotericsoftware.kryo.Kryo class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: dremio-oss   File: KryoLogicalPlanSerializers.java   Source Code and License Vote up 6 votes
/**
 * Returns a new {@link LogicalPlanSerializer}
 * @param cluster cluster to used during serialization
 */
public static LogicalPlanSerializer forSerialization(final RelOptCluster cluster) {
  final Kryo kryo = new Kryo();
  // use objenesis for creating mock objects
  kryo.setInstantiatorStrategy(new Kryo.DefaultInstantiatorStrategy(new StdInstantiatorStrategy()));

  final CalciteCatalogReader catalog = kryo.newInstance(CalciteCatalogReader.class);
  final StoragePluginRegistry registry = kryo.newInstance(StoragePluginRegistryImpl.class);
  final RelSerializer serializer = RelSerializer.newBuilder(kryo, cluster, catalog, registry).build();

  return new LogicalPlanSerializer() {

    @Override
    public byte[] serialize(final RelNode plan) {
      return serializer.serialize(plan);
    }

  };
}
 
Example 2
Project: dremio-oss   File: RelTraitSerializers.java   Source Code and License Vote up 5 votes
@Override
public RelTraitSet read(final Kryo kryo, final Input input, final Class<RelTraitSet> type) {

  final int size = kryo.readObject(input, Integer.class);
  final RelTrait[] traits = new RelTrait[size];
  for (int i = 0; i < size; i++) {
    final RelTrait trait = (RelTrait) kryo.readClassAndObject(input);
    // normalize trait so that stupid calcite won't complain about == checks.
    traits[i] = trait.getTraitDef().canonize(trait);
  }

  final String digest = kryo.readObject(input, String.class);
  final Object cache = kryo.readClassAndObject(input);

  final RelTraitSet traitSet = kryo.newInstance(type);

  try {
    getField(NAME_CACHE).set(traitSet, cache);
    getField(NAME_TRAITS).set(traitSet, traits);
    getField(NAME_STRING).set(traitSet, digest);
  } catch (final NoSuchFieldException|IllegalAccessException e) {
    throw new RuntimeException("unable to deserialize TraitSet", e);
  }

  kryo.reference(traitSet);
  return traitSet;
}
 
Example 3
Project: dremio-oss   File: RelDataTypeSerializer.java   Source Code and License Vote up 5 votes
@Override
public T read(final Kryo kryo, final Input input, final Class<T> type) {
  // do not use delegate.read because we do not want it to cache the object. Rather, we will cache the normalized type.
  final T dataType = kryo.newInstance(type);
  final FieldSerializer.CachedField[] fields = delegate.getFields();
  for (int i = 0, n = fields.length; i < n; i++) {
    fields[i].read(input, dataType);
  }

  // be gentle to calcite and normalize the returned data type. normalization here means to use same type instances.
  final T result = (T) typeFactory.copyType(dataType);
  kryo.reference(result);
  return result;
}
 
Example 4
Project: dremio-oss   File: WritableSerializer.java   Source Code and License Vote up 5 votes
@Override
public T read(final Kryo kryo, final Input input, final Class<T> type) {
  try {
    final T object = kryo.newInstance(type);
    kryo.reference(object);
    object.readFields(new DataInputStream(input));
    return object;
  } catch (final IOException e) {
    throw new RuntimeException("unable to deserialize Writable object", e);
  }
}
 
Example 5
Project: GabrielBot   File: CustomSerializer.java   Source Code and License Vote up 5 votes
@Override
public T read(Kryo kryo, Input input, Class<T> type) {
    int nfields = input.readInt(true);
    T object = kryo.newInstance(type);
    for(int i = 0; i < nfields; i++) {
        int id = input.readInt(true);
        try {
            fields.get(id).set(object, kryo.readClassAndObject(input));
        } catch(IllegalAccessException e) {
            throw new AssertionError(e);
        }
    }
    return object;
}