cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1564840 - in /cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs: model/AbstractResourceInfo.java utils/InjectionUtils.java
Date Wed, 05 Feb 2014 17:21:57 GMT
Author: sergeyb
Date: Wed Feb  5 17:21:57 2014
New Revision: 1564840

URL: http://svn.apache.org/r1564840
Log:
[CXF-5542] Injecting TL contexts immediately, with the optimizations to follow

Modified:
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/AbstractResourceInfo.java
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/AbstractResourceInfo.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/AbstractResourceInfo.java?rev=1564840&r1=1564839&r2=1564840&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/AbstractResourceInfo.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/model/AbstractResourceInfo.java
Wed Feb  5 17:21:57 2014
@@ -80,7 +80,7 @@ public abstract class AbstractResourceIn
     private void findContexts(Class<?> cls, Object provider, 
                               Map<Class<?>, ThreadLocalProxy<?>> constructorProxies)
{
         findContextFields(cls, provider);
-        findContextSetterMethods(cls);
+        findContextSetterMethods(cls, provider);
         if (constructorProxies != null) {
             Map<Class<?>, Map<Class<?>, ThreadLocalProxy<?>>>
proxies = getConstructorProxyMap(true);
             proxies.put(serviceClass, constructorProxies);
@@ -130,19 +130,46 @@ public abstract class AbstractResourceIn
     }
     
     private static ThreadLocalProxy<?> getFieldThreadLocalProxy(Field f, Object provider)
{
+        ThreadLocalProxy<?> defaultValue = InjectionUtils.createThreadLocalProxy(f.getType());

         if (provider != null) {
+            Object proxy = null;
             synchronized (provider) {
                 try {
-                    Object proxy = InjectionUtils.extractFieldValue(f, provider);
-                    if (proxy instanceof ThreadLocalProxy) {
-                        return (ThreadLocalProxy<?>)proxy;
-                    }
+                    proxy = InjectionUtils.extractFieldValue(f, provider);
                 } catch (Throwable t) {
                     // continue
                 }
+                if (!(proxy instanceof ThreadLocalProxy)) {
+                    proxy = defaultValue;
+                    InjectionUtils.injectFieldValue(f, provider, proxy);
+                }
             }
+            return (ThreadLocalProxy<?>)proxy;
+        } else {
+            return defaultValue;
+        }
+    }
+    
+    private static ThreadLocalProxy<?> getMethodThreadLocalProxy(Method m, Object provider)
{
+        ThreadLocalProxy<?> defaultValue = InjectionUtils.createThreadLocalProxy(m.getParameterTypes()[0]);

+        if (provider != null) {
+            Object proxy = null;
+            synchronized (provider) {
+                try {
+                    Method getter = m.getClass().getMethod("get" + m.getName().substring(3),
new Class[]{});
+                    proxy = InjectionUtils.extractFromMethod(provider, getter);
+                } catch (Throwable t) {
+                    // continue
+                }
+                if (!(proxy instanceof ThreadLocalProxy)) {
+                    proxy = defaultValue;
+                    InjectionUtils.injectThroughMethod(provider, m, proxy);
+                }
+            }
+            return (ThreadLocalProxy<?>)proxy;
+        } else {
+            return defaultValue;
         }
-        return InjectionUtils.createThreadLocalProxy(f.getType());
     }
     
     @SuppressWarnings("unchecked")
@@ -185,7 +212,7 @@ public abstract class AbstractResourceIn
         return getProxyMap(Method.class, SETTER_PROXY_MAP, create);
     }
     
-    private void findContextSetterMethods(Class<?> cls) {
+    private void findContextSetterMethods(Class<?> cls, Object provider) {
         
         for (Method m : cls.getMethods()) {
         
@@ -194,25 +221,25 @@ public abstract class AbstractResourceIn
             }
             for (Annotation a : m.getAnnotations()) {
                 if (a.annotationType() == Context.class) {
-                    checkContextMethod(m);
+                    checkContextMethod(m, provider);
                     break;
                 }
             }
         }
         Class<?>[] interfaces = cls.getInterfaces();
         for (Class<?> i : interfaces) {
-            findContextSetterMethods(i);
+            findContextSetterMethods(i, provider);
         }
         Class<?> superCls = cls.getSuperclass();
         if (superCls != null && superCls != Object.class) {
-            findContextSetterMethods(superCls);
+            findContextSetterMethods(superCls, provider);
         }
     }
     
-    private void checkContextMethod(Method m) {
+    private void checkContextMethod(Method m, Object provider) {
         Class<?> type = m.getParameterTypes()[0];
         if (m.getName().equals("set" + type.getSimpleName())) {        
-            addContextMethod(type, m);
+            addContextMethod(type, m, provider);
         }
     }
     
@@ -223,14 +250,13 @@ public abstract class AbstractResourceIn
                                       : Collections.unmodifiableMap(methods);
     }
     
-    private void addContextMethod(Class<?> contextClass, Method m) {
+    private void addContextMethod(Class<?> contextClass, Method m, Object provider)
{
         if (contextMethods == null) {
             contextMethods = new HashMap<Class<?>, Map<Class<?>, Method>>();
         }
         addToMap(contextMethods, contextClass, m);
         if (m.getParameterTypes()[0] != Application.class) {
-            addToMap(getSetterProxyMap(true), m, 
-                     InjectionUtils.createThreadLocalProxy(m.getParameterTypes()[0]));
+            addToMap(getSetterProxyMap(true), m, getMethodThreadLocalProxy(m, provider));
         }
     }
     

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java?rev=1564840&r1=1564839&r2=1564840&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/InjectionUtils.java
Wed Feb  5 17:21:57 2014
@@ -982,6 +982,15 @@ public final class InjectionUtils {
             Method method = entry.getValue();
             Object value = method.getParameterTypes()[0] == Application.class 
                 ? app : cri.getContextSetterProxy(method);
+            try {
+                synchronized (instance) {
+                    if (value == InjectionUtils.extractFromMethod(instance, method)) {
+                        continue;
+                    }
+                }
+            } catch (Throwable t) {
+                // continue
+            }
             InjectionUtils.injectThroughMethod(instance, method, value);
         }
         



Mime
View raw message