Java Code Examples for com.esotericsoftware.kryo.Kryo#reference()
The following examples show how to use
com.esotericsoftware.kryo.Kryo#reference() .
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: RelTraitSerializers.java From dremio-oss with Apache License 2.0 | 5 votes |
@Override public T read(final Kryo kryo, final Input input, final Class<T> type) { final boolean isNone = kryo.readObject(input, Boolean.class); if (isNone) { return (T)Convention.NONE; } final T result = super.read(kryo, input, type); final T normalized = (T) result.getTraitDef().canonize(result); kryo.reference(normalized); return normalized; }
Example 2
Source File: RelTraitSerializers.java From dremio-oss with Apache License 2.0 | 5 votes |
@Override public T read(final Kryo kryo, final Input input, final Class<T> type) { final boolean isKnown = kryo.readObject(input, Boolean.class); final T result; if (isKnown) { final RelDistribution.Type kind = kryo.readObject(input, RelDistribution.Type.class); result = (T)distributionMap.get(kind); } else { result = super.read(kryo, input, type); } final T normalized = (T) result.getTraitDef().canonize(result); kryo.reference(normalized); return normalized; }
Example 3
Source File: RelTraitSerializers.java From dremio-oss with Apache License 2.0 | 5 votes |
@Override public T read(final Kryo kryo, final Input input, final Class<T> type) { final boolean isKnown = kryo.readObject(input, Boolean.class); final T result; if (isKnown) { final DistributionTrait.DistributionType kind = kryo.readObject(input, DistributionTrait.DistributionType.class); result = (T)distributionMap.get(kind); } else { result = super.read(kryo, input, type); } final T normalized = (T) result.getTraitDef().canonize(result); kryo.reference(normalized); return normalized; }
Example 4
Source File: RelTraitSerializers.java From dremio-oss with Apache License 2.0 | 5 votes |
@Override public T read(final Kryo kryo, final Input input, final Class<T> type) { final boolean isKnown = kryo.readObject(input, Boolean.class); final T result; if (isKnown) { final Integer pos = kryo.readObject(input, Integer.class); result = (T) (pos == 0 ? RelCollations.EMPTY:RelCollations.PRESERVE); } else { result = super.read(kryo, input, type); } final T normalized = (T) result.getTraitDef().canonize(result); kryo.reference(normalized); return normalized; }
Example 5
Source File: RelTraitSerializers.java From dremio-oss with Apache License 2.0 | 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 6
Source File: RelDataTypeSerializer.java From dremio-oss with Apache License 2.0 | 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 7
Source File: ImmutableCollectionSerializers.java From dremio-oss with Apache License 2.0 | 5 votes |
@Override public ImmutableList<Object> read(final Kryo kryo, final Input input, final Class<ImmutableList<Object>> type) { final int size = input.readInt(true); final Object[] values = new Object[size]; for (int i = 0; i < size; ++i) { values[i] = kryo.readClassAndObject(input); } final ImmutableList<Object> result = ImmutableList.copyOf(values); kryo.reference(result); return result; }
Example 8
Source File: ImmutableCollectionSerializers.java From dremio-oss with Apache License 2.0 | 5 votes |
@Override public ImmutableSet<Object> read(final Kryo kryo, final Input input, final Class<ImmutableSet<Object>> type) { final int size = input.readInt(true); final ImmutableSet.Builder builder = ImmutableSet.builder(); for (int i = 0; i < size; ++i) { builder.add(kryo.readClassAndObject(input)); } final ImmutableSet<Object> result = builder.build(); kryo.reference(result); return result; }
Example 9
Source File: ImmutableCollectionSerializers.java From dremio-oss with Apache License 2.0 | 5 votes |
@Override public ImmutableMap<Object, Object> read(Kryo kryo, Input input, Class<ImmutableMap<Object, ? extends Object>> type) { Map map = kryo.readObject(input, HashMap.class); final ImmutableMap<Object, Object> result = ImmutableMap.copyOf(map); kryo.reference(result); return result; }
Example 10
Source File: SqlOperatorSerializer.java From dremio-oss with Apache License 2.0 | 5 votes |
@Override public T read(final Kryo kryo, final Input input, final Class<T> type) { final boolean isKnown = kryo.readObject(input, Boolean.class); if (isKnown) { final Integer ordinal = kryo.readObject(input, Integer.class); final SqlOperator operator = OperatorPopulator.BACKWARD.get(ordinal); if (operator != null) { kryo.reference(operator); return (T)operator; } throw new IllegalStateException(String.format("Unable to locate operator with ordinal [%s]", ordinal)); } return super.read(kryo, input, type); }
Example 11
Source File: WritableSerializer.java From dremio-oss with Apache License 2.0 | 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 12
Source File: StoragePluginIdSerializer.java From dremio-oss with Apache License 2.0 | 4 votes |
@Override public StoragePluginId read(Kryo kryo, Input input, Class<StoragePluginId> type) { // Override read such that we construct a specialized serializer for the ConnectionConf // based on the value (not metadata) of the SourceConfig. Aside from the reading from fields, // this code is the same as the base class implementation of read(). try { if (config.isOptimizedGenerics()) { if (typeParameters != null && getGenerics() != null) { // Rebuild fields info. It may result in rebuilding the // genericScope rebuildCachedFields(); } if (getGenericsScope() != null) { // Push a new scope for generics kryo.getGenericsResolver().pushScope(type, getGenericsScope()); } } final StoragePluginId object = create(kryo, input, type); kryo.reference(object); // Read fields up to config. Note that fields are serialized in _alphabetical_ order, // not the order they are declared in! // Using indices rather than field name lookups for performance reasons. final CachedField[] fields = this.getFields(); fields[StoragePluginId.CAPABILITIES_INDEX_0].read(input, object); // capabilities fields[StoragePluginId.CONFIG_INDEX_1].read(input, object); // config // Add custom serializer for the ConnectionConf that is aware of the SourceConfig. fields[StoragePluginId.CONNECTION_INDEX_2].setSerializer(getConnectionConfDeserializer(object.getConfig())); fields[StoragePluginId.CONNECTION_INDEX_2].read(input, object); // connection fields[StoragePluginId.HASH_CODE_INDEX_3].read(input, object); // hashCode // De-serialize transient fields if (config.isSerializeTransient()) { for (int i = 0, n = getTransientFields().length; i < n; i++) { getTransientFields()[i].read(input, object); } } return object; } finally { if (config.isOptimizedGenerics() && getGenericsScope() != null && kryo.getGenericsResolver() != null) { // Pop the scope for generics kryo.getGenericsResolver().popScope(); } } }
Example 13
Source File: RelTraitDefSerializers.java From dremio-oss with Apache License 2.0 | 4 votes |
@Override public T read(final Kryo kryo, final Input input, final Class<T> type) { final T result = factory.get(); kryo.reference(result); return result; }