tapestry-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hls...@apache.org
Subject svn commit: r964851 - in /tapestry/tapestry5/trunk: tapestry-core/src/main/java/org/apache/tapestry5/internal/structure/ tapestry-core/src/main/java/org/apache/tapestry5/internal/transform/ tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/s...
Date Fri, 16 Jul 2010 16:34:36 GMT
Author: hlship
Date: Fri Jul 16 16:34:36 2010
New Revision: 964851

URL: http://svn.apache.org/viewvc?rev=964851&view=rev
Log:
TAP5-1197: Use an internally generated unique Long key to access PerThreadValues (which will
be a more efficient Map key than a String), and make some other small optimizations

Modified:
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/structure/ComponentPageElementImpl.java
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/structure/ComponentPageElementResources.java
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/structure/ComponentPageElementResourcesImpl.java
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/structure/InternalComponentResourcesImpl.java
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/structure/PageImpl.java
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/transform/PersistWorker.java
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/transform/UnclaimedFieldWorker.java
    tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/services/PerThreadServiceCreator.java
    tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/services/PerThreadServiceLifecycle.java
    tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/services/PerthreadManagerImpl.java
    tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/util/InternalUtils.java
    tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/services/PerThreadValue.java
    tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/services/PerthreadManager.java
    tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/services/PerthreadManagerImplTest.java

Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/structure/ComponentPageElementImpl.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/structure/ComponentPageElementImpl.java?rev=964851&r1=964850&r2=964851&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/structure/ComponentPageElementImpl.java
(original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/structure/ComponentPageElementImpl.java
Fri Jul 16 16:34:36 2010
@@ -597,8 +597,8 @@ public class ComponentPageElementImpl ex
 
         eventLogger = elementResources.getEventLogger(coreResources.getLogger());
 
-        renderEvent = elementResources.createPerThreadValue("tapestry.internal.RenderEvent:"
+ completeId);
-        rendering = elementResources.createPerThreadValue("tapestry.internal.Rendering:"
+ completeId);
+        renderEvent = elementResources.createPerThreadValue();
+        rendering = elementResources.createPerThreadValue();
     }
 
     /**
@@ -1001,7 +1001,7 @@ public class ComponentPageElementImpl ex
 
     public boolean isRendering()
     {
-        return rendering.exists() && rendering.get();
+        return rendering.get(false);
     }
 
     /**
@@ -1289,9 +1289,9 @@ public class ComponentPageElementImpl ex
         if (result != null)
             return result;
 
-        // Create a per-thread value to use until the end of the render. 
+        // Create a per-thread value to use until the end of the render.
         // This assumes that the queue will not change during the current request,
-        // which should be valid. 
+        // which should be valid.
 
         result = new RenderPhaseEvent(new RenderPhaseEventHandler(queue), eventLogger);
 

Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/structure/ComponentPageElementResources.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/structure/ComponentPageElementResources.java?rev=964851&r1=964850&r2=964851&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/structure/ComponentPageElementResources.java
(original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/structure/ComponentPageElementResources.java
Fri Jul 16 16:34:36 2010
@@ -129,9 +129,9 @@ public interface ComponentPageElementRes
     Logger getEventLogger(Logger componentLogger);
 
     /**
-     * Wrapper around {@link PerthreadManager#createValue(Object)}.
+     * Wrapper around {@link PerthreadManager#createValue()}.
      * 
      * @since 5.2.0
      */
-    <T> PerThreadValue<T> createPerThreadValue(Object key);
+    <T> PerThreadValue<T> createPerThreadValue();
 }

Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/structure/ComponentPageElementResourcesImpl.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/structure/ComponentPageElementResourcesImpl.java?rev=964851&r1=964850&r2=964851&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/structure/ComponentPageElementResourcesImpl.java
(original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/structure/ComponentPageElementResourcesImpl.java
Fri Jul 16 16:34:36 2010
@@ -133,7 +133,7 @@ public class ComponentPageElementResourc
 
     private Object[] defaulted(Object[] context)
     {
-        return context == null ? InternalConstants.EMPTY_STRING_ARRAY: context;
+        return context == null ? InternalConstants.EMPTY_STRING_ARRAY : context;
     }
 
     public <T> T invoke(String description, Invokable<T> operation)
@@ -146,9 +146,9 @@ public class ComponentPageElementResourc
         tracker.run(description, operation);
     }
 
