tapestry-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hls...@apache.org
Subject svn commit: r1130344 - in /tapestry/tapestry5/trunk: tapestry-core/src/main/java/org/apache/tapestry5/internal/transform/ tapestry-core/src/main/java/org/apache/tapestry5/services/ tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/services/
Date Wed, 01 Jun 2011 23:30:02 GMT
Author: hlship
Date: Wed Jun  1 23:30:02 2011
New Revision: 1130344

URL: http://svn.apache.org/viewvc?rev=1130344&view=rev
Log:
TAP5-1528: More (minor) speed/memory optimizations

Modified:
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/transform/UnclaimedFieldWorker.java
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/TapestryModule.java
    tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/services/PerthreadManagerImpl.java

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=1130344&r1=1130343&r2=1130344&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
Wed Jun  1 23:30:02 2011
@@ -1,4 +1,4 @@
-// Copyright 2006, 2007, 2010 The Apache Software Foundation
+// Copyright 2006, 2007, 2010, 2011 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.
@@ -19,26 +19,28 @@ import java.lang.reflect.Modifier;
 import org.apache.tapestry5.ComponentResources;
 import org.apache.tapestry5.internal.InternalComponentResources;
 import org.apache.tapestry5.internal.services.ComponentClassCache;
-import org.apache.tapestry5.ioc.services.FieldValueConduit;
 import org.apache.tapestry5.ioc.services.PerThreadValue;
 import org.apache.tapestry5.ioc.services.PerthreadManager;
 import org.apache.tapestry5.model.MutableComponentModel;
-import org.apache.tapestry5.services.ClassTransformation;
-import org.apache.tapestry5.services.ComponentClassTransformWorker;
-import org.apache.tapestry5.services.ComponentValueProvider;
-import org.apache.tapestry5.services.TransformField;
+import org.apache.tapestry5.plastic.ComputedValue;
+import org.apache.tapestry5.plastic.FieldConduit;
+import org.apache.tapestry5.plastic.InstanceContext;
+import org.apache.tapestry5.plastic.PlasticClass;
+import org.apache.tapestry5.plastic.PlasticField;
+import org.apache.tapestry5.services.transform.ComponentClassTransformWorker2;
+import org.apache.tapestry5.services.transform.TransformationSupport;
 
 /**
  * Designed to be just about the last worker in the pipeline. Its job is to convert each
otherwise unclaimed
  * field into a value stored in the {@link PerthreadManager}.
  */
-public final class UnclaimedFieldWorker implements ComponentClassTransformWorker
+public final class UnclaimedFieldWorker implements ComponentClassTransformWorker2
 {
     private final PerthreadManager perThreadManager;
 
     private final ComponentClassCache classCache;
 
-    static class UnclaimedFieldConduit implements FieldValueConduit
+    static class UnclaimedFieldConduit implements FieldConduit<Object>
     {
         private final InternalComponentResources resources;
 
@@ -56,12 +58,12 @@ public final class UnclaimedFieldWorker 
             this.fieldDefaultValue = fieldDefaultValue;
         }
 
-        public Object get()
+        public Object get(Object instance, InstanceContext context)
         {
             return fieldValue.get(fieldDefaultValue);
         }
 
-        public void set(Object newValue)
+        public void set(Object instance, InstanceContext context, Object newValue)
         {
             fieldValue.set(newValue);
 
@@ -71,7 +73,6 @@ public final class UnclaimedFieldWorker 
             if (!resources.isLoaded())
                 fieldDefaultValue = newValue;
         }
-
     }
 
     public UnclaimedFieldWorker(ComponentClassCache classCache, PerthreadManager perThreadManager)
@@ -80,36 +81,36 @@ public final class UnclaimedFieldWorker 
         this.perThreadManager = perThreadManager;
     }
 
-    public void transform(ClassTransformation transformation, MutableComponentModel model)
+    public void transform(PlasticClass plasticClass, TransformationSupport support, MutableComponentModel
model)
     {
-        for (TransformField field : transformation.matchUnclaimedFields())
+        for (PlasticField field : plasticClass.getUnclaimedFields())
         {
             transformField(field);
         }
     }
 
-    private void transformField(TransformField field)
+    private void transformField(PlasticField field)
     {
         int modifiers = field.getModifiers();
 
         if (Modifier.isFinal(modifiers) || Modifier.isStatic(modifiers))
             return;
 
-        ComponentValueProvider<FieldValueConduit> provider = createFieldValueConduitProvider(field);
+        ComputedValue<FieldConduit<?>> computed = createComputedFieldConduit(field);
 
-        field.replaceAccess(provider);
+        field.setComputedConduit(computed);
     }
 
