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

alibaba / jetcache / #448

23 May 2026 01:38PM UTC coverage: 89.341% (+0.4%) from 88.921%
#448

push

areyouok
fix: init fail if Kryo not in classpath

0 of 4 new or added lines in 1 file covered. (0.0%)

27 existing lines in 9 files now uncovered.

5029 of 5629 relevant lines covered (89.34%)

0.89 hits per line

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

92.11
/jetcache-anno/src/main/java/com/alicp/jetcache/anno/support/ConfigProvider.java
1
package com.alicp.jetcache.anno.support;
2

3
import com.alicp.jetcache.CacheBuilder;
4
import com.alicp.jetcache.CacheManager;
5
import com.alicp.jetcache.embedded.EmbeddedCacheBuilder;
6
import com.alicp.jetcache.external.ExternalCacheBuilder;
7
import com.alicp.jetcache.support.AbstractLifecycle;
8
import com.alicp.jetcache.support.DecodeFilter;
9
import com.alicp.jetcache.support.StatInfo;
10
import com.alicp.jetcache.support.StatInfoLogger;
11
import com.alicp.jetcache.template.CacheBuilderTemplate;
12
import com.alicp.jetcache.template.CacheMonitorInstaller;
13
import com.alicp.jetcache.template.MetricsMonitorInstaller;
14
import com.alicp.jetcache.template.NotifyMonitorInstaller;
15
import org.slf4j.Logger;
16
import org.slf4j.LoggerFactory;
17

18
import java.time.Duration;
19
import java.util.List;
20
import java.util.function.Consumer;
21
import java.util.function.Function;
22

23
/**
24
 * Created on 2016/11/29.
25
 *
26
 * @author huangli
27
 */
