com.esotericsoftware.kryo.serializers.FieldSerializer Java Examples

The following examples show how to use com.esotericsoftware.kryo.serializers.FieldSerializer. 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: KryoTranscoderTests.java    From cas4.0.x-server-wechat with Apache License 2.0 6 votes vote down vote up
public KryoTranscoderTests(final int bufferSize) {

        this.principalAttributes = new HashMap<String, Object>();
        this.principalAttributes.put(ST_ID, TGT_ID);

        transcoder = new KryoTranscoder(bufferSize);
        final Map<Class<?>, Serializer> serializerMap = new HashMap<Class<?>, Serializer>();
        serializerMap.put(
                MockServiceTicket.class,
                new FieldSerializer(transcoder.getKryo(), MockServiceTicket.class));
        serializerMap.put(
                MockTicketGrantingTicket.class,
                new FieldSerializer(transcoder.getKryo(), MockTicketGrantingTicket.class));
        serializerMap.put(
                TicketGrantingTicketImpl.class,
                new FieldSerializer(transcoder.getKryo(), TicketGrantingTicketImpl.class));
        serializerMap.put(
                ServiceTicketImpl.class,
                new FieldSerializer(transcoder.getKryo(), ServiceTicketImpl.class));
        transcoder.setSerializerMap(serializerMap);
        transcoder.initialize();
    }
 
Example #2
Source File: KnowledgeBase.java    From fasten with Apache License 2.0 5 votes vote down vote up
/** Initializes the kryo instance used for serialization. */
private void initKryo() {
	kryo = new Kryo();
	kryo.register(BVGraph.class, new BVGraphSerializer(kryo));
	kryo.register(byte[].class);
	kryo.register(InputBitStream.class);
	kryo.register(NullInputStream.class);
	kryo.register(EliasFanoMonotoneLongBigList.class, new JavaSerializer());
	kryo.register(MutableString.class, new FieldSerializer<>(kryo, MutableString.class));
	kryo.register(Properties.class);
	kryo.register(long[].class);
	kryo.register(Long2IntOpenHashMap.class);
}
 
Example #3
Source File: RocksDao.java    From fasten with Apache License 2.0 5 votes vote down vote up
private void initKryo() {
      kryo = new Kryo();
      kryo.register(BVGraph.class, new BVGraphSerializer(kryo));
kryo.register(Boolean.class);
      kryo.register(byte[].class);
      kryo.register(InputBitStream.class);
      kryo.register(NullInputStream.class);
      kryo.register(EliasFanoMonotoneLongBigList.class, new JavaSerializer());
      kryo.register(MutableString.class, new FieldSerializer<>(kryo, MutableString.class));
      kryo.register(Properties.class);
      kryo.register(long[].class);
      kryo.register(Long2IntOpenHashMap.class);
kryo.register(GOV3LongFunction.class, new JavaSerializer());
  }
 
Example #4
Source File: KryoTranscoderTests.java    From springboot-shiro-cas-mybatis with MIT License 5 votes vote down vote up
public KryoTranscoderTests() {
    transcoder = new KryoTranscoder();
    final Map<Class<?>, Serializer> serializerMap = new HashMap<Class<?>, Serializer>();
    serializerMap.put(
            MockServiceTicket.class,
            new FieldSerializer(transcoder.getKryo(), MockServiceTicket.class));
    serializerMap.put(
            MockTicketGrantingTicket.class,
            new FieldSerializer(transcoder.getKryo(), MockTicketGrantingTicket.class));
    transcoder.setSerializerMap(serializerMap);
    transcoder.initialize();

    this.principalAttributes = new HashMap<>();
    this.principalAttributes.put(NICKNAME_KEY, NICKNAME_VALUE);
}
 
Example #5
Source File: RelDataTypeSerializer.java    From dremio-oss with Apache License 2.0 5 votes vote down vote up
@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 #6
Source File: ImmutableCollectionSerializers.java    From dremio-oss with Apache License 2.0 5 votes vote down vote up
public static void register(final Kryo kryo) {
  // register list
  ImmutableListSerializer.register(kryo);
  // register set
  ImmutableSetSerializer.register(kryo);
  // register set
  ImmutableMapSerializer.register(kryo);
  // others
  kryo.addDefaultSerializer(FlatLists.AbstractFlatList.class, FieldSerializer.class);
  kryo.addDefaultSerializer(ImmutableNullableList.class, ImmutableNullableListSerializer.class);
}
 
