You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by bu...@apache.org on 2020/02/21 20:11:17 UTC

[cxf] branch 3.3.x-fixes updated (675ffaf -> fca6f87)

This is an automated email from the ASF dual-hosted git repository.

buhhunyx pushed a change to branch 3.3.x-fixes
in repository https://gitbox.apache.org/repos/asf/cxf.git.


    from 675ffaf  [CXF-8219] upgrade to netty 4.1.45.Final
     new 27d12fe  CXF-8149 Reduce synchronization in AbstractJXBProvider (#597)
     new fca6f87  Recording .gitmergeinfo Changes

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .gitmergeinfo                                      |   1 +
 .../cxf/jaxrs/provider/AbstractJAXBProvider.java   | 115 ++++++++++-----------
 2 files changed, 56 insertions(+), 60 deletions(-)


[cxf] 01/02: CXF-8149 Reduce synchronization in AbstractJXBProvider (#597)

Posted by bu...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

buhhunyx pushed a commit to branch 3.3.x-fixes
in repository https://gitbox.apache.org/repos/asf/cxf.git

commit 27d12fe0b183fff3ef5d507356b879c55856ca6b
Author: Alexey Markevich <bu...@gmail.com>
AuthorDate: Fri Feb 21 09:42:15 2020 +0300

    CXF-8149 Reduce synchronization in AbstractJXBProvider (#597)
    
    * CXF-8149 Reduce synchronization in AbstractJXBProvider
    
    * use javax.xml.ws.Holder; improve getCollectionContext impl
    
    * use single value array for possible exception propagation
    
    (cherry picked from commit 224fa741d6753053c6f47d361f8cc7e93fd34ed9)
---
 .../cxf/jaxrs/provider/AbstractJAXBProvider.java   | 115 ++++++++++-----------
 1 file changed, 55 insertions(+), 60 deletions(-)

diff --git a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/AbstractJAXBProvider.java b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/AbstractJAXBProvider.java
index 9704a91..a9500e5 100644
--- a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/AbstractJAXBProvider.java
+++ b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/AbstractJAXBProvider.java
@@ -32,12 +32,12 @@ import java.security.PrivilegedExceptionAction;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collections;
-import java.util.HashMap;
 import java.util.HashSet;
 import java.util.LinkedList;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
 
 import javax.ws.rs.WebApplicationException;
 import javax.ws.rs.core.MediaType;
@@ -98,7 +98,7 @@ public abstract class AbstractJAXBProvider<T> extends AbstractConfigurableProvid
         new HashSet<Class<?>>(Arrays.asList(InputStream.class,
                                             OutputStream.class,
                                             StreamingOutput.class));
-    protected Set<Class<?>> collectionContextClasses = new HashSet<>();
+    protected Set<Class<?>> collectionContextClasses = ConcurrentHashMap.newKeySet();
 
     protected Map<String, String> jaxbElementClassMap = Collections.emptyMap();
     protected boolean unmarshalAsJaxbElement;
@@ -111,8 +111,8 @@ public abstract class AbstractJAXBProvider<T> extends AbstractConfigurableProvid
     protected List<String> inDropElements;
     protected Map<String, String> inElementsMap;
     protected Map<String, String> inAppendMap;
-    protected Map<String, JAXBContext> packageContexts = new HashMap<>();
-    protected Map<Class<?>, JAXBContext> classContexts = new HashMap<>();
+    protected Map<String, JAXBContext> packageContexts = new ConcurrentHashMap<>();
+    protected Map<Class<?>, JAXBContext> classContexts = new ConcurrentHashMap<>();
     private boolean attributesToElements;
 
     private MessageContext mc;
@@ -366,14 +366,11 @@ public abstract class AbstractJAXBProvider<T> extends AbstractConfigurableProvid
     }
 
     protected JAXBContext getCollectionContext(Class<?> type) throws JAXBException {
-        synchronized (collectionContextClasses) {
-            if (!collectionContextClasses.contains(type)) {
-                collectionContextClasses.add(CollectionWrapper.class);
-                collectionContextClasses.add(type);
-            }
-            return newJAXBContextInstance(
-                collectionContextClasses.toArray(new Class[0]), cProperties);
+        if (collectionContextClasses.add(type)) {
+            collectionContextClasses.add(CollectionWrapper.class);
         }
+        return newJAXBContextInstance(
+            collectionContextClasses.toArray(new Class[0]), cProperties);
     }
 
     protected QName getCollectionWrapperQName(Class<?> cls, Type type, Object object, boolean pluralName)
@@ -506,14 +503,12 @@ public abstract class AbstractJAXBProvider<T> extends AbstractConfigurableProvid
             }
         }
 
-        synchronized (classContexts) {
-            JAXBContext context = classContexts.get(type);
-            if (context != null) {
-                return context;
-            }
+        JAXBContext context = classContexts.get(type);
+        if (context != null) {
+            return context;
         }
 
-        JAXBContext context = getPackageContext(type, genericType);
+        context = getPackageContext(type, genericType);
 
         return context != null ? context : getClassContext(type, genericType);
     }
@@ -521,23 +516,28 @@ public abstract class AbstractJAXBProvider<T> extends AbstractConfigurableProvid
         return getClassContext(type, type);
     }
     protected JAXBContext getClassContext(Class<?> type, Type genericType) throws JAXBException {
-        synchronized (classContexts) {
-            JAXBContext context = classContexts.get(type);
-            if (context == null) {
-                Class<?>[] classes;
-                if (extraClass != null) {
-                    classes = new Class[extraClass.length + 1];
-                    classes[0] = type;
-                    System.arraycopy(extraClass, 0, classes, 1, extraClass.length);
-                } else {
-                    classes = new Class[] {type};
-                }
+        final JAXBException[] jaxbException = new JAXBException[] {null};
+        final JAXBContext context = classContexts.computeIfAbsent(type, t -> {
+            final Class<?>[] classes;
+            if (extraClass != null) {
+                classes = new Class[extraClass.length + 1];
+                classes[0] = type;
+                System.arraycopy(extraClass, 0, classes, 1, extraClass.length);
+            } else {
+                classes = new Class[] {type};
+            }
 
-                context = newJAXBContextInstance(classes, cProperties);
-                classContexts.put(type, context);
+            try {
+                return newJAXBContextInstance(classes, cProperties);
+            } catch (JAXBException e) {
+                jaxbException[0] = e;
+                return null;
             }
-            return context;
+        });
+        if (null != jaxbException[0]) {
+            throw jaxbException[0];
         }
+        return context;
     }
     public JAXBContext getPackageContext(Class<?> type) {
         return getPackageContext(type, type);
@@ -546,40 +546,35 @@ public abstract class AbstractJAXBProvider<T> extends AbstractConfigurableProvid
         if (type == null || type == JAXBElement.class) {
             return null;
         }
-        synchronized (packageContexts) {
-            String packageName = PackageUtils.getPackageName(type);
-            JAXBContext context = packageContexts.get(packageName);
-            if (context == null) {
-                try {
-                    final ClassLoader loader = AccessController.doPrivileged((PrivilegedAction<ClassLoader>) 
-                        () -> {
-                            return type.getClassLoader();
-                        });
-                    if (loader != null && objectFactoryOrIndexAvailable(type)) {
-
-                        String contextName = packageName;
-                        if (extraClass != null) {
-                            StringBuilder sb = new StringBuilder(contextName);
-                            for (Class<?> extra : extraClass) {
-                                String extraPackage = PackageUtils.getPackageName(extra);
-                                if (!extraPackage.equals(packageName)) {
-                                    sb.append(':').append(extraPackage);
-                                }
+        final String packageName = PackageUtils.getPackageName(type);
+        return packageContexts.computeIfAbsent(packageName, p -> {
+            try {
+                final ClassLoader loader = AccessController.doPrivileged((PrivilegedAction<ClassLoader>) 
+                    () -> {
+                        return type.getClassLoader();
+                    });
+                if (loader != null && objectFactoryOrIndexAvailable(type)) {
+
+                    String contextName = packageName;
+                    if (extraClass != null) {
+                        StringBuilder sb = new StringBuilder(contextName);
+                        for (Class<?> extra : extraClass) {
+                            String extraPackage = PackageUtils.getPackageName(extra);
+                            if (!extraPackage.equals(packageName)) {
+                                sb.append(':').append(extraPackage);
                             }
-                            contextName = sb.toString();
                         }
-
-                        context = JAXBContext.newInstance(contextName, loader, cProperties);
-                        packageContexts.put(packageName, context);
+                        contextName = sb.toString();
                     }
-                } catch (JAXBException ex) {
-                    LOG.fine("Error creating a JAXBContext using ObjectFactory : "
-                                + ex.getMessage());
-                    return null;
+
+                    return JAXBContext.newInstance(contextName, loader, cProperties);
                 }
+            } catch (JAXBException ex) {
+                LOG.fine("Error creating a JAXBContext using ObjectFactory : "
+                            + ex.getMessage());
             }
-            return context;
-        }
+            return null;
+        });
     }
 
     protected boolean isSupported(Class<?> type, Type genericType, Annotation[] anns) {


[cxf] 02/02: Recording .gitmergeinfo Changes

Posted by bu...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

buhhunyx pushed a commit to branch 3.3.x-fixes
in repository https://gitbox.apache.org/repos/asf/cxf.git

commit fca6f87259a365b1999751460280bc7f02c69439
Author: Alexey Markevich <bu...@gmail.com>
AuthorDate: Fri Feb 21 23:09:03 2020 +0300

    Recording .gitmergeinfo Changes
---
 .gitmergeinfo | 1 +
 1 file changed, 1 insertion(+)

diff --git a/.gitmergeinfo b/.gitmergeinfo
index f9f0d7f..45c8c57 100644
--- a/.gitmergeinfo
+++ b/.gitmergeinfo
@@ -131,6 +131,7 @@ B fcd22cd026bc94a95fa19210df193df753afe4d1
 M 09ddfdeaef6f32537dba23fa6d7ef36992b3217b
 M 160f50ed9bd9391b61417716b3a67653c9e81a98
 M 180578d01f361d77ce7f42dd760fa8d5f245ce7e
+M 224fa741d6753053c6f47d361f8cc7e93fd34ed9
 M 2275d49772676ac72bc14ebbc3173719cd72e635
 M 2cde96f38fc835f7d0eb1e303037e572110c3399
 M 325ed0436bc9cfa9150b3504a54b5911b47e3266