-    private ComponentValueProvider<FieldValueConduit> createFieldValueConduitProvider(TransformField
field)
+    private ComputedValue<FieldConduit<?>> createComputedFieldConduit(PlasticField
field)
     {
-        final String fieldName = field.getName();
-        final String fieldType = field.getType();
+        final String fieldType = field.getTypeName();
 
-        return new ComponentValueProvider<FieldValueConduit>()
+        return new ComputedValue<FieldConduit<?>>()
         {
-            public FieldValueConduit get(ComponentResources resources)
+            public FieldConduit<?> get(InstanceContext context)
             {
                 Object fieldDefaultValue = classCache.defaultValueForType(fieldType);
+                ComponentResources resources = context.get(ComponentResources.class);
 
                 return new UnclaimedFieldConduit((InternalComponentResources) resources,
                         perThreadManager.createValue(), fieldDefaultValue);

Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/TapestryModule.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/TapestryModule.java?rev=1130344&r1=1130343&r2=1130344&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/TapestryModule.java
(original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/TapestryModule.java
Wed Jun  1 23:30:02 2011
@@ -200,6 +200,7 @@ import org.apache.tapestry5.ioc.services
 import org.apache.tapestry5.ioc.services.CoercionTuple;
 import org.apache.tapestry5.ioc.services.LazyAdvisor;
 import org.apache.tapestry5.ioc.services.MasterObjectProvider;
+import org.apache.tapestry5.ioc.services.PerThreadValue;
 import org.apache.tapestry5.ioc.services.PerthreadManager;
 import org.apache.tapestry5.ioc.services.PipelineBuilder;
 import org.apache.tapestry5.ioc.services.PlasticProxyFactory;
@@ -636,6 +637,8 @@ public final class TapestryModule
      * <dd>Generates accessor methods if {@link org.apache.tapestry5.annotations.Property}
annotation is present</dd> *
      * <dt>Import</dt>
      * <dd>Supports the {@link Import} annotation</dd>
+     * <dt>UnclaimedField</dt>
+     * <dd>Manages unclaimed fields, storing their value in a {@link PerThreadValue}</dd>
      * </ul>
      */
     @Contribute(ComponentClassTransformWorker2.class)
@@ -643,6 +646,12 @@ public final class TapestryModule
     {
         configuration.add("Property", new PropertyWorker());
         configuration.addInstance("Import", ImportWorker.class, "after:SetupRender");
+
+        // This one is always last. Any additional private fields that aren't
+        // annotated will
+        // be converted to clear out at the end of the request.
+
+        configuration.addInstance("UnclaimedField", UnclaimedFieldWorker.class, "after:*");
     }
 
     /**
@@ -675,8 +684,6 @@ public final class TapestryModule
      * <dd>Checks for meta data annotations and adds it to the component model</dd>
      * <dt>ApplicationState</dt>
      * <dd>Converts fields that reference application state objects
-     * <dt>UnclaimedField</dt>
-     * <dd>Identifies unclaimed fields and resets them to null/0/false at the end of
the request</dd>
      * <dt>RenderCommand</dt>
      * <dd>Ensures all components also implement {@link org.apache.tapestry5.runtime.RenderCommand}</dd>
      * <dt>RenderPhase</dt>
@@ -763,12 +770,6 @@ public final class TapestryModule
 
         configuration.addInstance("PageReset", PageResetAnnotationWorker.class);
 
-        // This one is always last. Any additional private fields that aren't
-        // annotated will
-        // be converted to clear out at the end of the request.
-
-        configuration.addInstance("UnclaimedField", UnclaimedFieldWorker.class, "after:*");
-
         configuration.add("PageActivationContext", new PageActivationContextWorker(), "after:OnEvent");
 
         configuration.addInstance("SessionAttribute", SessionAttributeWorker.class);

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=1130344&r1=1130343&r2=1130344&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
Wed Jun  1 23:30:02 2011
@@ -16,6 +16,7 @@ package org.apache.tapestry5.ioc.interna
 
 import java.util.List;
 import java.util.Map;
+import java.util.concurrent.atomic.AtomicInteger;
 import java.util.concurrent.locks.Lock;
 import java.util.concurrent.locks.ReentrantLock;
 
@@ -49,6 +50,8 @@ public class PerthreadManagerImpl implem
 
     private final MapHolder holder = new MapHolder();
 
+    private final AtomicInteger uuidGenerator = new AtomicInteger();
+
     public PerthreadManagerImpl(Logger logger)
     {
         this(logger, JDKUtils.JDK_1_5);
@@ -181,7 +184,7 @@ public class PerthreadManagerImpl implem
 
     public <T> PerThreadValue<T> createValue()
     {
-        return createValue(InternalUtils.nextUUID());
+        return createValue(uuidGenerator.getAndIncrement());
     }
 
     public void run(Runnable runnable)



Mime
View raw message