X-Git-Url: http://wamblee.org/gitweb/?a=blobdiff_plain;f=support%2Fgeneral%2Fsrc%2Fmain%2Fjava%2Forg%2Fwamblee%2Fgeneral%2FThreadSpecificInvocationHandler.java;h=c7c9952b9c902730418bba9e9c0b9b77f3b5fc49;hb=4a575582a5c2999bd816b197d9cf274b4b3ddcd7;hp=49c2e177c71a5af22b59b49b5c125ae17589c64b;hpb=7d3754ca3d757ef89241cdbd679f82941e64cfc6;p=utils diff --git a/support/general/src/main/java/org/wamblee/general/ThreadSpecificInvocationHandler.java b/support/general/src/main/java/org/wamblee/general/ThreadSpecificInvocationHandler.java index 49c2e177..c7c9952b 100644 --- a/support/general/src/main/java/org/wamblee/general/ThreadSpecificInvocationHandler.java +++ b/support/general/src/main/java/org/wamblee/general/ThreadSpecificInvocationHandler.java @@ -24,39 +24,43 @@ import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.atomic.AtomicInteger; /** - * Invocation handler for thread-specific proxies. + * Invocation handler for thread-specific proxies. * * @author Erik Brakkee - * + * * @param */ -class ThreadSpecificInvocationHandler implements InvocationHandler, Serializable { - +class ThreadSpecificInvocationHandler implements InvocationHandler, + Serializable { + /** - * We store a map of unique ids of invocation handlers to thread local storage of the - * service. In this way, serialiability of the generated proxy is obtained (required by - * framweorks such as wicket). Also, different factories will still be separate and never - * use the same threadlocal storage. + * We store a map of unique ids of invocation handlers to thread local + * storage of the service. In this way, serialiability of the generated + * proxy is obtained (required by framweorks such as wicket). Also, + * different factories will still be separate and never use the same + * threadlocal storage. */ - private static Map STORAGE = initializeThreadLocal(); - + private static Map STORAGE = initializeThreadLocal(); + private static AtomicInteger COUNTER = new AtomicInteger(); - + private static Map initializeThreadLocal() { - Map map = new ConcurrentHashMap(); + Map map = new ConcurrentHashMap(); return map; } - - private int id; - private Class clazz; - + private int id; + private Class clazz; + /** - * Constructs the handler. - * @param aSvc Thread local for the service. - * @param aClass Service interface class. + * Constructs the handler. + * + * @param aSvc + * Thread local for the service. + * @param aClass + * Service interface class. */ - public ThreadSpecificInvocationHandler(ThreadLocal aSvc, Class aClass) { + public ThreadSpecificInvocationHandler(ThreadLocal aSvc, Class aClass) { id = COUNTER.incrementAndGet(); clazz = aClass; STORAGE.put(id, aSvc); @@ -68,8 +72,9 @@ class ThreadSpecificInvocationHandler implements InvocationHandler, Serializa ThreadLocal local = STORAGE.get(id); T actualSvc = local.get(); - if ( aMethod.getName().equals("toString") && actualSvc == null) { - return "Thread-specific proxy for '" + clazz.getName() + "' id = " + id; + if (aMethod.getName().equals("toString") && actualSvc == null) { + return "Thread-specific proxy for '" + clazz.getName() + "' id = " + + id; } try { return aMethod.invoke(actualSvc, aArgs);