-    public <T> PerThreadValue<T> createPerThreadValue(Object key)
+    public <T> PerThreadValue<T> createPerThreadValue()
     {
-        return perThreadManager.createValue(key);
+        return perThreadManager.createValue();
     }
 
 }

Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/structure/InternalComponentResourcesImpl.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/structure/InternalComponentResourcesImpl.java?rev=964851&r1=964850&r2=964851&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/structure/InternalComponentResourcesImpl.java
(original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/structure/InternalComponentResourcesImpl.java
Fri Jul 16 16:34:36 2010
@@ -464,8 +464,7 @@ public class InternalComponentResourcesI
     private synchronized Map<String, Object> getRenderVariables()
     {
         if (renderVariables == null)
-            renderVariables = elementResources.createPerThreadValue("tapestry.internal.RenderVariables:"
-                    + getCompleteId());
+            renderVariables = elementResources.createPerThreadValue();
 
         Map<String, Object> result = renderVariables.get();
 

Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/structure/PageImpl.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/structure/PageImpl.java?rev=964851&r1=964850&r2=964851&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/structure/PageImpl.java
(original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/structure/PageImpl.java
Fri Jul 16 16:34:36 2010
@@ -77,14 +77,14 @@ public class PageImpl implements Page
 
         if (pooled)
         {
-            dirtyCount = perThreadManager.createValue("PageDirtyCount:" + name);
+            dirtyCount = perThreadManager.createValue();
         }
         else
         {
             dirtyCount = null;
         }
 
-        fieldBundle = perThreadManager.createValue("PersistentFieldBundle:" + name);
+        fieldBundle = perThreadManager.createValue();
     }
 
     @Override
@@ -227,7 +227,7 @@ public class PageImpl implements Page
     {
         if (dirtyCount != null)
         {
-            int newCount = dirtyCount.exists() ? dirtyCount.get() + 1 : 1;
+            int newCount = dirtyCount.get(0) + 1;
 
             dirtyCount.set(newCount);
         }

Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/transform/PersistWorker.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/transform/PersistWorker.java?rev=964851&r1=964850&r2=964851&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/transform/PersistWorker.java
(original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/transform/PersistWorker.java
Fri Jul 16 16:34:36 2010
@@ -65,10 +65,7 @@ public class PersistWorker implements Co
 
         public Object get()
         {
-            if (!fieldValue.exists())
-                return defaultValue;
-
-            return fieldValue.get();
+            return fieldValue.get(defaultValue);
         }
 
         public void set(Object newValue)
@@ -119,10 +116,8 @@ public class PersistWorker implements Co
         {
             public FieldValueConduit get(ComponentResources resources)
             {
-                String key = String.format("PersistWorker:%s/%s", resources.getCompleteId(),
logicalFieldName);
-
                 return new PersistentFieldConduit((InternalComponentResources) resources,
logicalFieldName,
-                        perThreadManager.createValue(key), defaultValue);
+                        perThreadManager.createValue(), defaultValue);
             }
         };
 

Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/transform/UnclaimedFieldWorker.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/transform/UnclaimedFieldWorker.java?rev=964851&r1=964850&r2=964851&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/transform/UnclaimedFieldWorker.java
(original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/transform/UnclaimedFieldWorker.java
Fri Jul 16 16:34:36 2010
@@ -58,7 +58,7 @@ public final class UnclaimedFieldWorker 
 
         public Object get()
         {
-            return fieldValue.exists() ? fieldValue.get() : fieldDefaultValue;
+            return fieldValue.get(fieldDefaultValue);
         }
 
         public void set(Object newValue)
@@ -111,10 +111,8 @@ public final class UnclaimedFieldWorker 
             {
                 Object fieldDefaultValue = classCache.defaultValueForType(fieldType);
 
-                String key = String.format("UnclaimedFieldWorker:%s/%s", resources.getCompleteId(),
fieldName);
-
                 return new UnclaimedFieldConduit((InternalComponentResources) resources,
-                        perThreadManager.createValue(key), fieldDefaultValue);
+                        perThreadManager.createValue(), fieldDefaultValue);
             }
         };
     }

Modified: tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/services/PerThreadServiceCreator.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/services/PerThreadServiceCreator.java?rev=964851&r1=964850&r2=964851&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/services/PerThreadServiceCreator.java
(original)
+++ tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/services/PerThreadServiceCreator.java
Fri Jul 16 16:34:36 2010
@@ -1,10 +1,10 @@
-// Copyright 2006, 2008 The Apache Software Foundation
+// Copyright 2006, 2008, 2010 The Apache Software Foundation
 //
 // Licensed under the Apache License, Version 2.0 (the "License");
 // you may not use this file except in compliance with the License.
 // You may obtain a copy of the License at
 //
-//     http://www.apache.org/licenses/LICENSE-2.0
+// http://www.apache.org/licenses/LICENSE-2.0
 //
 // Unless required by applicable law or agreed to in writing, software
 // distributed under the License is distributed on an "AS IS" BASIS,
@@ -15,6 +15,7 @@
 package org.apache.tapestry5.ioc.internal.services;
 
 import org.apache.tapestry5.ioc.ObjectCreator;
+import org.apache.tapestry5.ioc.services.PerThreadValue;
 import org.apache.tapestry5.ioc.services.PerthreadManager;
 
 /**
@@ -22,33 +23,27 @@ import org.apache.tapestry5.ioc.services
  */
 public class PerThreadServiceCreator implements ObjectCreator
 {
-    private final PerthreadManager perthreadManager;
+    private final PerThreadValue<Object> perThreadValue;
 
     private final ObjectCreator delegate;
 
     public PerThreadServiceCreator(PerthreadManager perthreadManager, ObjectCreator delegate)
     {
-        this.perthreadManager = perthreadManager;
+        perThreadValue = perthreadManager.createValue();
+
         this.delegate = delegate;
     }
 
     /**
-     * For each thread, the first call will use the delegate {@link org.apache.tapestry5.ioc.ObjectCreator}
to create an
-     * instance, and later calls will reuse the same per-thread instance. The instance is
stored in the {@link
-     * org.apache.tapestry5.ioc.services.PerthreadManager} and will be released at the end
of the request.
+     * For each thread, the first call will use the delegate {@link org.apache.tapestry5.ioc.ObjectCreator}
to create
+     * an instance, and later calls will reuse the same per-thread instance. The instance
is stored in the
+     * {@link org.apache.tapestry5.ioc.services.PerthreadManager} and will be released at
the end of the request.
      */
     public Object createObject()
     {
-        // Use the ObjectCreator instance as the key.  it will be unique.
-
-        Object perthreadInstance = perthreadManager.get(delegate);
-
-        if (perthreadInstance == null)
-        {
-            perthreadInstance = delegate.createObject();
-            perthreadManager.put(delegate, perthreadInstance);
-        }
+        if (perThreadValue.exists())
+            return perThreadValue.get();
 
-        return perthreadInstance;
+        return perThreadValue.set(delegate.createObject());
     }
 }

Modified: tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/services/PerThreadServiceLifecycle.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/services/PerThreadServiceLifecycle.java?rev=964851&r1=964850&r2=964851&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/services/PerThreadServiceLifecycle.java
(original)
+++ tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/services/PerThreadServiceLifecycle.java
Fri Jul 16 16:34:36 2010
@@ -1,4 +1,4 @@
-// Copyright 2006, 2007, 2008, 2009 The Apache Software Foundation
+// Copyright 2006, 2007, 2008, 2009, 2010 The Apache Software Foundation
 //
 // Licensed under the Apache License, Version 2.0 (the "License");
 // you may not use this file except in compliance with the License.
@@ -33,6 +33,7 @@ import java.lang.reflect.Modifier;
  * application, the service decoration process occurs only once. The final calling chain
is: Service Proxy --&gt;
  * Decorator(s) --&gt; PerThread Proxy --&gt; (per thread) instance.
  */
+@SuppressWarnings("all")
 public class PerThreadServiceLifecycle implements ServiceLifecycle
 {
     private static final String PER_THREAD_METHOD_NAME = "_perThreadInstance";

Modified: tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/services/PerthreadManagerImpl.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/services/PerthreadManagerImpl.java?rev=964851&r1=964850&r2=964851&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/services/PerthreadManagerImpl.java
(original)
+++ tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/services/PerthreadManagerImpl.java
Fri Jul 16 16:34:36 2010
@@ -21,12 +21,14 @@ import java.util.concurrent.locks.Reentr
 
 import org.apache.tapestry5.ioc.internal.util.CollectionFactory;
 import org.apache.tapestry5.ioc.internal.util.DummyLock;
+import org.apache.tapestry5.ioc.internal.util.InternalUtils;
 import org.apache.tapestry5.ioc.internal.util.JDKUtils;
 import org.apache.tapestry5.ioc.services.PerThreadValue;
 import org.apache.tapestry5.ioc.services.PerthreadManager;
 import org.apache.tapestry5.ioc.services.ThreadCleanupListener;
 import org.slf4j.Logger;
 
+@SuppressWarnings("all")
 public class PerthreadManagerImpl implements PerthreadManager
 {
     private static final String LISTENERS_KEY = "PerthreadManager.listenerList";
@@ -130,7 +132,6 @@ public class PerthreadManagerImpl implem
         }
     }
 
-    @SuppressWarnings("unchecked")
     public void put(Object key, Object value)
     {
         getPerthreadMap().put(key, value);
@@ -143,19 +144,30 @@ public class PerthreadManagerImpl implem
 
     private static Object NULL_VALUE = new Object();
 
-    public <T> PerThreadValue<T> createValue(final Object key)
+    <T> PerThreadValue<T> createValue(final Object key)
     {
         return new PerThreadValue<T>()
         {
-            @SuppressWarnings("unchecked")
             public T get()
             {
-                Object storedValue = PerthreadManagerImpl.this.get(key);
+                return get(null);
+            }
+
+            public T get(T defaultValue)
+            {
+                Map map = getPerthreadMap();
+
+                if (map.containsKey(key))
+                {
+                    Object storedValue = map.get(key);
 
-                if (storedValue == NULL_VALUE)
-                    return null;
+                    if (storedValue == NULL_VALUE)
+                        return null;
 
-                return (T) storedValue;
+                    return (T) storedValue;
+                }
+
+                return defaultValue;
             }
 
             public T set(T newValue)
@@ -172,4 +184,9 @@ public class PerthreadManagerImpl implem
         };
     }
 
+    public <T> PerThreadValue<T> createValue()
+    {
+        return createValue(InternalUtils.nextUUID());
+    }
+
 }

Modified: tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/util/InternalUtils.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/util/InternalUtils.java?rev=964851&r1=964850&r2=964851&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/util/InternalUtils.java
(original)
+++ tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/util/InternalUtils.java
Fri Jul 16 16:34:36 2010
@@ -29,6 +29,7 @@ import java.lang.reflect.Modifier;
 import java.lang.reflect.Type;
 import java.net.URL;
 import java.util.*;
+import java.util.concurrent.atomic.AtomicLong;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
@@ -1022,4 +1023,17 @@ public class InternalUtils
             }
         };
     }
