Author: hlship Date: Fri Sep 2 23:57:50 2011 New Revision: 1164764 URL: http://svn.apache.org/viewvc?rev=1164764&view=rev Log: TAP5-1627: Enable OperationTracker to produce debug trace of all operations
Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ComponentInstantiatorSourceImpl.java tapestry/tapestry5/trunk/tapestry-core/src/test/resources/log4j.properties tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/IOCMessages.java tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/ModuleImpl.java tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/OperationTrackerImpl.java tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/ReloadableObjectCreatorSource.java tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/util/InternalUtils.java tapestry/tapestry5/trunk/tapestry-ioc/src/main/resources/org/apache/tapestry5/ioc/internal/IOCStrings.properties tapestry/tapestry5/trunk/tapestry-ioc/src/test/resources/log4j.properties Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ComponentInstantiatorSourceImpl.java URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ComponentInstantiatorSourceImpl.java?rev=1164764&r1=1164763&r2=1164764&view=diff ============================================================================== --- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ComponentInstantiatorSourceImpl.java (original) +++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ComponentInstantiatorSourceImpl.java Fri Sep 2 23:57:50 2011 @@ -95,6 +95,9 @@ public final class ComponentInstantiator private final Map<String, ComponentModel> classToModel = CollectionFactory.newMap(); + private final MethodDescription GET_COMPONENT_RESOURCES = PlasticUtils.getMethodDescription( + ComponentResourcesAware.class, "getComponentResources"); + private final ConstructorCallback REGISTER_AS_PAGE_LIFECYCLE_LISTENER = new ConstructorCallback() { public void onConstruct(Object instance, InstanceContext context) @@ -326,9 +329,6 @@ public final class ComponentInstantiator }); } - private MethodDescription GET_COMPONENT_RESOURCES = PlasticUtils.getMethodDescription( - ComponentResourcesAware.class, "getComponentResources"); - private void implementComponentInterface(PlasticClass plasticClass) { plasticClass.introduceInterface(Component.class); Modified: tapestry/tapestry5/trunk/tapestry-core/src/test/resources/log4j.properties URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/resources/log4j.properties?rev=1164764&r1=1164763&r2=1164764&view=diff ============================================================================== --- tapestry/tapestry5/trunk/tapestry-core/src/test/resources/log4j.properties (original) +++ tapestry/tapestry5/trunk/tapestry-core/src/test/resources/log4j.properties Fri Sep 2 23:57:50 2011 @@ -1,17 +1,3 @@ -# Copyright 2005, 2006, 2007, 2008, 2009 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 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - log4j.rootCategory=INFO, A1 # A1 is set to be a ConsoleAppender. @@ -29,4 +15,5 @@ log4j.category.org.apache.tapestry5.inte # Turn off much of the racket from Selenium when it runs -log4j.category.org.openqa.selenium.server=warn \ No newline at end of file +log4j.category.org.openqa.selenium.server=warn +log4j.category.org.apache.tapestry5.ioc.Registry=debug Modified: tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/IOCMessages.java URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/IOCMessages.java?rev=1164764&r1=1164763&r2=1164764&view=diff ============================================================================== --- tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/IOCMessages.java (original) +++ tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/IOCMessages.java Fri Sep 2 23:57:50 2011 @@ -1,4 +1,4 @@ -// 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. @@ -54,11 +54,6 @@ final class IOCMessages .getReturnType().getCanonicalName()); } - public static String builderLocked() - { - return MESSAGES.get("builder-locked"); - } - static String serviceWrongInterface(String serviceId, Class actualInterface, Class requestedInterface) { return MESSAGES.format("service-wrong-interface", serviceId, actualInterface.getName(), @@ -115,11 +110,6 @@ final class IOCMessages serviceInterface.getName()); } - static String creatingService(String serviceId) - { - return MESSAGES.format("creating-service", serviceId); - } - static String invokingMethod(String methodId) { return MESSAGES.format("invoking-method", methodId); Modified: tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/ModuleImpl.java URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/ModuleImpl.java?rev=1164764&r1=1164763&r2=1164764&view=diff ============================================================================== --- tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/ModuleImpl.java (original) +++ tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/ModuleImpl.java Fri Sep 2 23:57:50 2011 @@ -14,7 +14,16 @@ package org.apache.tapestry5.ioc.internal; -import static java.lang.String.format; +import org.apache.tapestry5.ioc.*; +import org.apache.tapestry5.ioc.annotations.Local; +import org.apache.tapestry5.ioc.def.*; +import org.apache.tapestry5.ioc.internal.services.JustInTimeObjectCreator; +import org.apache.tapestry5.ioc.internal.util.*; +import org.apache.tapestry5.ioc.services.AspectDecorator; +import org.apache.tapestry5.ioc.services.PlasticProxyFactory; +import org.apache.tapestry5.ioc.services.Status; +import org.apache.tapestry5.plastic.*; +import org.slf4j.Logger; import java.io.ObjectStreamException; import java.io.Serializable; @@ -22,40 +31,9 @@ import java.lang.reflect.Constructor; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.lang.reflect.Modifier; -import java.util.Arrays; -import java.util.Collection; -import java.util.Comparator; -import java.util.Map; -import java.util.Set; +import java.util.*; -import org.apache.tapestry5.ioc.*; -import org.apache.tapestry5.ioc.annotations.Local; -import org.apache.tapestry5.ioc.def.ContributionDef; -import org.apache.tapestry5.ioc.def.ContributionDef2; -import org.apache.tapestry5.ioc.def.DecoratorDef; -import org.apache.tapestry5.ioc.def.ModuleDef; -import org.apache.tapestry5.ioc.def.ModuleDef2; -import org.apache.tapestry5.ioc.def.ServiceDef; -import org.apache.tapestry5.ioc.def.ServiceDef2; -import org.apache.tapestry5.ioc.def.ServiceDef3; -import org.apache.tapestry5.ioc.internal.services.JustInTimeObjectCreator; -import org.apache.tapestry5.ioc.internal.util.CollectionFactory; -import org.apache.tapestry5.ioc.internal.util.ConcurrentBarrier; -import org.apache.tapestry5.ioc.internal.util.InjectionResources; -import org.apache.tapestry5.ioc.internal.util.InternalUtils; -import org.apache.tapestry5.ioc.internal.util.MapInjectionResources; -import org.apache.tapestry5.ioc.services.AspectDecorator; -import org.apache.tapestry5.ioc.services.PlasticProxyFactory; -import org.apache.tapestry5.ioc.services.Status; -import org.apache.tapestry5.plastic.ClassInstantiator; -import org.apache.tapestry5.plastic.InstructionBuilder; -import org.apache.tapestry5.plastic.InstructionBuilderCallback; -import org.apache.tapestry5.plastic.MethodDescription; -import org.apache.tapestry5.plastic.PlasticClass; -import org.apache.tapestry5.plastic.PlasticClassTransformer; -import org.apache.tapestry5.plastic.PlasticField; -import org.apache.tapestry5.plastic.PlasticMethod; -import org.slf4j.Logger; +import static java.lang.String.format; @SuppressWarnings("all") public class ModuleImpl implements Module @@ -93,13 +71,15 @@ public class ModuleImpl implements Modul */ private final static ConcurrentBarrier BARRIER = new ConcurrentBarrier(); - /** "Magic" method related to Externalizable that allows the Proxy object to replace itself with the token. */ + /** + * "Magic" method related to Externalizable that allows the Proxy object to replace itself with the token. + */ private static final MethodDescription WRITE_REPLACE = new MethodDescription(Modifier.PRIVATE, "java.lang.Object", "writeReplace", null, null, new String[] - { ObjectStreamException.class.getName() }); + {ObjectStreamException.class.getName()}); public ModuleImpl(InternalRegistry registry, ServiceActivityTracker tracker, ModuleDef moduleDef, - PlasticProxyFactory proxyFactory, Logger logger) + PlasticProxyFactory proxyFactory, Logger logger) { this.registry = registry; this.tracker = tracker; @@ -131,8 +111,7 @@ public class ModuleImpl implements Modul try { return serviceInterface.cast(service); - } - catch (ClassCastException ex) + } catch (ClassCastException ex) { // This may be overkill: I don't know how this could happen // given that the return type of the method determines @@ -186,11 +165,9 @@ public class ModuleImpl implements Modul /** * Locates the service proxy for a particular service (from the service definition). - * - * @param def - * defines the service - * @param eagerLoadProxies - * collection into which proxies for eager loaded services are added (or null) + * + * @param def defines the service + * @param eagerLoadProxies collection into which proxies for eager loaded services are added (or null) * @return the service proxy */ private Object findOrCreate(final ServiceDef3 def, final Collection<EagerLoadServiceProxy> eagerLoadProxies) @@ -255,9 +232,8 @@ public class ModuleImpl implements Modul /** * Creates the service and updates the cache of created services. - * - * @param eagerLoadProxies - * a list into which any eager loaded proxies should be added + * + * @param eagerLoadProxies a list into which any eager loaded proxies should be added */ private Object create(final ServiceDef3 def, final Collection<EagerLoadServiceProxy> eagerLoadProxies) { @@ -265,7 +241,11 @@ public class ModuleImpl implements Modul final Logger logger = registry.getServiceLogger(serviceId); - String description = IOCMessages.creatingService(serviceId); + final Class serviceInterface = def.getServiceInterface(); + + String description = String.format("Creating %s service %s", + serviceInterface.isInterface() ? "proxy for" : "non-proxied instance of", + serviceId); if (logger.isDebugEnabled()) logger.debug(description); @@ -286,14 +266,13 @@ public class ModuleImpl implements Modul ObjectCreator creator = def.createServiceCreator(resources); - Class serviceInterface = def.getServiceInterface(); - - ServiceLifecycle2 lifecycle = registry.getServiceLifecycle(def.getServiceScope()); // For non-proxyable services, we immediately create the service implementation // and return it. There's no interface to proxy, which throws out the possibility of // deferred instantiation, service lifecycles, and decorators. + ServiceLifecycle2 lifecycle = registry.getServiceLifecycle(def.getServiceScope()); + if (!serviceInterface.isInterface()) { if (lifecycle.requiresProxy()) @@ -305,7 +284,7 @@ public class ModuleImpl implements Modul return creator.createObject(); } - creator = new OperationTrackingObjectCreator(registry, "Invoking service creator " + creator.toString(), creator); + creator = new OperationTrackingObjectCreator(registry, String.format("Realizing service %s via %s", serviceId, creator), creator); creator = new LifecycleWrappedServiceCreator(lifecycle, resources, creator); @@ -343,8 +322,7 @@ public class ModuleImpl implements Modul tracker.setStatus(serviceId, Status.VIRTUAL); return proxy; - } - catch (Exception ex) + } catch (Exception ex) { throw new RuntimeException(IOCMessages.errorBuildingService(serviceId, def, ex), ex); } @@ -453,16 +431,13 @@ public class ModuleImpl implements Modul InternalUtils.injectIntoFields(result, locator, resources, registry); return result; - } - catch (InvocationTargetException ex) + } catch (InvocationTargetException ex) { fail = ex.getTargetException(); - } - catch (Exception ex) + } catch (Exception ex) { fail = ex; - } - finally + } finally { insideConstructor = false; } @@ -483,7 +458,7 @@ public class ModuleImpl implements Modul } private Object createProxyInstance(final ObjectCreator creator, final ServiceProxyToken token, - final Class serviceInterface, final Class serviceImplementation, final String description) + final Class serviceInterface, final Class serviceImplementation, final String description) { ClassInstantiator instantiator = proxyFactory.createProxy(serviceInterface, new PlasticClassTransformer() { @@ -546,8 +521,7 @@ public class ModuleImpl implements Modul if (serviceDef.getServiceId().equalsIgnoreCase(def.getServiceId())) { result.add(def); - } - else + } else { if (markerMatched(serviceDef, def)) { Modified: tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/OperationTrackerImpl.java URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/OperationTrackerImpl.java?rev=1164764&r1=1164763&r2=1164764&view=diff ============================================================================== --- tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/OperationTrackerImpl.java (original) +++ tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/OperationTrackerImpl.java Fri Sep 2 23:57:50 2011 @@ -1,4 +1,4 @@ -// Copyright 2008, 2009, 2010 The Apache Software Foundation +// Copyright 2008, 2009, 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. @@ -23,7 +23,7 @@ import org.slf4j.Logger; /** * Core implementation that manages a logger and catches and reports exception. - * + * * @see org.apache.tapestry5.ioc.internal.PerThreadOperationTracker */ public class OperationTrackerImpl implements OperationTracker @@ -43,6 +43,7 @@ public class OperationTrackerImpl implem { assert InternalUtils.isNonBlank(description); assert operation != null; + invoke(description, new Invokable<Void>() { public Void invoke() @@ -58,29 +59,45 @@ public class OperationTrackerImpl implem { assert InternalUtils.isNonBlank(description); assert operation != null; + + long startNanos = System.nanoTime(); + + if (logger.isDebugEnabled()) + { + logger.debug(String.format("[%3d] --> %s", operations.getDepth() + 1, description)); + } + operations.push(description); try { - return operation.invoke(); - } - catch (RuntimeException ex) + T result = operation.invoke(); + + if (logger.isDebugEnabled()) + { + long elapsedNanos = System.nanoTime() - startNanos; + double elapsedMillis = ((double) elapsedNanos) / 1000000.d; + + logger.debug(String.format("[%3d] <-- %s [%,.2f ms]", operations.getDepth(), description, elapsedMillis)); + } + + return result; + + } catch (RuntimeException ex) { logAndRethrow(ex); throw ex; - } - catch (Error ex) + } catch (Error ex) { if (!logged) { log(ex); logged = true; } - + throw ex; - } - finally + } finally { operations.pop(); @@ -89,6 +106,8 @@ public class OperationTrackerImpl implem if (operations.isEmpty()) logged = false; } + + } private void logAndRethrow(Throwable ex) Modified: tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/ReloadableObjectCreatorSource.java URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/ReloadableObjectCreatorSource.java?rev=1164764&r1=1164763&r2=1164764&view=diff ============================================================================== --- tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/ReloadableObjectCreatorSource.java (original) +++ tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/internal/ReloadableObjectCreatorSource.java Fri Sep 2 23:57:50 2011 @@ -14,13 +14,13 @@ package org.apache.tapestry5.ioc.internal; -import java.lang.reflect.Method; - import org.apache.tapestry5.ioc.ObjectCreator; import org.apache.tapestry5.ioc.ServiceBuilderResources; import org.apache.tapestry5.ioc.services.PlasticProxyFactory; import org.apache.tapestry5.services.UpdateListenerHub; +import java.lang.reflect.Method; + /** * Responsible for creating a {@link ReloadableServiceImplementationObjectCreator} for a service implementation. */ @@ -38,7 +38,7 @@ public class ReloadableObjectCreatorSour private final boolean eagerLoad; public ReloadableObjectCreatorSource(PlasticProxyFactory proxyFactory, Method bindMethod, - Class serviceInterfaceClass, Class serviceImplementationClass, boolean eagerLoad) + Class serviceInterfaceClass, Class serviceImplementationClass, boolean eagerLoad) { this.proxyFactory = proxyFactory; this.bindMethod = bindMethod; @@ -47,6 +47,7 @@ public class ReloadableObjectCreatorSour this.eagerLoad = eagerLoad; } + public ObjectCreator constructCreator(final ServiceBuilderResources resources) { return new ObjectCreator() @@ -55,6 +56,12 @@ public class ReloadableObjectCreatorSour { return createReloadableProxy(resources); } + + @Override + public String toString() + { + return proxyFactory.getMethodLocation(bindMethod).toString(); + } }; } 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=1164764&r1=1164763&r2=1164764&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 Sep 2 23:57:50 2011 @@ -14,89 +14,41 @@ package org.apache.tapestry5.ioc.internal.util; +import org.apache.tapestry5.func.Mapper; +import org.apache.tapestry5.func.Predicate; +import org.apache.tapestry5.ioc.*; +import org.apache.tapestry5.ioc.annotations.*; +import org.apache.tapestry5.ioc.def.*; +import org.apache.tapestry5.ioc.internal.NullAnnotationProvider; +import org.apache.tapestry5.ioc.services.ClassFabUtils; +import org.apache.tapestry5.ioc.services.Coercion; +import org.apache.tapestry5.ioc.services.PlasticProxyFactory; +import org.apache.tapestry5.plastic.MethodAdvice; +import org.apache.tapestry5.plastic.MethodInvocation; +import org.apache.tapestry5.plastic.PlasticUtils; + +import javax.inject.Named; import java.io.Closeable; import java.io.IOException; import java.lang.annotation.Annotation; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; -import java.lang.reflect.AnnotatedElement; -import java.lang.reflect.Constructor; -import java.lang.reflect.Field; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.lang.reflect.Modifier; -import java.lang.reflect.Type; +import java.lang.reflect.*; import java.net.URL; -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; -import java.util.Comparator; -import java.util.Enumeration; -import java.util.Iterator; -import java.util.List; -import java.util.ListIterator; -import java.util.Map; -import java.util.Set; +import java.util.*; import java.util.concurrent.atomic.AtomicLong; import java.util.regex.Matcher; import java.util.regex.Pattern; -import javax.inject.Named; - -import org.apache.tapestry5.func.F; -import org.apache.tapestry5.func.Flow; -import org.apache.tapestry5.func.Mapper; -import org.apache.tapestry5.func.Predicate; -import org.apache.tapestry5.ioc.AdvisorDef; -import org.apache.tapestry5.ioc.AdvisorDef2; -import org.apache.tapestry5.ioc.AnnotationAccess; -import org.apache.tapestry5.ioc.AnnotationProvider; -import org.apache.tapestry5.ioc.Configuration; -import org.apache.tapestry5.ioc.IOCConstants; -import org.apache.tapestry5.ioc.Invokable; -import org.apache.tapestry5.ioc.Locatable; -import org.apache.tapestry5.ioc.Location; -import org.apache.tapestry5.ioc.MappedConfiguration; -import org.apache.tapestry5.ioc.ModuleBuilderSource; -import org.apache.tapestry5.ioc.ObjectCreator; -import org.apache.tapestry5.ioc.ObjectLocator; -import org.apache.tapestry5.ioc.OperationTracker; -import org.apache.tapestry5.ioc.OrderedConfiguration; -import org.apache.tapestry5.ioc.ServiceAdvisor; -import org.apache.tapestry5.ioc.ServiceBuilderResources; -import org.apache.tapestry5.ioc.ServiceDecorator; -import org.apache.tapestry5.ioc.ServiceLifecycle; -import org.apache.tapestry5.ioc.ServiceLifecycle2; -import org.apache.tapestry5.ioc.ServiceResources; -import org.apache.tapestry5.ioc.annotations.Inject; -import org.apache.tapestry5.ioc.annotations.InjectResource; -import org.apache.tapestry5.ioc.annotations.InjectService; -import org.apache.tapestry5.ioc.annotations.PostInjection; -import org.apache.tapestry5.ioc.annotations.ServiceId; -import org.apache.tapestry5.ioc.def.ContributionDef; -import org.apache.tapestry5.ioc.def.ContributionDef2; -import org.apache.tapestry5.ioc.def.DecoratorDef; -import org.apache.tapestry5.ioc.def.DecoratorDef2; -import org.apache.tapestry5.ioc.def.ModuleDef; -import org.apache.tapestry5.ioc.def.ModuleDef2; -import org.apache.tapestry5.ioc.def.ServiceDef; -import org.apache.tapestry5.ioc.def.ServiceDef2; -import org.apache.tapestry5.ioc.def.ServiceDef3; -import org.apache.tapestry5.ioc.internal.NullAnnotationProvider; -import org.apache.tapestry5.ioc.internal.services.AnnotationProviderChain; -import org.apache.tapestry5.ioc.services.ClassFabUtils; -import org.apache.tapestry5.ioc.services.Coercion; -import org.apache.tapestry5.ioc.services.PlasticProxyFactory; -import org.apache.tapestry5.plastic.MethodAdvice; -import org.apache.tapestry5.plastic.MethodInvocation; - /** * Utilities used within various internal implementations of the tapestry-ioc module. */ @SuppressWarnings("all") public class InternalUtils { - /** @since 5.2.2 */ + /** + * @since 5.2.2 + */ public static final boolean SERVICE_CLASS_RELOADING_ENABLED = Boolean.parseBoolean(System.getProperty( IOCConstants.SERVICE_CLASS_RELOADING_ENABLED, "true")); @@ -111,18 +63,18 @@ public class InternalUtils private static final Pattern NAME_PATTERN = Pattern.compile("^[_|$]*([\\p{javaJavaIdentifierPart}]+?)[_|$]*$", Pattern.CASE_INSENSITIVE); - /** @since 5.3 */ + /** + * @since 5.3 + */ public static AnnotationProvider NULL_ANNOTATION_PROVIDER = new NullAnnotationProvider(); /** * Converts a method to a user presentable string using a {@link PlasticProxyFactory} to obtain a {@link Location} * (where possible). {@link #asString(Method)} is used under the covers, to present a detailed, but not excessive, * description of the class, method and parameters. - * - * @param method - * method to convert to a string - * @param proxyFactory - * used to obtain the {@link Location} + * + * @param method method to convert to a string + * @param proxyFactory used to obtain the {@link Location} * @return the method formatted for presentation to the user */ public static String asString(Method method, PlasticProxyFactory proxyFactory) @@ -135,7 +87,7 @@ public class InternalUtils /** * Converts a method to a user presentable string consisting of the containing class name, the method name, and the * short form of the parameter list (the class name of each parameter type, shorn of the package name portion). - * + * * @param method * @return short string representation */ @@ -218,12 +170,10 @@ public class InternalUtils /** * Finds a specific annotation type within an array of annotations. - * + * * @param <T> - * @param annotations - * to search - * @param annotationClass - * to match + * @param annotations to search + * @param annotationClass to match * @return the annotation instance, if found, or null otherwise */ public static <T extends Annotation> T findAnnotation(Annotation[] annotations, Class<T> annotationClass) @@ -238,7 +188,7 @@ public class InternalUtils } private static Object calculateInjection(Class injectionType, Type genericType, final Annotation[] annotations, - ObjectLocator locator, InjectionResources resources) + ObjectLocator locator, InjectionResources resources) { AnnotationProvider provider = new AnnotationProvider() { @@ -262,7 +212,10 @@ public class InternalUtils Named named = provider.getAnnotation(Named.class); - if (named != null) { return locator.getService(named.value(), injectionType); } + if (named != null) + { + return locator.getService(named.value(), injectionType); + } // In the absence of @InjectService, try some autowiring. First, does the // parameter type match one of the resources (the parameter defaults)? @@ -282,7 +235,7 @@ public class InternalUtils } public static Object[] calculateParametersForMethod(Method method, ObjectLocator locator, - InjectionResources resources, OperationTracker tracker) + InjectionResources resources, OperationTracker tracker) { return calculateParameters(locator, resources, method.getParameterTypes(), method.getGenericParameterTypes(), @@ -290,7 +243,7 @@ public class InternalUtils } public static Object[] calculateParametersForConstructor(Constructor constructor, ObjectLocator locator, - InjectionResources resources, OperationTracker tracker) + InjectionResources resources, OperationTracker tracker) { return calculateParameters(locator, resources, constructor.getParameterTypes(), @@ -298,8 +251,8 @@ public class InternalUtils } public static Object[] calculateParameters(final ObjectLocator locator, final InjectionResources resources, - Class[] parameterTypes, final Type[] genericTypes, Annotation[][] parameterAnnotations, - OperationTracker tracker) + Class[] parameterTypes, final Type[] genericTypes, Annotation[][] parameterAnnotations, + OperationTracker tracker) { int parameterCount = parameterTypes.length; @@ -331,18 +284,14 @@ public class InternalUtils /** * Injects into the fields (of all visibilities) when the {@link org.apache.tapestry5.ioc.annotations.Inject} or * {@link org.apache.tapestry5.ioc.annotations.InjectService} annotations are present. - * - * @param object - * to be initialized - * @param locator - * used to resolve external dependencies - * @param resources - * provides injection resources for fields - * @param tracker - * track operations + * + * @param object to be initialized + * @param locator used to resolve external dependencies + * @param resources provides injection resources for fields + * @param tracker track operations */ public static void injectIntoFields(final Object object, final ObjectLocator locator, - final InjectionResources resources, OperationTracker tracker) + final InjectionResources resources, OperationTracker tracker) { Class clazz = object.getClass(); @@ -352,9 +301,11 @@ public class InternalUtils for (final Field f : fields) { - // Ignore all static fields. + // Ignore all static and final fields. - if (Modifier.isStatic(f.getModifiers())) + int fieldModifiers = f.getModifiers(); + + if (Modifier.isStatic(fieldModifiers) || Modifier.isFinal(fieldModifiers)) continue; final AnnotationProvider ap = new AnnotationProvider() @@ -365,8 +316,9 @@ public class InternalUtils } }; - String description = String.format("Calculating injection value for field '%s' (%s)", f.getName(), - ClassFabUtils.toJavaClassName(f.getType())); + String description = String.format("Calculating possible injection value for field %s.%s (%s)", + clazz.getName(), f.getName(), + PlasticUtils.toTypeName(f.getType())); tracker.run(description, new Runnable() { @@ -406,8 +358,7 @@ public class InternalUtils if (named == null) { inject(object, f, locator.getObject(fieldType, ap)); - } - else + } else { inject(object, f, locator.getService(named.value(), fieldType)); } @@ -426,7 +377,7 @@ public class InternalUtils } public static void invokePostInjectionMethods(final Object object, final ObjectLocator locator, - final InjectionResources injectionResources, final OperationTracker tracker) + final InjectionResources injectionResources, final OperationTracker tracker) { for (final Method m : object.getClass().getMethods()) { @@ -447,12 +398,10 @@ public class InternalUtils injectionResources, tracker); m.invoke(object, parameters); - } - catch (InvocationTargetException ex) + } catch (InvocationTargetException ex) { fail = ex.getTargetException(); - } - catch (Exception ex) + } catch (Exception ex) { fail = ex; } @@ -475,8 +424,7 @@ public class InternalUtils field.set(target, value); // Is there a need to setAccessible back to false? - } - catch (Exception ex) + } catch (Exception ex) { throw new RuntimeException(String.format("Unable to set field '%s' of %s to %s: %s", field.getName(), target, value, toMessage(ex))); @@ -494,11 +442,9 @@ public class InternalUtils /** * Joins together some number of elements. If a value in the list is the empty string, it is replaced with the * string "(blank)". - * - * @param elements - * objects to be joined together - * @param separator - * used between elements when joining + * + * @param elements objects to be joined together + * @param separator used between elements when joining */ public static String join(List elements, String separator) { @@ -536,7 +482,7 @@ public class InternalUtils /** * Creates a sorted copy of the provided elements, then turns that into a comma separated list. - * + * * @return the elements converted to strings, sorted, joined with comma ... or "(none)" if the elements are null or * empty */ @@ -570,7 +516,10 @@ public class InternalUtils public static boolean isEmptyCollection(Object input) { - if (input instanceof Collection) { return ((Collection) input).isEmpty(); } + if (input instanceof Collection) + { + return ((Collection) input).isEmpty(); + } return false; } @@ -612,9 +561,8 @@ public class InternalUtils /** * Extracts the string keys from a map and returns them in sorted order. The keys are converted to strings. - * - * @param map - * the map to extract keys from (may be null) + * + * @param map the map to extract keys from (may be null) * @return the sorted keys, or the empty set if map is null */ @@ -643,11 +591,10 @@ public class InternalUtils /** * Gets a value from a map (which may be null). - * + * * @param <K> * @param <V> - * @param map - * the map to extract from (may be null) + * @param map the map to extract from (may be null) * @param key * @return the value from the map, or null if the map is null */ @@ -723,9 +670,8 @@ public class InternalUtils * is not determined which will be returned (don't build a class like that!). In addition, if a constructor is * annotated with {@link org.apache.tapestry5.ioc.annotations.Inject}, it will be used (no check for multiple such * constructors is made, only at most a single constructor should have the annotation). - * - * @param clazz - * to search for a constructor for + * + * @param clazz to search for a constructor for * @return the constructor to be used to instantiate the class, or null if no appropriate constructor was found */ public static Constructor findAutobuildConstructor(Class clazz) @@ -783,7 +729,7 @@ public class InternalUtils } private static <T extends Annotation> Constructor findConstructorByAnnotation(Constructor[] constructors, - Class<T> annotationClass) + Class<T> annotationClass) { for (Constructor c : constructors) { @@ -797,17 +743,12 @@ public class InternalUtils /** * Adds a value to a specially organized map where the values are lists of objects. This somewhat simulates a map * that allows multiple values for the same key. - * - * @param map - * to store value into - * @param key - * for which a value is added - * @param value - * to add - * @param <K> - * the type of key - * @param <V> - * the type of the list + * + * @param map to store value into + * @param key for which a value is added + * @param value to add + * @param <K> the type of key + * @param <V> the type of the list */ public static <K, V> void addToMapList(Map<K, List<V>> map, K key, V value) { @@ -824,9 +765,8 @@ public class InternalUtils /** * Validates that the marker annotation class had a retention policy of runtime. - * - * @param markerClass - * the marker annotation class + * + * @param markerClass the marker annotation class */ public static void validateMarkerAnnotation(Class markerClass) { @@ -850,8 +790,7 @@ public class InternalUtils try { stream.close(); - } - catch (IOException ex) + } catch (IOException ex) { // Ignore. } @@ -859,9 +798,8 @@ public class InternalUtils /** * Extracts the message from an exception. If the exception's message is null, returns the exceptions class name. - * - * @param exception - * to extract message from + * + * @param exception to extract message from * @return message or class name */ public static String toMessage(Throwable exception) @@ -890,7 +828,9 @@ public class InternalUtils constructor)); } - /** @since 5.3 */ + /** + * @since 5.3 + */ public static final Mapper<Class, AnnotationProvider> CLASS_TO_AP_MAPPER = new Mapper<Class, AnnotationProvider>() { public AnnotationProvider map(final Class element) @@ -900,7 +840,9 @@ public class InternalUtils }; - /** @since 5.3 */ + /** + * @since 5.3 + */ public static AnnotationProvider toAnnotationProvider(final Class element) { return new AnnotationProvider() @@ -910,9 +852,13 @@ public class InternalUtils return annotationClass.cast(element.getAnnotation(annotationClass)); } }; - }; + } + + ; - /** @since 5.3 */ + /** + * @since 5.3 + */ public static final Mapper<Method, AnnotationProvider> METHOD_TO_AP_MAPPER = new Mapper<Method, AnnotationProvider>() { public AnnotationProvider map(final Method element) @@ -929,18 +875,18 @@ public class InternalUtils try { return containingClass.getMethod(methodName, parameterTypes); - } - catch (SecurityException ex) + } catch (SecurityException ex) { throw new RuntimeException(ex); - } - catch (NoSuchMethodException ex) + } catch (NoSuchMethodException ex) { return null; } } - /** @since 5.3 */ + /** + * @since 5.3 + */ public static ServiceDef3 toServiceDef3(ServiceDef sd) { if (sd instanceof ServiceDef3) @@ -1093,7 +1039,9 @@ public class InternalUtils }; } - /** @since 5.1.0.2 */ + /** + * @since 5.1.0.2 + */ public static ServiceLifecycle2 toServiceLifecycle2(final ServiceLifecycle lifecycle) { if (lifecycle instanceof ServiceLifecycle2) @@ -1118,9 +1066,11 @@ public class InternalUtils }; } - /** @since 5.2.0 */ + /** + * @since 5.2.0 + */ public static <T extends Comparable<T>> List<T> matchAndSort(Collection<? extends T> collection, - Predicate<T> predicate) + Predicate<T> predicate) { assert predicate != null; @@ -1159,19 +1109,19 @@ public class InternalUtils } public void contribute(ModuleBuilderSource moduleSource, ServiceResources resources, - Configuration configuration) + Configuration configuration) { contribution.contribute(moduleSource, resources, configuration); } public void contribute(ModuleBuilderSource moduleSource, ServiceResources resources, - OrderedConfiguration configuration) + OrderedConfiguration configuration) { contribution.contribute(moduleSource, resources, configuration); } public void contribute(ModuleBuilderSource moduleSource, ServiceResources resources, - MappedConfiguration configuration) + MappedConfiguration configuration) { contribution.contribute(moduleSource, resources, configuration); } @@ -1225,6 +1175,11 @@ public class InternalUtils return null; } + @Override + public String toString() + { + return advisor.toString(); + } }; } @@ -1269,6 +1224,11 @@ public class InternalUtils return null; } + @Override + public String toString() + { + return decorator.toString(); + } }; } @@ -1276,7 +1236,7 @@ public class InternalUtils * Determines if the indicated class is stored as a locally accessible file * (and not, typically, as a file inside a JAR). This is related to automatic * reloading of services. - * + * * @since 5.2.0 */ public static boolean isLocalFile(Class clazz) @@ -1297,7 +1257,7 @@ public class InternalUtils /** * Wraps a {@link Coercion} as a {@link Mapper}. - * + * * @since 5.2.0 */ public static <S, T> Mapper<S, T> toMapper(final Coercion<S, T> coercion) @@ -1319,7 +1279,7 @@ public class InternalUtils /** * Generates a unique value for the current execution of the application. This initial UUID value * is not easily predictable; subsequent UUIDs are allocated in ascending series. - * + * * @since 5.2.0 */ public static long nextUUID() @@ -1332,16 +1292,18 @@ public class InternalUtils * If present, its value is returned. Otherwise {@link Named} annotation is checked. If present, its value is * returned. * If neither of the annotations is present, <code>null</code> value is returned - * - * @param annotated - * annotated element to get annotations from + * + * @param annotated annotated element to get annotations from * @since 5.3 */ public static String getServiceId(AnnotatedElement annotated) { ServiceId serviceIdAnnotation = annotated.getAnnotation(ServiceId.class); - if (serviceIdAnnotation != null) { return serviceIdAnnotation.value(); } + if (serviceIdAnnotation != null) + { + return serviceIdAnnotation.value(); + } Named namedAnnotation = annotated.getAnnotation(Named.class); @@ -1349,7 +1311,10 @@ public class InternalUtils { String value = namedAnnotation.value(); - if (InternalUtils.isNonBlank(value)) { return value; } + if (InternalUtils.isNonBlank(value)) + { + return value; + } } return null; @@ -1358,13 +1323,12 @@ public class InternalUtils /** * Converts old-style Tapestry IoC {@link org.apache.tapestry5.ioc.MethodAdvice} to modern * Plastic {@link MethodAdvice}. - * - * @param iocMethodAdvice - * old style advice + * + * @param iocMethodAdvice old style advice * @return new style advice */ public static MethodAdvice toPlasticMethodAdvice(final org.apache.tapestry5.ioc.MethodAdvice iocMethodAdvice, - final AnnotationProvider methodAnnotationProvider) + final AnnotationProvider methodAnnotationProvider) { assert iocMethodAdvice != null; Modified: tapestry/tapestry5/trunk/tapestry-ioc/src/main/resources/org/apache/tapestry5/ioc/internal/IOCStrings.properties URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-ioc/src/main/resources/org/apache/tapestry5/ioc/internal/IOCStrings.properties?rev=1164764&r1=1164763&r2=1164764&view=diff ============================================================================== --- tapestry/tapestry5/trunk/tapestry-ioc/src/main/resources/org/apache/tapestry5/ioc/internal/IOCStrings.properties (original) +++ tapestry/tapestry5/trunk/tapestry-ioc/src/main/resources/org/apache/tapestry5/ioc/internal/IOCStrings.properties Fri Sep 2 23:57:50 2011 @@ -1,4 +1,4 @@ - # 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. @@ -17,7 +17,6 @@ build-method-wrong-return-type=Method %s but the return type (%s) is not acceptable (try an interface). decorator-method-wrong-return-type=Method %s is named like a service decorator method, \ but the return type (%s) is not acceptable (try Object). -builder-locked=The Registry Builder has created the Registry, further operations are not allowed. service-wrong-interface=Service '%s' implements interface %s, which is not compatible with the requested type %s. instantiate-builder-error=Unable to instantiate class %s as a module: %s builder-method-error=Error invoking service builder method %s (for service '%s'): %s @@ -32,7 +31,6 @@ many-services-match-marker=Unable to loc unknown-scope=Unknown service scope '%s'. decorator-returned-wrong-type=Decorator method %s (invoked for service '%s') returned %s, \ which is not assignable to the %s service interface. -creating-service=Creating service '%s'. invoking-method=Invoking method %s. invoking-constructor=Invoking constructor %s. recursive-service-build=Construction of service '%s' has failed due to recursion: \ Modified: tapestry/tapestry5/trunk/tapestry-ioc/src/test/resources/log4j.properties URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-ioc/src/test/resources/log4j.properties?rev=1164764&r1=1164763&r2=1164764&view=diff ============================================================================== --- tapestry/tapestry5/trunk/tapestry-ioc/src/test/resources/log4j.properties (original) +++ tapestry/tapestry5/trunk/tapestry-ioc/src/test/resources/log4j.properties Fri Sep 2 23:57:50 2011 @@ -17,5 +17,8 @@ log4j.category.org.apache.tapestry5.ioc. log4j.category.com.example=debug log4j.category.org.apache.tapestry5.ioc.services.TapestryIOCModule.PeriodicExecutor=debug +# This makes things very verbose, but can be useful to figure what's happening and how long its taking. +# log4j.category.org.apache.tapestry5.ioc.Registry=debug + # log4j.category.org.apache.tapestry5.ioc.services.TapestryIOCModule.PlasticProxyFactory=debug