commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ohe...@apache.org
Subject svn commit: r1533963 - /commons/proper/beanutils/branches/java5/src/main/java/org/apache/commons/beanutils/ContextClassLoaderLocal.java
Date Sun, 20 Oct 2013 20:25:08 GMT
Author: oheger
Date: Sun Oct 20 20:25:07 2013
New Revision: 1533963

URL: http://svn.apache.org/r1533963
Log:
Generified ContextClassLoaderLocal.

Modified:
    commons/proper/beanutils/branches/java5/src/main/java/org/apache/commons/beanutils/ContextClassLoaderLocal.java

Modified: commons/proper/beanutils/branches/java5/src/main/java/org/apache/commons/beanutils/ContextClassLoaderLocal.java
URL: http://svn.apache.org/viewvc/commons/proper/beanutils/branches/java5/src/main/java/org/apache/commons/beanutils/ContextClassLoaderLocal.java?rev=1533963&r1=1533962&r2=1533963&view=diff
==============================================================================
--- commons/proper/beanutils/branches/java5/src/main/java/org/apache/commons/beanutils/ContextClassLoaderLocal.java
(original)
+++ commons/proper/beanutils/branches/java5/src/main/java/org/apache/commons/beanutils/ContextClassLoaderLocal.java
Sun Oct 20 20:25:07 2013
@@ -50,14 +50,14 @@ import java.util.WeakHashMap;
  * <p>Expected usage is as follows:<br>
  * <pre>
  *  public class SomeClass {
- *    private static final ContextClassLoaderLocal global
- *      = new ContextClassLoaderLocal() {
- *          protected Object initialValue() {
+ *    private static final ContextClassLoaderLocal&lt;String&gt; global
+ *      = new ContextClassLoaderLocal&lt;String&gt;() {
+ *          protected String initialValue() {
  *              return new String("Initial value");
  *          };
  *
  *    public void testGlobal() {
- *      String s = (String) global.get();
+ *      String s = global.get();
  *      System.out.println("global value:" + s);
  *      buf.set("New Value");
  *    }
@@ -97,13 +97,14 @@ import java.util.WeakHashMap;
  * containers required each component to load the full set of classes it
  * needs, ie avoided providing classes loaded via a "shared" classloader.</p>
  *
+ * @param <T> the type of data stored in an instance
  * @version $Id$
  * @see java.lang.Thread#getContextClassLoader
  */
-public class ContextClassLoaderLocal {
-    private final Map valueByClassLoader = new WeakHashMap();
+public class ContextClassLoaderLocal<T> {
+    private final Map<ClassLoader, T> valueByClassLoader = new WeakHashMap<ClassLoader,
T>();
     private boolean globalValueInitialized = false;
-    private Object globalValue;
+    private T globalValue;
 
     /**
      * Construct a context classloader instance
@@ -125,7 +126,7 @@ public class ContextClassLoaderLocal {
      *
      * @return a new Object to be used as an initial value for this ContextClassLoaderLocal
      */
-    protected Object initialValue() {
+    protected T initialValue() {
         return null;
     }
 
@@ -135,7 +136,7 @@ public class ContextClassLoaderLocal {
      * This mechanism provides isolation for web apps deployed in the same container.
      * @return the object currently associated with the context-classloader of the current
thread.
      */
-    public synchronized Object get() {
+    public synchronized T get() {
         // synchronizing the whole method is a bit slower
         // but guarantees no subtle threading problems, and there's no
         // need to synchronize valueByClassLoader
@@ -147,7 +148,7 @@ public class ContextClassLoaderLocal {
             ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
             if (contextClassLoader != null) {
 
-                Object value = valueByClassLoader.get(contextClassLoader);
+                T value = valueByClassLoader.get(contextClassLoader);
                 if ((value == null)
                 && !valueByClassLoader.containsKey(contextClassLoader)) {
                     value = initialValue();
@@ -173,7 +174,7 @@ public class ContextClassLoaderLocal {
      *
      * @param value the object to be associated with the entrant thread's context classloader
      */
-    public synchronized void set(Object value) {
+    public synchronized void set(T value) {
         // synchronizing the whole method is a bit slower
         // but guarentees no subtle threading problems
 



Mime
View raw message