Skip to content

Commit

Permalink
Load the first time you use hessian serialization (sofastack#339)
Browse files Browse the repository at this point in the history
* Load the first time you use hessian serialization
  • Loading branch information
funky-eyes authored and jiangyuan04 committed Jun 5, 2024
1 parent 8187102 commit e2feb8e
Showing 1 changed file with 19 additions and 6 deletions.
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

0 comments on commit e2feb8e

Please sign in to comment.