• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

alibaba / jetcache / #385

11 Oct 2023 03:46AM UTC coverage: 88.891% (+0.01%) from 88.878%
#385

push

areyouok
improve unit test stability

4745 of 5338 relevant lines covered (88.89%)

0.89 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

75.76
/jetcache-core/src/main/java/com/alicp/jetcache/support/DecoderMap.java
1
/**
2
 * Created on 2018/3/20.
3
 */
4
package com.alicp.jetcache.support;
5

6
import com.alicp.jetcache.anno.SerialPolicy;
7

8
import java.util.concurrent.ConcurrentHashMap;
9
import java.util.concurrent.locks.ReentrantLock;
10

11
/**
12
 * @author <a href="mailto:areyouok@gmail.com">huangli</a>
13
 */
14
public class DecoderMap {
15

16
    private final ConcurrentHashMap<Integer, AbstractValueDecoder> decoderMap = new ConcurrentHashMap<>();
1✔
17
    private volatile boolean inited = false;
1✔
18
    private final ReentrantLock reentrantLock = new ReentrantLock();
1✔
19

20
    private static final DecoderMap instance = new DecoderMap();
1✔
21

22
    public DecoderMap() {
1✔
23
    }
1✔
24

25
    public static DecoderMap defaultInstance() {
26
        return instance;
1✔
27
    }
28

29
    public AbstractValueDecoder getDecoder(int identityNumber) {
30
        return decoderMap.get(identityNumber);
1✔
31
    }
32

33
    public void register(int identityNumber, AbstractValueDecoder decoder) {
34
        reentrantLock.lock();
1✔
35
        try {
36
            decoderMap.put(identityNumber, decoder);
1✔
37
            inited = true;
1✔
38
        }finally {
39
            reentrantLock.unlock();
1✔
40
        }
41
    }
1✔
42

43
    public void clear() {
44
        reentrantLock.lock();
×
45
        try {
46
            decoderMap.clear();
×
47
            inited = true;
×
48
        }finally {
49
            reentrantLock.unlock();
×
50
        }
51
    }
×
52

53
    public void initDefaultDecoder() {
54
        if (inited) {
1✔
55
            return;
1✔
56
        }
57
        reentrantLock.lock();
1✔
58
        try {
59
            if (inited) {
1✔
60
                return;
×
61
            }
62
            register(SerialPolicy.IDENTITY_NUMBER_JAVA, defaultJavaValueDecoder());
1✔
63
            register(SerialPolicy.IDENTITY_NUMBER_KRYO4, KryoValueDecoder.INSTANCE);
1✔
64
            register(SerialPolicy.IDENTITY_NUMBER_KRYO5, Kryo5ValueDecoder.INSTANCE);
1✔
65
            // register(SerialPolicy.IDENTITY_NUMBER_FASTJSON2, Fastjson2ValueDecoder.INSTANCE);
66
            inited = true;
1✔
67
        }finally {
68
            reentrantLock.unlock();
1✔
69
        }
70
    }
1✔
71

72
    public static JavaValueDecoder defaultJavaValueDecoder() {
73
        try {
74
            Class.forName("org.springframework.core.ConfigurableObjectInputStream");
1✔
75
            return SpringJavaValueDecoder.INSTANCE;
1✔
76
        } catch (ClassNotFoundException e) {
×
77
            return JavaValueDecoder.INSTANCE;
×
78
        }
79
    }
80

81

82
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc