1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package io.netty.handler.codec.serialization;
17
18 import java.util.Map;
19
20 class CachingClassResolver implements ClassResolver {
21
22 private final Map<String, Class<?>> classCache;
23 private final ClassResolver delegate;
24
25 CachingClassResolver(ClassResolver delegate, Map<String, Class<?>> classCache) {
26 this.delegate = delegate;
27 this.classCache = classCache;
28 }
29
30 @Override
31 public Class<?> resolve(String className) throws ClassNotFoundException {
32
33 Class<?> clazz;
34 clazz = classCache.get(className);
35 if (clazz != null) {
36 return clazz;
37 }
38
39
40 clazz = delegate.resolve(className);
41
42 classCache.put(className, clazz);
43 return clazz;
44 }
45
46 }