1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.jboss.netty.handler.codec.serialization;
17
18 import java.lang.ref.Reference;
19 import java.util.HashMap;
20 import java.util.concurrent.ConcurrentHashMap;
21
22 public final class ClassResolvers {
23
24
25
26
27
28
29 public static ClassResolver cacheDisabled(ClassLoader classLoader) {
30 return new ClassLoaderClassResolver(defaultClassLoader(classLoader));
31 }
32
33
34
35
36
37
38
39
40 public static ClassResolver weakCachingResolver(ClassLoader classLoader) {
41 return new CachingClassResolver(
42 new ClassLoaderClassResolver(defaultClassLoader(classLoader)),
43 new WeakReferenceMap<String, Class<?>>(new HashMap<String, Reference<Class<?>>>()));
44 }
45
46
47
48
49
50
51
52
53 public static ClassResolver softCachingResolver(ClassLoader classLoader) {
54 return new CachingClassResolver(
55 new ClassLoaderClassResolver(defaultClassLoader(classLoader)),
56 new SoftReferenceMap<String, Class<?>>(new HashMap<String, Reference<Class<?>>>()));
57 }
58
59
60
61
62
63
64
65
66 public static ClassResolver weakCachingConcurrentResolver(ClassLoader classLoader) {
67 return new CachingClassResolver(
68 new ClassLoaderClassResolver(defaultClassLoader(classLoader)),
69 new WeakReferenceMap<String, Class<?>>(new ConcurrentHashMap<String, Reference<Class<?>>>()));
70 }
71
72
73
74
75
76
77
78
79 public static ClassResolver softCachingConcurrentResolver(ClassLoader classLoader) {
80 return new CachingClassResolver(
81 new ClassLoaderClassResolver(defaultClassLoader(classLoader)),
82 new SoftReferenceMap<String, Class<?>>(new ConcurrentHashMap<String, Reference<Class<?>>>()));
83 }
84
85 static ClassLoader defaultClassLoader(ClassLoader classLoader) {
86 if (classLoader != null) {
87 return classLoader;
88 }
89
90 final ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
91 if (contextClassLoader != null) {
92 return contextClassLoader;
93 }
94
95 return ClassResolvers.class.getClassLoader();
96 }
97
98 private ClassResolvers() {
99
100 }
101 }