+
+    private static final AtomicLong uuidGenerator = new AtomicLong(System.nanoTime());
+
+    /**
+     * Generates a unique value for the current execution of the application. This initial
UUID value
+     * is not easily predicatable; subsequent UUIDs are allocated in ascending series.
+     * 
+     * @since 5.2.0
+     */
+    public static long nextUUID()
+    {
+        return uuidGenerator.incrementAndGet();
+    }
 }

Modified: tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/services/PerThreadValue.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/services/PerThreadValue.java?rev=964851&r1=964850&r2=964851&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/services/PerThreadValue.java
(original)
+++ tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/services/PerThreadValue.java
Fri Jul 16 16:34:36 2010
@@ -23,10 +23,16 @@ public interface PerThreadValue<T>
 {
     /** Is a value stored (even null)? */
     boolean exists();
-    
+
     /** Reads the current per-thread value, or returns null if no value has been stored.
*/
     T get();
 
+    /**
+     * Gets the current per-thread value if it exists (even if null), or the defaultValue
+     * if no value has been stored.
+     */
+    T get(T defaultValue);
+
     /** Sets the current per-thread value, then returns that value. */
     T set(T newValue);
 }

Modified: tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/services/PerthreadManager.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/services/PerthreadManager.java?rev=964851&r1=964850&r2=964851&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/services/PerthreadManager.java
(original)
+++ tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/services/PerthreadManager.java
Fri Jul 16 16:34:36 2010
@@ -46,14 +46,21 @@ public interface PerthreadManager
      * @param key
      *            key used to retrieve object
      * @return corresponding per-thread object, or null
