de.javakaffee.kryoserializers.UUIDSerializer Java Examples

The following examples show how to use de.javakaffee.kryoserializers.UUIDSerializer. 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: DbStoragePlainFile.java    From Paper with Apache License 2.0 5 votes vote down vote up
private Kryo createKryoInstance(boolean compatibilityMode) {
    Kryo kryo = new Kryo();

    if (compatibilityMode) {
        kryo.getFieldSerializerConfig().setOptimizedGenerics(true);
    }

    kryo.register(PaperTable.class);
    kryo.setDefaultSerializer(CompatibleFieldSerializer.class);
    kryo.setReferences(false);

    // Serialize Arrays$ArrayList
    //noinspection ArraysAsListWithZeroOrOneArgument
    kryo.register(Arrays.asList("").getClass(), new ArraysAsListSerializer());
    UnmodifiableCollectionsSerializer.registerSerializers(kryo);
    SynchronizedCollectionsSerializer.registerSerializers(kryo);
    // Serialize inner AbstractList$SubAbstractListRandomAccess
    kryo.addDefaultSerializer(new ArrayList<>().subList(0, 0).getClass(),
            new NoArgCollectionSerializer());
    // Serialize AbstractList$SubAbstractList
    kryo.addDefaultSerializer(new LinkedList<>().subList(0, 0).getClass(),
            new NoArgCollectionSerializer());
    // To keep backward compatibility don't change the order of serializers above

    // UUID support
    kryo.register(UUID.class, new UUIDSerializer());

    for (Class<?> clazz : mCustomSerializers.keySet())
        kryo.register(clazz, mCustomSerializers.get(clazz));

    kryo.setInstantiatorStrategy(
            new Kryo.DefaultInstantiatorStrategy(new StdInstantiatorStrategy()));

    return kryo;
}
 
Example #2
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;
    });
}