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 io.netty.util.internal.PlatformDependent;
19
20 import java.lang.ref.Reference;
21 import java.util.HashMap;
22
23 public final class ClassResolvers {
24
25
26
27
28
29
30 public static ClassResolver cacheDisabled(ClassLoader classLoader) {
31 return new ClassLoaderClassResolver(defaultClassLoader(classLoader));
32 }
33
34
35
36
37
38
39
40
41 public static ClassResolver weakCachingResolver(ClassLoader classLoader) {
42 return new CachingClassResolver(
43 new ClassLoaderClassResolver(defaultClassLoader(classLoader)),
44 new WeakReferenceMap<String, Class<?>>(new HashMap<String, Reference<Class<?>>>()));
45 }
46
47
48
49
50
51
52
53
54 public static ClassResolver softCachingResolver(ClassLoader classLoader) {
55 return new CachingClassResolver(
56 new ClassLoaderClassResolver(defaultClassLoader(classLoader)),
57 new SoftReferenceMap<String, Class<?>>(new HashMap<String, Reference<Class<?>>>()));
58 }
59
60
61
62
63
64
65
66
67 public static ClassResolver weakCachingConcurrentResolver(ClassLoader classLoader) {
68 return new CachingClassResolver(
69 new ClassLoaderClassResolver(defaultClassLoader(classLoader)),
70 new WeakReferenceMap<String, Class<?>>(
71 PlatformDependent.<String, Reference<Class<?>>>newConcurrentHashMap()));
72 }
73
74
75
76
77
78
79
80
81 public static ClassResolver softCachingConcurrentResolver(ClassLoader classLoader) {
82 return new CachingClassResolver(
83 new ClassLoaderClassResolver(defaultClassLoader(classLoader)),
84 new SoftReferenceMap<String, Class<?>>(
85 PlatformDependent.<String, Reference<Class<?>>>newConcurrentHashMap()));
86 }
87
88 static ClassLoader defaultClassLoader(ClassLoader classLoader) {
89 if (classLoader != null) {
90 return classLoader;
91 }
92
93 final ClassLoader contextClassLoader = PlatformDependent.getContextClassLoader();
94 if (contextClassLoader != null) {
95 return contextClassLoader;
96 }
97
98 return PlatformDependent.getClassLoader(ClassResolvers.class);
99 }
100
101 private ClassResolvers() {
102
103 }
104 }