+     * @deprecated use {@link PerthreadManager#createValue()} instead
      */
     Object get(Object key);
 
     /**
      * Stores a value into the per-thread map.
+     * 
+     * @deprecated use {@link PerthreadManager#createValue()} instead
      */
     void put(Object key, Object value);
 
-    /** Creates an object that captures the key, making it easier to get or set per-thread
values. */
-    <T> PerThreadValue<T> createValue(Object key);
+    /**
+     * Creates a value using a unique internal key.
+     * 
+     * @since 5.2.0
+     */
+    <T> PerThreadValue<T> createValue();
 }

Modified: tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/services/PerthreadManagerImplTest.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/services/PerthreadManagerImplTest.java?rev=964851&r1=964850&r2=964851&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/services/PerthreadManagerImplTest.java
(original)
+++ tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/services/PerthreadManagerImplTest.java
Fri Jul 16 16:34:36 2010
@@ -139,7 +139,29 @@ public class PerthreadManagerImplTest ex
         assertSame(m.get(key), value);
         assertSame(v.get(), value);
     }
-    
+
+    @Test
+    public void get_with_default()
+    {
+        PerthreadManagerImpl m = new PerthreadManagerImpl(null);
+
+        PerThreadValue<Object> v = m.createValue(new Object());
+
+        Object def = new Object();
+
+        assertSame(v.get(def), def);
+
+        v.set(null);
+
+        assertNull(v.get(def));
+
+        Object x = new Object();
+
+        v.set(x);
+
+        assertSame(v.get(def), x);
+    }
+
     @Test
     public void per_thread_null()
     {
@@ -148,9 +170,9 @@ public class PerthreadManagerImplTest ex
         PerThreadValue<Object> v = m.createValue(new Object());
 
         v.set(null);
-        
+
         assertTrue(v.exists());
-        
+
         assertNull(v.get());
     }
 }



Mime
View raw message