Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom Kryo serializer for unmodificable collections #46

Open
llaros opened this issue Sep 14, 2021 · 6 comments
Open

Custom Kryo serializer for unmodificable collections #46

llaros opened this issue Sep 14, 2021 · 6 comments

Comments

@llaros
Copy link

llaros commented Sep 14, 2021

Hello,

I've read #8 and therefore placed subzero-serializers.properties file with UnmodifiableCollectionsSerializer
as its content.

Project dependencies

                  <dependency>
			<groupId>info.jerrinot</groupId>
			<artifactId>subzero-all</artifactId>
			<version>0.10</version>
		</dependency>
		<dependency>
			<groupId>de.javakaffee</groupId>
			<artifactId>kryo-serializers</artifactId>
			<version>0.45</version> <!-- tried also with 0.49 same problem -->
		</dependency>

hazelcast.xml with following element

    <serialization>
        <serializers>
            <global-serializer override-java-serialization="true">info.jerrinot.subzero.Serializer</global-serializer>
        </serializers>
    </serialization>

But got following exception on hz node startup:

Caused by: java.lang.IllegalStateException: Serializer UnmodifiableCollectionsSerializer does not have expected method 'registerSerializers()': 
obh-cache-hz-cluster_1                    |     at info.jerrinot.subzero.internal.PropertyUserSerializer.addNewSpecialSerializer(PropertyUserSerializer.java:90)
obh-cache-hz-cluster_1                    |     at info.jerrinot.subzero.internal.PropertyUserSerializer.readLineAndRegister(PropertyUserSerializer.java:73)
obh-cache-hz-cluster_1                    |     at info.jerrinot.subzero.internal.PropertyUserSerializer.initCustomSerializers(PropertyUserSerializer.java:54)
obh-cache-hz-cluster_1                    |     at info.jerrinot.subzero.internal.PropertyUserSerializer.<init>(PropertyUserSerializer.java:41)
obh-cache-hz-cluster_1                    |     at info.jerrinot.subzero.Serializer.<init>(Serializer.java:10)

I've decompiled UnmodifiableCollectionsSerializer and assured that it has

 public static void registerSerializers(Kryo kryo) {
        UnmodifiableCollectionsSerializer serializer = new UnmodifiableCollectionsSerializer();
        UnmodifiableCollectionsSerializer.UnmodifiableCollection.values();
        UnmodifiableCollectionsSerializer.UnmodifiableCollection[] var2 = UnmodifiableCollectionsSerializer.UnmodifiableCollection.values();
        int var3 = var2.length;

        for(int var4 = 0; var4 < var3; ++var4) {
            UnmodifiableCollectionsSerializer.UnmodifiableCollection item = var2[var4];
            kryo.register(item.type, serializer);
        }

    }
@llaros
Copy link
Author

llaros commented Sep 14, 2021

IMHO the problem lies with the expected Kryo object or more precisely its package com.esotericsoftware.kryo.Kryo vs info.jerrinot.subzero.relocated.com.esotericsoftware.kryo.Kryo

@llaros
Copy link
Author

llaros commented Sep 14, 2021

Problem solved with following dependencies

<dependency>
			<groupId>info.jerrinot</groupId>
			<artifactId>subzero-core</artifactId>
			<version>0.10</version>
		</dependency>
		<dependency>
			<groupId>de.javakaffee</groupId>
			<artifactId>kryo-serializers</artifactId>
			<version>0.45</version>
		</dependency>
		<dependency>
			<groupId>com.esotericsoftware</groupId>
			<artifactId>kryo</artifactId>
			<version>4.0.2</version>
		</dependency>

@llaros llaros closed this as completed Sep 14, 2021
@llaros llaros reopened this Sep 15, 2021
@llaros
Copy link
Author

llaros commented Sep 15, 2021

I've reopened just because I don't know whether or notshould subzero-all work out-of-the box with kryo-serializers.

@jerrinot
Copy link
Owner

jerrinot commented Oct 6, 2021

hi, thanks for reporting this, your analysis looks correct. I'll check what to do about it.

@jerrinot
Copy link
Owner

jerrinot commented Oct 8, 2021

@llaros I'm afraid there is no good solution. The serializer plugins expect Kryo in the original package. I could either:

  1. Not relocate Kryo at all. That's already the case with subzero-core.
  2. Include (and relocate) selected serialized plugins inside subzero-all but it does not feel good.

Any other idea?

@jerrinot
Copy link
Owner

jerrinot commented Oct 12, 2021

Some more thoughts: Subzero-All could relocate Kryo dependencies, but keep Kryo itself in its original packages.
Why? Kryo depends on some fairly popular low-level infrastructure libraries, such as Asm or Objenesis. Not relocating them could lead to a bad JAR hell. Kryo itself is less popular and the risk of conflicts is lower. Not relocating it will allow 3rd party serializers to work. Thanks to @viliam-durina for the idea!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants