|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.curjent.impl.agent.ProxyCache
final class ProxyCache
Cache for generated proxy classes. WeakReference
is used to ensure
proxy classes and related objects, such as the ClassLoader
, are
eligible for garbage collection.
The cache uses a hierarchical structure. The top-level key is the proxy's
ClassLoader
. Otherwise identical proxies are distinct if they
were loaded by different class loaders. The next level is a synthetic key
created to uniquely identify the proxy based on its interfaces and task type
(see getKey(String[], String)
). The final level is the cached value.
This is the ProxyInfo
used by ProxyFactory
to create new
proxy instances.
This class is thread-safe.
Field Summary | |
---|---|
private Map<ClassLoader,ConcurrentMap<String,Reference<ProxyInfo>>> |
cache
Maps class loaders and proxy keys to cached ProxyInfo
instances. |
private Lock |
lock
Lock for accessing the top-level map. |
Constructor Summary | |
---|---|
ProxyCache()
|
Method Summary | |
---|---|
(package private) ProxyInfo |
get(ClassLoader classLoader,
String proxyKey)
Returns the cached proxy info for the given class loader and key. |
(package private) static String |
getKey(String[] interfaceNames,
String taskName)
Generates a unique caching key for the agent's interfaces and task type. |
(package private) ProxyInfo |
put(ClassLoader classLoader,
String proxyKey,
ProxyInfo proxyInfo)
Caches a proxy's info. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
private final Map<ClassLoader,ConcurrentMap<String,Reference<ProxyInfo>>> cache
ProxyInfo
instances.
getKey(String[], String)
private final Lock lock
ConcurrentMap
for thread safety.
Constructor Detail |
---|
ProxyCache()
Method Detail |
---|
static String getKey(String[] interfaceNames, String taskName)
ProxyInfo get(ClassLoader classLoader, String proxyKey)
null
if not found.
ProxyInfo put(ClassLoader classLoader, String proxyKey, ProxyInfo proxyInfo)
This algorithm avoids having to add a placeholder. Using a placeholder algorithm would add more complexity. Thread waiting and notification would have to be implemented. And the solution and its use would have to be carefully implemented by multiple classes to handle and recover from errors.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |