Author: hlship
Date: Tue May  3 23:18:09 2011
New Revision: 1099294

URL: http://svn.apache.org/viewvc?rev=1099294&view=rev
Log:
TAP5-1519: Ensure that all calls to invoke methods and constructors with 
dependencies are tracked with the OperationTracker

Modified:
    
tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/AbstractMethodInvokingInstrumenter.java
    
tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/ConstructorServiceCreator.java
    
tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/RegistryImpl.java
    
tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/ServiceBuilderMethodInvoker.java

Modified: 
tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/AbstractMethodInvokingInstrumenter.java
URL: 
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/AbstractMethodInvokingInstrumenter.java?rev=1099294&r1=1099293&r2=1099294&view=diff
==============================================================================
--- 
tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/AbstractMethodInvokingInstrumenter.java
 (original)
+++ 
tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/AbstractMethodInvokingInstrumenter.java
 Tue May  3 23:18:09 2011
@@ -14,6 +14,7 @@
 
 package org.apache.tapestry5.ioc.internal;
 
+import org.apache.tapestry5.ioc.Invokable;
 import org.apache.tapestry5.ioc.ModuleBuilderSource;
 import org.apache.tapestry5.ioc.ObjectLocator;
 import org.apache.tapestry5.ioc.OperationTracker;
@@ -83,34 +84,47 @@ public class AbstractMethodInvokingInstr
         return InternalUtils.isStatic(method) ? null : 
moduleSource.getModuleBuilder();
     }
 
-    protected Object invoke(InjectionResources injectionResources)
+    protected Object invoke(final InjectionResources injectionResources)
     {
-        Object result = null;
-        Throwable failure = null;
+        final String methodId = toString();
 
-        if (logger.isDebugEnabled())
-            logger.debug(String.format("Invoking method %s", this));
-
-        try
-        {
-            Object[] parameters = 
InternalUtils.calculateParametersForMethod(method, resources, 
injectionResources,
-                    resources.getTracker());
+        String description = String.format("Invoking method %s", methodId);
 
-            result = method.invoke(getModuleInstance(), parameters);
-        }
-        catch (InvocationTargetException ite)
-        {
-            failure = ite.getTargetException();
-        }
-        catch (Exception ex)
+        if (logger.isDebugEnabled())
         {
-            failure = ex;
+            logger.debug(description);
         }
 
-        if (failure != null)
-            throw new RuntimeException(String.format("Exception invoking 
method %s: %s", this,
-                    InternalUtils.toMessage(failure)), failure);
+        return resources.getTracker().invoke(description, new 
Invokable<Object>()
+        {
+            public Object invoke()
+            {
+                Object result = null;
+                Throwable failure = null;
+
+                try
+                {
+                    Object[] parameters = 
InternalUtils.calculateParametersForMethod(method, resources,
+                            injectionResources, resources.getTracker());
+
+                    result = method.invoke(getModuleInstance(), parameters);
+                }
+                catch (InvocationTargetException ite)
+                {
+                    failure = ite.getTargetException();
+                }
+                catch (Exception ex)
+                {
+                    failure = ex;
+                }
+
+                if (failure != null)
+                    throw new RuntimeException(String.format("Exception 
invoking method %s: %s", methodId,
+                            InternalUtils.toMessage(failure)), failure);
+
+                return result;
+            }
+        });
 
-        return result;
     }
 }

Modified: 
tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/ConstructorServiceCreator.java
URL: 
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/ConstructorServiceCreator.java?rev=1099294&r1=1099293&r2=1099294&view=diff
==============================================================================
--- 
tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/ConstructorServiceCreator.java
 (original)
+++ 
tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/ConstructorServiceCreator.java
 Tue May  3 23:18:09 2011
@@ -1,10 +1,10 @@
-// Copyright 2007, 2008 The Apache Software Foundation
+// Copyright 2007, 2008, 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.
 // 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,
@@ -14,6 +14,7 @@
 
 package org.apache.tapestry5.ioc.internal;
 
+import org.apache.tapestry5.ioc.Invokable;
 import org.apache.tapestry5.ioc.ServiceBuilderResources;
 import org.apache.tapestry5.ioc.internal.util.InjectionResources;
 import org.apache.tapestry5.ioc.internal.util.InternalUtils;
@@ -29,7 +30,7 @@ public class ConstructorServiceCreator e
     private final Constructor constructor;
 
     public ConstructorServiceCreator(ServiceBuilderResources resources, String 
creatorDescription,
-                                     Constructor constructor)
+            Constructor constructor)
     {
         super(resources, creatorDescription);
 
@@ -44,39 +45,47 @@ public class ConstructorServiceCreator e
 
     public Object createObject()
     {
-        Throwable failure = null;
-        Object result = null;
-
-        InternalUtils.validateConstructorForAutobuild(constructor);
-
-        InjectionResources injectionResources = createInjectionResources();
-
-        try
-        {
-            Object[] parameters = 
InternalUtils.calculateParametersForConstructor(constructor, resources,
-                                                                               
   injectionResources,
-                                                                               
   resources.getTracker());
-
-            if (logger.isDebugEnabled()) 
logger.debug(IOCMessages.invokingConstructor(creatorDescription));
-
-            result = constructor.newInstance(parameters);
-
-            InternalUtils.injectIntoFields(result, resources, 
injectionResources, resources.getTracker());
-        }
-        catch (InvocationTargetException ite)
-        {
-            failure = ite.getTargetException();
-        }
-        catch (Exception ex)
+        return resources.getTracker().invoke("Invoking " + creatorDescription, 
new Invokable<Object>()
         {
-            failure = ex;
-        }
-
-        if (failure != null)
-            throw new 
RuntimeException(IOCMessages.constructorError(creatorDescription, serviceId, 
failure), failure);
-
-        InternalUtils.invokePostInjectionMethods(result, resources, 
injectionResources, resources.getTracker());
+            public Object invoke()
+            {
+                Throwable failure = null;
+                Object result = null;
+
+                InternalUtils.validateConstructorForAutobuild(constructor);
+
+                InjectionResources injectionResources = 
createInjectionResources();
+
+                try
+                {
+                    Object[] parameters = 
InternalUtils.calculateParametersForConstructor(constructor, resources,
+                            injectionResources, resources.getTracker());
+
+                    if (logger.isDebugEnabled())
+                        
logger.debug(IOCMessages.invokingConstructor(creatorDescription));
+
+                    result = constructor.newInstance(parameters);
+
+                    InternalUtils.injectIntoFields(result, resources, 
injectionResources, resources.getTracker());
+                }
+                catch (InvocationTargetException ite)
+                {
+                    failure = ite.getTargetException();
+                }
+                catch (Exception ex)
+                {
+                    failure = ex;
+                }
+
+                if (failure != null)
+                    throw new 
RuntimeException(IOCMessages.constructorError(creatorDescription, serviceId, 
failure),
+                            failure);
+
+                InternalUtils.invokePostInjectionMethods(result, resources, 
injectionResources, resources.getTracker());
+
+                return result;
+            }
+        });
 
-        return result;
     }
 }

Modified: 
tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/RegistryImpl.java
URL: 
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/RegistryImpl.java?rev=1099294&r1=1099293&r2=1099294&view=diff
==============================================================================
--- 
tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/RegistryImpl.java
 (original)
+++ 
tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/RegistryImpl.java
 Tue May  3 23:18:09 2011
@@ -1051,7 +1051,8 @@ public class RegistryImpl implements Reg
             }
         };
 
-        return proxyFactory.createProxy(interfaceClass, justInTime, 
String.format("<Autobuild proxy %s(%s)>", implementationClass.getName(), 
interfaceClass.getName()));
+        return proxyFactory.createProxy(interfaceClass, justInTime,
+                String.format("<Autobuild proxy %s(%s)>", 
implementationClass.getName(), interfaceClass.getName()));
     }
 
     private <T> T createReloadingProxy(Class<T> interfaceClass, final Class<? 
extends T> implementationClass,
@@ -1062,7 +1063,8 @@ public class RegistryImpl implements Reg
 
         getService(UpdateListenerHub.class).addUpdateListener(creator);
 
-        return proxyFactory.createProxy(interfaceClass, (ObjectCreator<T>) 
creator, String.format("<Autoreload proxy %s(%s)>", 
implementationClass.getName(), interfaceClass.getName()));
+        return proxyFactory.createProxy(interfaceClass, (ObjectCreator<T>) 
creator,
+                String.format("<Autoreload proxy %s(%s)>", 
implementationClass.getName(), interfaceClass.getName()));
     }
 
     public Object provideServiceProxy(String serviceId)