28
public class ConfigProvider extends AbstractLifecycle {
29

30
    private static final Logger logger = LoggerFactory.getLogger(ConfigProvider.class);
1✔
31

32
    protected GlobalCacheConfig globalCacheConfig;
33

34
    protected EncoderParser encoderParser;
35
    protected KeyConvertorParser keyConvertorParser;
36
    private Consumer<StatInfo> metricsCallback;
37

38
    private CacheBuilderTemplate cacheBuilderTemplate;
39

40
    public ConfigProvider() {
1✔
41
        encoderParser = new DefaultEncoderParser();
1✔
42
        keyConvertorParser = new DefaultKeyConvertorParser();
1✔
43
        metricsCallback = new StatInfoLogger(false);
1✔
44
    }
1✔
45

46
    @Override
47
    protected void doInit() {
48
        cacheBuilderTemplate = new CacheBuilderTemplate(globalCacheConfig.isPenetrationProtect(),
1✔
49
                globalCacheConfig.isUseDefaultLocalExpireInMultiLevelCache(),
1✔
50
                globalCacheConfig.getLocalCacheBuilders(), globalCacheConfig.getRemoteCacheBuilders());
1✔
51
        for (CacheBuilder builder : globalCacheConfig.getLocalCacheBuilders().values()) {
1✔
52
            EmbeddedCacheBuilder eb = (EmbeddedCacheBuilder) builder;
1✔
53
            if (eb.getConfig().getKeyConvertor() instanceof ParserFunction) {
1✔
54
                ParserFunction f = (ParserFunction) eb.getConfig().getKeyConvertor();
1✔
55
                eb.setKeyConvertor(parseKeyConvertor(f.getValue()));
1✔
56
            }
57
        }
1✔
58
        for (CacheBuilder builder : globalCacheConfig.getRemoteCacheBuilders().values()) {
1✔
59
            ExternalCacheBuilder eb = (ExternalCacheBuilder) builder;
1✔
60
            if (eb.getConfig().getKeyConvertor() instanceof ParserFunction) {
1✔
61
                ParserFunction f = (ParserFunction) eb.getConfig().getKeyConvertor();
1✔
62
                eb.setKeyConvertor(parseKeyConvertor(f.getValue()));
1✔
63
            }
64
            if (eb.getConfig().getValueEncoder() instanceof ParserFunction) {
1✔
65
                ParserFunction f = (ParserFunction) eb.getConfig().getValueEncoder();
1✔
66
                eb.setValueEncoder(parseValueEncoder(f.getValue()));
1✔
67
            }
68
            if (eb.getConfig().getValueDecoder() instanceof ParserFunction) {
1✔
69
                ParserFunction f = (ParserFunction) eb.getConfig().getValueDecoder();
1✔
70
                eb.setValueDecoder(parseValueDecoder(f.getValue()));
1✔
71
            }
72
        }
1✔
73
        initDecodeFilter();
1✔
74
        initCacheMonitorInstallers();
1✔
75
    }
1✔
76

77
    protected void initCacheMonitorInstallers() {
78
        cacheBuilderTemplate.getCacheMonitorInstallers().add(metricsMonitorInstaller());
1✔
79
        cacheBuilderTemplate.getCacheMonitorInstallers().add(notifyMonitorInstaller());
1✔
80
        for (CacheMonitorInstaller i : cacheBuilderTemplate.getCacheMonitorInstallers()) {
1✔
81
            if (i instanceof AbstractLifecycle) {
1✔
82
                ((AbstractLifecycle) i).init();
1✔
83
            }
84
        }
1✔
85
    }
1✔
86

87
    private void initDecodeFilter() {
88
        DecodeFilter f = DecodeFilter.getDefault();
1✔
89
        f.setEnabled(globalCacheConfig.isDecodeFilterEnabled());
1✔
90
        List<String> allowPatterns = globalCacheConfig.getDecodeFilterAllowPatterns();
1✔
91
        if (allowPatterns != null && !allowPatterns.isEmpty()) {
1✔
92
            f.addAllowPatterns(allowPatterns.toArray(new String[0]));
1✔
93
        }
94
        List<String> denyPatterns = globalCacheConfig.getDecodeFilterDenyPatterns();
1✔
95
        if (denyPatterns != null && !denyPatterns.isEmpty()) {
1✔
96
            f.addDenyPatterns(denyPatterns.toArray(new String[0]));
1✔
97
        }
98
    }
1✔
99

100
    protected CacheMonitorInstaller metricsMonitorInstaller() {
101
        Duration interval = null;
1✔
102
        if (globalCacheConfig.getStatIntervalMinutes() > 0) {
1✔
103
            interval = Duration.ofMinutes(globalCacheConfig.getStatIntervalMinutes());
1✔
104
        }
105

106
        MetricsMonitorInstaller i = new MetricsMonitorInstaller(metricsCallback, interval);
1✔
107
        i.init();
1✔
108
        return i;
1✔
109
    }
110

111
    protected CacheMonitorInstaller notifyMonitorInstaller() {
112
        return new NotifyMonitorInstaller(area -> globalCacheConfig.getRemoteCacheBuilders().get(area));
1✔
113
    }
114

115
    public CacheBuilderTemplate getCacheBuilderTemplate() {
116
        return cacheBuilderTemplate;
1✔
117
    }
118

119
    @Override
120
    public void doShutdown() {
121
        try {
122
            for (CacheMonitorInstaller i : cacheBuilderTemplate.getCacheMonitorInstallers()) {
1✔
123
                if (i instanceof AbstractLifecycle) {
1✔
124
                    ((AbstractLifecycle) i).shutdown();
1✔
125
                }
126
            }
1✔
UNCOV
127
        } catch (Exception e) {
×
UNCOV
128
            logger.error("close fail", e);
×
129
        }
1✔
130
    }
1✔
131

132
    /**
133
     * Keep this method for backward compatibility.
134
     * NOTICE: there is no getter for encoderParser.
135
     */
136
    public Function<Object, byte[]> parseValueEncoder(String valueEncoder) {
137
        return encoderParser.parseEncoder(valueEncoder);
1✔
138
    }
139

140
    /**
141
     * Keep this method for backward compatibility.
142
     * NOTICE: there is no getter for encoderParser.
143
     */
144
    public Function<byte[], Object> parseValueDecoder(String valueDecoder) {
145
        return encoderParser.parseDecoder(valueDecoder);
1✔
146
    }
147

148
    /**
149
     * Keep this method for backward compatibility.
150
     * NOTICE: there is no getter for keyConvertorParser.
151
     */
152
    public Function<Object, Object> parseKeyConvertor(String convertor) {
153
        return keyConvertorParser.parseKeyConvertor(convertor);
1✔
154
    }
155

156
    public CacheNameGenerator createCacheNameGenerator(String[] hiddenPackages) {
157
        return new DefaultCacheNameGenerator(hiddenPackages);
1✔
158
    }
159

160
    public CacheContext newContext(CacheManager cacheManager) {
161
        return new CacheContext(cacheManager, this, globalCacheConfig);
1✔
162
    }
163

164
    public void setEncoderParser(EncoderParser encoderParser) {
165
        this.encoderParser = encoderParser;
×
166
    }
×
167

168
    public void setKeyConvertorParser(KeyConvertorParser keyConvertorParser) {
UNCOV
169
        this.keyConvertorParser = keyConvertorParser;
×
UNCOV
170
    }
×
171

172
    public GlobalCacheConfig getGlobalCacheConfig() {
173
        return globalCacheConfig;
1✔
174
    }
175

176
    public void setGlobalCacheConfig(GlobalCacheConfig globalCacheConfig) {
177
        this.globalCacheConfig = globalCacheConfig;
1✔
178
    }
1✔
179

180
    public void setMetricsCallback(Consumer<StatInfo> metricsCallback) {
181
        this.metricsCallback = metricsCallback;
1✔
182
    }
1✔
183

184
}
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