FAQ
Author: lu4242
Date: Sat Jul 23 22:44:50 2011
New Revision: 1150236

URL: http://svn.apache.org/viewvc?rev=1150236&view=rev
Log:
MYFACES-3238 [PERF] Improve Application.createConverter(Class<?> forClass) method

Modified:
myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/application/ApplicationImpl.java

Modified: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/application/ApplicationImpl.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/application/ApplicationImpl.java?rev=1150236&r1=1150235&r2=1150236&view=diff
==============================================================================
--- myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/application/ApplicationImpl.java (original)
+++ myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/application/ApplicationImpl.java Sat Jul 23 22:44:50 2011
@@ -166,8 +166,8 @@ public class ApplicationImpl extends App
// synchronize, uses ConcurrentHashMap to allow concurrent read of map
private final Map<String, Object> _converterIdToClassMap = new ConcurrentHashMap<String, Object>();

- private final Map<Class<?>, String> _converterClassNameToClassMap = new ConcurrentHashMap<Class<?>, String>();
-
+ private final Map<Class<?>, Object> _converterTargetClassToConverterClassMap = new ConcurrentHashMap<Class<?>, Object>();
+
private final Map<String, Object> _componentClassMap = new ConcurrentHashMap<String, Object>();

private final Map<String, Object> _validatorClassMap = new ConcurrentHashMap<String, Object>();
@@ -622,7 +622,7 @@ public class ApplicationImpl extends App
@Override
public final Iterator<Class<?>> getConverterTypes()
{
- return _converterClassNameToClassMap.keySet().iterator();
+ return _converterTargetClassToConverterClassMap.keySet().iterator();
}

@Override
@@ -1031,7 +1031,11 @@ public class ApplicationImpl extends App

try
{
- _converterClassNameToClassMap.put(targetClass, converterClass);
+ if(isLazyLoadConfigObjects())
+ _converterTargetClassToConverterClassMap.put(targetClass, converterClass);
+ else
+ _converterTargetClassToConverterClassMap.put(targetClass, ClassUtils.simpleClassForName(converterClass));
+
if (log.isLoggable(Level.FINEST))
log.finest("add Converter for class = " + targetClass + " converterClass = " + converterClass);
}
@@ -1392,14 +1396,17 @@ public class ApplicationImpl extends App
return internalCreateConverter(targetClass);
}

+ @SuppressWarnings("unchecked")
private Converter internalCreateConverter(final Class<?> targetClass)
{
// Locate a Converter registered for the target class itself.
- String converterClassName = _converterClassNameToClassMap.get(targetClass);
-
+ Object converterClassOrClassName = _converterTargetClassToConverterClassMap.get(targetClass);
+
// Locate a Converter registered for interfaces that are
// implemented by the target class (directly or indirectly).
- if (converterClassName == null)
+ // Skip if class is String, for performance reasons
+ // (save 3 additional lookups over a concurrent map per request).
+ if (converterClassOrClassName == null && !String.class.equals(targetClass))
{
final Class<?> interfaces[] = targetClass.getInterfaces();
if (interfaces != null)
@@ -1419,15 +1426,30 @@ public class ApplicationImpl extends App

// Get EnumConverter for enum classes with no special converter, check
// here as recursive call with java.lang.Enum will not work
- if (converterClassName == null && targetClass.isEnum()) {
- converterClassName = _converterClassNameToClassMap.get(Enum.class);
+ if (converterClassOrClassName == null && targetClass.isEnum()) {
+ converterClassOrClassName = _converterTargetClassToConverterClassMap.get(Enum.class);
}

- if (converterClassName != null)
+ if (converterClassOrClassName != null)
{
try
{
- Class<? extends Converter> converterClass = ClassUtils.simpleClassForName(converterClassName);
+ Class<? extends Converter> converterClass = null;
+ if (converterClassOrClassName instanceof Class<?>)
+ {
+ converterClass = (Class<? extends Converter>) converterClassOrClassName;
+ }
+ else if (converterClassOrClassName instanceof String)
+ {
+ converterClass = ClassUtils.simpleClassForName((String) converterClassOrClassName);
+ _converterTargetClassToConverterClassMap.put(targetClass, converterClass);
+ }
+ else
+ {
+ //object stored in the map for this id is an invalid type. remove it and return null
+ _converterTargetClassToConverterClassMap.remove(targetClass);
+ }
+
Converter converter = null;

// check cached constructor information
@@ -1466,8 +1488,8 @@ public class ApplicationImpl extends App
}
catch (Exception e)
{
- log.log(Level.SEVERE, "Could not instantiate converter " + converterClassName, e);
- throw new FacesException("Could not instantiate converter: " + converterClassName, e);
+ log.log(Level.SEVERE, "Could not instantiate converter " + converterClassOrClassName.toString(), e);
+ throw new FacesException("Could not instantiate converter: " + converterClassOrClassName.toString(), e);
}
}

Search Discussions

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupcommits @
categoriesmyfaces
postedJul 23, '11 at 10:45p
activeJul 23, '11 at 10:45p
posts1
users1
websitemyfaces.apache.org

1 user in discussion

Lu4242: 1 post

People

Translate

site design / logo © 2019 Grokbase