Example #7
Source File: PropertyUserSerializer.java    From subzero with Apache License 2.0 5 votes vote down vote up
private void registerDefaultSerializer(Kryo kryo) {
    if (defaultSerializerClass != null || !serializerConfigurers.isEmpty()) {
        Class<? extends Serializer> serializerClass = defaultSerializerClass == null
                ? FieldSerializer.class
                : defaultSerializerClass;

        SerializerFactory serializerFactory = new ReflectionSerializerFactory(serializerClass);
        if (!serializerConfigurers.isEmpty()) {
            SerializerConfigurer configurer = serializerConfigurers.get(0);
            serializerFactory = new PostProcessingSerializerFactory(serializerFactory, configurer);
        }
        kryo.setDefaultSerializer(serializerFactory);
    }
}
 
Example #8
Source File: GATKRegistrator.java    From gatk with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@SuppressWarnings({"unchecked", "rawtypes"})
private void registerGATKClasses(Kryo kryo) {
    //relatively inefficient serialization of Collections created with Collections.nCopies(), without this
    //any Collection created with Collections.nCopies fails to serialize at run time
    kryo.register(Collections.nCopies(2, "").getClass(), new FieldSerializer<>(kryo, Collections.nCopies(2, "").getClass()));

    // htsjdk.variant.variantcontext.CommonInfo has a Map<String, Object> that defaults to
    // a Collections.unmodifiableMap. This can't be handled by the version of kryo used in Spark, it's fixed
    // in newer versions (3.0.x), but we can't use those because of incompatibility with Spark. We just include the
    // fix here.
    // We are tracking this issue with (#874)
    kryo.register(Collections.unmodifiableMap(Collections.EMPTY_MAP).getClass(), new UnmodifiableCollectionsSerializer());

    kryo.register(Collections.unmodifiableList(Collections.EMPTY_LIST).getClass(), new UnmodifiableCollectionsSerializer());

    kryo.register(ImmutableMap.of().getClass(), new ImmutableMapSerializer());
    kryo.register(ImmutableMap.of("one","element").getClass(), new ImmutableMapSerializer());
    kryo.register(ImmutableMap.of("map","with","multiple","elements").getClass(), new ImmutableMapSerializer());

    kryo.register(SAMRecordToGATKReadAdapter.class, new SAMRecordToGATKReadAdapterSerializer());

    kryo.register(SAMRecord.class, new SAMRecordSerializer());
    kryo.register(BAMRecord.class, new SAMRecordSerializer());

    kryo.register(SAMFileHeader.class);
    kryo.register(SAMFileHeader.GroupOrder.class);
    kryo.register(SAMFileHeader.SortOrder.class);
    kryo.register(SAMProgramRecord.class);
    kryo.register(SAMReadGroupRecord.class);
    kryo.register(EmptyFragment.class, new FieldSerializer(kryo, EmptyFragment.class));
    kryo.register(Fragment.class, new FieldSerializer(kryo, Fragment.class));
    kryo.register(Pair.class, new Pair.Serializer());
    kryo.register(Passthrough.class, new FieldSerializer(kryo, Passthrough.class));
    kryo.register(MarkDuplicatesSparkUtils.IndexPair.class, new FieldSerializer(kryo, MarkDuplicatesSparkUtils.IndexPair.class));
    kryo.register(ReadsKey.class, new FieldSerializer(kryo, ReadsKey.class));
    kryo.register(ReadsKey.KeyForFragment.class, new FieldSerializer(kryo, ReadsKey.KeyForFragment.class));
    kryo.register(ReadsKey.KeyForPair.class, new FieldSerializer(kryo, ReadsKey.KeyForPair.class));
}
 
Example #9
Source File: RelDataTypeSerializer.java    From dremio-oss with Apache License 2.0 4 votes vote down vote up
protected RelDataTypeSerializer(final Kryo kryo, final Class type, final RelDataTypeFactory typeFactory) {
  this.typeFactory = Preconditions.checkNotNull(typeFactory, "factory is required");
  this.delegate = new FieldSerializer<>(kryo, type);
}
 
Example #10
Source File: EnableSyntheticFields.java    From subzero with Apache License 2.0 4 votes vote down vote up
@Override
public void configure(Class<?> clazz, Object serializer) {
    if (serializer instanceof FieldSerializer) {
        ((FieldSerializer<?>) serializer).setIgnoreSyntheticFields(false);
    }
}
 
Example #11
Source File: DeflateTest.java    From kryonet with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
static public void register (Kryo kryo) {
	kryo.register(short[].class);
	kryo.register(SomeData.class, new DeflateSerializer(new FieldSerializer(kryo, SomeData.class)));
	kryo.register(ArrayList.class, new CollectionSerializer());
}