de.javakaffee.kryoserializers.guava.ImmutableMapSerializer Java Examples

The following examples show how to use de.javakaffee.kryoserializers.guava.ImmutableMapSerializer. 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: SerDeUtils.java    From metron with Apache License 2.0 5 votes vote down vote up
@Override
    protected Kryo initialValue() {
      Kryo ret = new Kryo();
      ret.setReferences(true);
      ret.setInstantiatorStrategy(new DefaultInstantiatorStrategy(new StdInstantiatorStrategy()));

      ret.register(Arrays.asList("").getClass(), new ArraysAsListSerializer());
      ret.register(Collections.EMPTY_LIST.getClass(), new CollectionsEmptyListSerializer());
      ret.register(Collections.EMPTY_MAP.getClass(), new CollectionsEmptyMapSerializer());
      ret.register(Collections.EMPTY_SET.getClass(), new CollectionsEmptySetSerializer());
      ret.register(Collections.singletonList("").getClass(), new CollectionsSingletonListSerializer());
      ret.register(Collections.singleton("").getClass(), new CollectionsSingletonSetSerializer());
      ret.register(Collections.singletonMap("", "").getClass(), new CollectionsSingletonMapSerializer());
      ret.register(GregorianCalendar.class, new GregorianCalendarSerializer());
      ret.register(InvocationHandler.class, new JdkProxySerializer());
      UnmodifiableCollectionsSerializer.registerSerializers(ret);
      SynchronizedCollectionsSerializer.registerSerializers(ret);

// custom serializers for non-jdk libs

// register CGLibProxySerializer, works in combination with the appropriate action in handleUnregisteredClass (see below)
      ret.register(CGLibProxySerializer.CGLibProxyMarker.class, new CGLibProxySerializer());
// joda DateTime, LocalDate and LocalDateTime
      ret.register(LocalDate.class, new JodaLocalDateSerializer());
      ret.register(LocalDateTime.class, new JodaLocalDateTimeSerializer());
// guava ImmutableList, ImmutableSet, ImmutableMap, ImmutableMultimap, UnmodifiableNavigableSet
      ImmutableListSerializer.registerSerializers(ret);
      ImmutableSetSerializer.registerSerializers(ret);
      ImmutableMapSerializer.registerSerializers(ret);
      ImmutableMultimapSerializer.registerSerializers(ret);
      return ret;
    }
 
Example #2
Source File: SerDeUtils.java    From metron with Apache License 2.0 5 votes vote down vote up
@Override
protected Kryo initialValue() {
  Kryo ret = new Kryo();
  ret.setReferences(true);
  ret.setInstantiatorStrategy(new DefaultInstantiatorStrategy(new StdInstantiatorStrategy()));

  ret.register(Arrays.asList("").getClass(), new ArraysAsListSerializer());
  ret.register(Collections.EMPTY_LIST.getClass(), new CollectionsEmptyListSerializer());
  ret.register(Collections.EMPTY_MAP.getClass(), new CollectionsEmptyMapSerializer());
  ret.register(Collections.EMPTY_SET.getClass(), new CollectionsEmptySetSerializer());
  ret.register(Collections.singletonList("").getClass(), new CollectionsSingletonListSerializer());
  ret.register(Collections.singleton("").getClass(), new CollectionsSingletonSetSerializer());
  ret.register(Collections.singletonMap("", "").getClass(), new CollectionsSingletonMapSerializer());
  ret.register(GregorianCalendar.class, new GregorianCalendarSerializer());
  ret.register(InvocationHandler.class, new JdkProxySerializer());
  UnmodifiableCollectionsSerializer.registerSerializers(ret);
  SynchronizedCollectionsSerializer.registerSerializers(ret);

  // custom serializers for non-jdk libs

  // register CGLibProxySerializer, works in combination with the appropriate action in handleUnregisteredClass (see below)
  ret.register(CGLibProxySerializer.CGLibProxyMarker.class, new CGLibProxySerializer());

  // joda DateTime, LocalDate and LocalDateTime
  ret.register(LocalDate.class, new JodaLocalDateSerializer());
  ret.register(LocalDateTime.class, new JodaLocalDateTimeSerializer());

  // guava ImmutableList, ImmutableSet, ImmutableMap, ImmutableMultimap, UnmodifiableNavigableSet
  ImmutableListSerializer.registerSerializers(ret);
  ImmutableSetSerializer.registerSerializers(ret);
  ImmutableMapSerializer.registerSerializers(ret);
  ImmutableMultimapSerializer.registerSerializers(ret);
  return ret;
}
 
Example #3
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 #4
Source File: ValkyrienSkiesMod.java    From Valkyrien-Skies with Apache License 2.0 4 votes vote down vote up
/**
 * Create our new instance of {@link Kryo}. This is done asynchronously with CompletableFuture
 * so as not to slow down initialization. We save a lot of time this way!
 */
