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

Load the first time you use hessian serialization #339

Merged
merged 3 commits into from
Feb 20, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
*/
package com.alipay.remoting.serialization;

import java.util.concurrent.locks.ReentrantLock;

/**
* Manage all serializers.
*
Expand All @@ -28,16 +30,27 @@
*/
public class SerializerManager {

private static Serializer[] serializers = new Serializer[5];
public static final byte Hessian2 = 1;
private static Serializer[] serializers = new Serializer[5];
public static final byte Hessian2 = 1;
//public static final byte Json = 2;

static {
addSerializer(Hessian2, new HessianSerializer());
}
private static final ReentrantLock REENTRANT_LOCK = new ReentrantLock();

public static Serializer getSerializer(int idx) {
return serializers[idx];
Serializer currentSerializer = serializers[idx];
if (currentSerializer == null && idx == Hessian2) {
REENTRANT_LOCK.lock();
try {
currentSerializer = serializers[idx];
if (currentSerializer == null) {
currentSerializer = new HessianSerializer();
addSerializer(Hessian2, currentSerializer);
}
} finally {
REENTRANT_LOCK.unlock();
}
}
return currentSerializer;
}

public static void addSerializer(int idx, Serializer serializer) {
Expand Down