Modified: 
tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/ServiceBuilderMethodInvoker.java
URL: 
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/ServiceBuilderMethodInvoker.java?rev=1099294&r1=1099293&r2=1099294&view=diff
==============================================================================
--- 
tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/ServiceBuilderMethodInvoker.java
 (original)
+++ 
tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/ServiceBuilderMethodInvoker.java
 Tue May  3 23:18:09 2011
@@ -1,10 +1,10 @@
-// Copyright 2006, 2007, 2008, 2009 The Apache Software Foundation
+// Copyright 2006, 2007, 2008, 2009, 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.
 // 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,
@@ -14,6 +14,8 @@
 
 package org.apache.tapestry5.ioc.internal;
 
+import org.apache.tapestry5.ioc.Invokable;
+import org.apache.tapestry5.ioc.OperationTracker;
 import org.apache.tapestry5.ioc.ServiceBuilderResources;
 import org.apache.tapestry5.ioc.internal.util.InternalUtils;
 
@@ -28,8 +30,7 @@ public class ServiceBuilderMethodInvoker
 {
     private final Method builderMethod;
 
-    public ServiceBuilderMethodInvoker(ServiceBuilderResources resources,
-                                       String creatorDescription, Method 
method)
+    public ServiceBuilderMethodInvoker(ServiceBuilderResources resources, 
String creatorDescription, Method method)
     {
         super(resources, creatorDescription);
 
@@ -44,46 +45,47 @@ public class ServiceBuilderMethodInvoker
         // Defer getting (and possibly instantitating) the module instance 
until the last possible
         // moment. If the method is static, there's no need to even get the 
builder.
 
-        Object moduleInstance = InternalUtils.isStatic(builderMethod)
-                                ? null
-                                : resources.getModuleBuilder();
+        final Object moduleInstance = InternalUtils.isStatic(builderMethod) ? 
null : resources.getModuleBuilder();
 
-        Object result = null;
-        Throwable failure = null;
+        final OperationTracker tracker = resources.getTracker();
 
-        try
+        return tracker.invoke(String.format("Invoking " + creatorDescription), 
new Invokable<Object>()
         {
-            Object[] parameters = InternalUtils.calculateParametersForMethod(
-                    builderMethod,
-                    resources,
-                    createInjectionResources(), resources.getTracker());
-
-            if (logger.isDebugEnabled())
-                logger.debug(IOCMessages.invokingMethod(creatorDescription));
-
-            result = builderMethod.invoke(moduleInstance, parameters);
-        }
-        catch (InvocationTargetException ite)
-        {
-            failure = ite.getTargetException();
-        }
-        catch (Exception ex)
-        {
-            failure = ex;
-        }
-
-        if (failure != null)
-            throw new RuntimeException(IOCMessages.builderMethodError(
-                    creatorDescription,
-                    serviceId,
-                    failure), failure);
-
-        if (result == null)
-            throw new RuntimeException(IOCMessages.builderMethodReturnedNull(
-                    creatorDescription,
-                    serviceId));
-
-        return result;
+            public Object invoke()
+            {
+                final OperationTracker tracker = resources.getTracker();
+                Object result = null;
+                Throwable failure = null;
+
+                try
+                {
+                    Object[] parameters = 
InternalUtils.calculateParametersForMethod(builderMethod, resources,
+                            createInjectionResources(), tracker);
+
+                    if (logger.isDebugEnabled())
+                        
logger.debug(IOCMessages.invokingMethod(creatorDescription));
+
+                    result = builderMethod.invoke(moduleInstance, parameters);
+                }
+                catch (InvocationTargetException ite)
+                {
+                    failure = ite.getTargetException();
+                }
+                catch (Exception ex)
+                {
+                    failure = ex;
+                }
+
+                if (failure != null)
+                    throw new 
RuntimeException(IOCMessages.builderMethodError(creatorDescription, serviceId, 
failure),
+                            failure);
+
+                if (result == null)
+                    throw new 
RuntimeException(IOCMessages.builderMethodReturnedNull(creatorDescription, 
serviceId));
+
+                return result;
+            }
+        });
     }
 
     @Override


Reply via email to