Skip to content

[Java] Support thread safe fury for graalvm native image#1164

Merged
chaokunyang merged 11 commits intoapache:mainfrom
chaokunyang:support_thread_safe_fury_for_graalvm_native
Nov 29, 2023
Merged

[Java] Support thread safe fury for graalvm native image#1164
chaokunyang merged 11 commits intoapache:mainfrom
chaokunyang:support_thread_safe_fury_for_graalvm_native

Conversation

@chaokunyang
Copy link
Collaborator

@chaokunyang chaokunyang commented Nov 28, 2023

What do these changes do?

Support thread safe fury for graalvm native image by cache generated serializer for query by other fury.

Usage example:

import io.fury.Fury;
import io.fury.ThreadLocalFury;
import io.fury.ThreadSafeFury;
import io.fury.util.Preconditions;

import java.util.List;
import java.util.Map;

public class Example {
  static ThreadSafeFury fury;

  static {
    fury = new ThreadLocalFury(classLoader -> {
      Fury f = Fury.builder().requireClassRegistration(true).build();
      // register and generate serializer code.
      f.register(Foo.class, true);
      return f;
    });
  }

  public static void main(String[] args) {
    Preconditions.checkArgument("abc".equals(fury.deserialize(fury.serialize("abc"))));
    Preconditions.checkArgument(List.of(1,2,3).equals(fury.deserialize(fury.serialize(List.of(1,2,3)))));
    Map<String, Integer> map = Map.of("k1", 1, "k2", 2);
    Preconditions.checkArgument(map.equals(fury.deserialize(fury.serialize(map))));
    Foo foo = new Foo(10, "abc", List.of("str1", "str2"), Map.of("k1", 10L, "k2", 20L));
    byte[] bytes = fury.serialize(foo);
    Object o = fury.deserialize(bytes);
    System.out.println(foo);
    System.out.println(o);
    Preconditions.checkArgument(foo.equals(o));
  }
}

Related issue number

Closes #1155
#678 #1115

Check code requirements

  • tests added / passed (if needed)
  • Ensure all linting tests pass, see here for how to run them

Copy link
Member

@theweipeng theweipeng left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@chaokunyang chaokunyang merged commit 8e8349c into apache:main Nov 29, 2023
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

Successfully merging this pull request may close these issues.

[Java] Support thread-safe fury in graalvm native image

2 participants