private void serializationInitAsync() {
    kryoInstance = CompletableFuture.supplyAsync(() -> {
        long start = System.currentTimeMillis();

        Kryo kryo = new Kryo();

        // region More serializers

        //noinspection ArraysAsListWithZeroOrOneArgument
        UnmodifiableCollectionsSerializer.registerSerializers(kryo);
        SynchronizedCollectionsSerializer.registerSerializers(kryo);

        ImmutableListSerializer.registerSerializers(kryo);
        ImmutableSetSerializer.registerSerializers(kryo);
        ImmutableMapSerializer.registerSerializers(kryo);
        ImmutableMultimapSerializer.registerSerializers(kryo);
        ImmutableTableSerializer.registerSerializers(kryo);
        ReverseListSerializer.registerSerializers(kryo);
        UnmodifiableNavigableSetSerializer.registerSerializers(kryo);

        ArrayListMultimapSerializer.registerSerializers(kryo);
        HashMultimapSerializer.registerSerializers(kryo);
        LinkedHashMultimapSerializer.registerSerializers(kryo);
        LinkedListMultimapSerializer.registerSerializers(kryo);
        TreeMultimapSerializer.registerSerializers(kryo);
        ArrayTableSerializer.registerSerializers(kryo);
        HashBasedTableSerializer.registerSerializers(kryo);
        TreeBasedTableSerializer.registerSerializers(kryo);

        // endregion

        kryo.register(ConcurrentIndexedCollection.class);
        kryo.register(ShipData.class);
        kryo.register(ShipPositionData.class);
        kryo.register(VSChunkClaim.class);
        kryo.register(HashSet.class);
        kryo.register(UUID.class, new UUIDSerializer());

        // This should be changed to true but only once we're stable
        kryo.setRegistrationRequired(false);

        log.debug("Kryo initialization: " + (System.currentTimeMillis() - start) + "ms");

        return kryo;
    });
}
 
Example #5
Source File: KryoSerialization.java    From cuba with Apache License 2.0 4 votes vote down vote up
protected Kryo newKryoInstance() {
    Kryo kryo = new Kryo(new DefaultClassResolver(), new CubaMapReferenceResolver());
    kryo.setInstantiatorStrategy(new CubaInstantiatorStrategy());
    if (onlySerializable) {
        kryo.setDefaultSerializer(CubaFieldSerializer.class);
    }

    //To work properly must itself be loaded by the application classloader (i.e. by classloader capable of loading
    //all the other application classes). For web application it means placing this class inside webapp folder.
    kryo.setClassLoader(KryoSerialization.class.getClassLoader());

    //noinspection ArraysAsListWithZeroOrOneArgument
    kryo.register(Arrays.asList("").getClass(), new ArraysAsListSerializer());
    kryo.register(Collections.EMPTY_LIST.getClass(), new CollectionsEmptyListSerializer());
    kryo.register(Collections.EMPTY_MAP.getClass(), new CollectionsEmptyMapSerializer());
    kryo.register(Collections.EMPTY_SET.getClass(), new CollectionsEmptySetSerializer());
    kryo.register(Collections.singletonList("").getClass(), new CollectionsSingletonListSerializer());
    kryo.register(Collections.singleton("").getClass(), new CollectionsSingletonSetSerializer());
    kryo.register(Collections.singletonMap("", "").getClass(), new CollectionsSingletonMapSerializer());
    kryo.register(BitSet.class, new BitSetSerializer());
    kryo.register(GregorianCalendar.class, new GregorianCalendarSerializer());
    kryo.register(InvocationHandler.class, new JdkProxySerializer());
    kryo.register(EnumSet.class, new EnumSetSerializer());
    kryo.register(TreeSet.class, new DefaultSerializers.TreeSetSerializer());
    UnmodifiableCollectionsSerializer.registerSerializers(kryo);
    SynchronizedCollectionsSerializer.registerSerializers(kryo);
    kryo.register(Pattern.class, new RegexSerializer());

    kryo.register(CGLibProxySerializer.CGLibProxyMarker.class, new CGLibProxySerializer());
    ImmutableListSerializer.registerSerializers(kryo);
    ImmutableSetSerializer.registerSerializers(kryo);
    ImmutableMapSerializer.registerSerializers(kryo);
    ImmutableMultimapSerializer.registerSerializers(kryo);
    kryo.register(IndirectList.class, new IndirectContainerSerializer());
    kryo.register(IndirectMap.class, new IndirectContainerSerializer());
    kryo.register(IndirectSet.class, new IndirectContainerSerializer());

    kryo.register(org.eclipse.persistence.indirection.IndirectList.class, new IndirectContainerSerializer());
    kryo.register(org.eclipse.persistence.indirection.IndirectMap.class, new IndirectContainerSerializer());
    kryo.register(org.eclipse.persistence.indirection.IndirectSet.class, new IndirectContainerSerializer());

    //classes with custom serialization methods
    kryo.register(HashMultimap.class, new CubaJavaSerializer());
    kryo.register(ArrayListMultimap.class, new CubaJavaSerializer());
    kryo.register(MetaClassImpl.class, new CubaJavaSerializer());
    kryo.register(MetaPropertyImpl.class, new CubaJavaSerializer());
    kryo.register(UnitOfWorkQueryValueHolder.class, new UnitOfWorkQueryValueHolderSerializer(kryo));

    kryo.addDefaultSerializer(Collection.class, new CubaCollectionSerializer());

    registerEntitySerializer(kryo);

    return kryo;
}