import java.util.concurrent.atomic.AtomicInteger;
/**
- * Invocation handler for thread-specific proxies.
+ * Invocation handler for thread-specific proxies.
*
* @author Erik Brakkee
- *
+ *
* @param <T>
*/
-class ThreadSpecificInvocationHandler<T> implements InvocationHandler, Serializable {
-
+class ThreadSpecificInvocationHandler<T> 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<Integer,ThreadLocal> STORAGE = initializeThreadLocal();
-
+ private static Map<Integer, ThreadLocal> STORAGE = initializeThreadLocal();
+
private static AtomicInteger COUNTER = new AtomicInteger();
-
+
private static Map<Integer, ThreadLocal> initializeThreadLocal() {
- Map<Integer,ThreadLocal> map = new ConcurrentHashMap<Integer,ThreadLocal>();
+ Map<Integer, ThreadLocal> map = new ConcurrentHashMap<Integer, ThreadLocal>();
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);
ThreadLocal<T> 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);