Skip to content

Commit

Permalink
refine type register API
Browse files Browse the repository at this point in the history
  • Loading branch information
chaokunyang committed Jul 13, 2024
1 parent 42a6f58 commit a3d4d9d
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,28 +21,36 @@

import java.util.function.Consumer;
import java.util.function.Function;

import org.apache.fury.config.Language;
import org.apache.fury.serializer.Serializer;
import org.apache.fury.serializer.SerializerFactory;
import org.apache.fury.util.Preconditions;

public abstract class AbstractThreadSafeFury implements ThreadSafeFury {
@Override
public void register(Class<?> clz) {
processCallback(fury -> fury.register(clz));
}

@Override
public void register(Class<?> cls, int id) {
processCallback(fury -> fury.register(cls, id));
}

@Override
public void register(Class<?> cls, boolean createSerializer) {
processCallback(fury -> fury.register(cls, createSerializer));
}

@Override
public void register(Class<?> cls, int id) {
processCallback(fury -> fury.register(cls, id));
public void register(Class<?> cls, String typeName) {
processCallback(fury -> fury.register(cls, typeName));
}

@Override
public void register(Class<?> cls, int id, boolean createSerializer) {
processCallback(fury -> fury.register(cls, id, createSerializer));
public void register(Class<?> cls, String namespace, String typeName) {
processCallback(fury -> fury.register(cls, namespace, typeName));
}

@Override
Expand Down
15 changes: 12 additions & 3 deletions java/fury-core/src/main/java/org/apache/fury/BaseFury.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,16 @@

import java.io.OutputStream;
import java.util.function.Function;

import org.apache.fury.config.Language;
import org.apache.fury.io.FuryInputStream;
import org.apache.fury.io.FuryReadableChannel;
import org.apache.fury.memory.MemoryBuffer;
import org.apache.fury.serializer.BufferCallback;
import org.apache.fury.serializer.Serializer;
import org.apache.fury.serializer.SerializerFactory;
import org.apache.fury.serializer.Serializers;
import org.apache.fury.util.Preconditions;

/** All Fury’s basic interface, including Fury’s basic methods. */
public interface BaseFury {
Expand All @@ -41,6 +44,9 @@ public interface BaseFury {
*/
void register(Class<?> cls);

/** register class with given id. */
void register(Class<?> cls, int id);

/**
* Register class and allocate an auto-grown ID for this class. Note that the registration order
* is important. If registration order is inconsistent, the allocated ID will be different, and
Expand All @@ -52,9 +58,6 @@ public interface BaseFury {
*/
void register(Class<?> cls, boolean createSerializer);

/** register class with given id. */
void register(Class<?> cls, int id);

/**
* Register class with specified id.
*
Expand All @@ -65,6 +68,12 @@ public interface BaseFury {
*/
void register(Class<?> cls, int id, boolean createSerializer);

/** register class with given type name which will be used for cross-language serialization. */
void register(Class<?> cls, String typeName);

/** register class with given type namespace and name which will be used for cross-language serialization. */
void register(Class<?> cls, String namespace, String typeName);

/**
* Register a Serializer for a class, and allocate an auto-grown ID for this class if it's not
* registered yet. Note that the registration order is important. If registration order is
Expand Down
14 changes: 6 additions & 8 deletions java/fury-core/src/main/java/org/apache/fury/Fury.java
Original file line number Diff line number Diff line change
Expand Up @@ -147,20 +147,20 @@ public void register(Class<?> cls) {
}

@Override
public void register(Class<?> cls, boolean createSerializer) {
public void register(Class<?> cls, int id) {
if (language == Language.JAVA) {
classResolver.register(cls, createSerializer);
classResolver.register(cls, id);
} else {
xtypeResolver.register(cls);
xtypeResolver.register(cls, id);
}
}

@Override
public void register(Class<?> cls, int id) {
public void register(Class<?> cls, boolean createSerializer) {
if (language == Language.JAVA) {
classResolver.register(cls, id);
classResolver.register(cls, createSerializer);
} else {
xtypeResolver.register(cls, id);
xtypeResolver.register(cls);
}
}

Expand All @@ -173,13 +173,11 @@ public void register(Class<?> cls, int id, boolean createSerializer) {
}
}

/** register class with given type tag which will be used for cross-language serialization. */
public void register(Class<?> cls, String typeName) {
Preconditions.checkArgument(language != Language.JAVA);
register(cls, "", typeName);
}

/** register class with given type tag which will be used for cross-language serialization. */
public void register(Class<?> cls, String namespace, String typeName) {
Preconditions.checkArgument(language != Language.JAVA);
xtypeResolver.register(cls, namespace, typeName);
Expand Down

0 comments on commit a3d4d9d

Please sign in to comment.