From e9f398cf41baa79e9b7cdc74b89a8e02d58ee0a6 Mon Sep 17 00:00:00 2001 From: Christoph Dreis Date: Tue, 30 May 2017 21:46:11 +0200 Subject: [PATCH] Deprecate ConcurrentHashSet (#1570) Signed-off-by: dreis2211 --- .../jetty/annotations/AnnotationConfiguration.java | 7 +++---- .../eclipse/jetty/annotations/AnnotationParser.java | 4 ++-- .../jetty/annotations/ClassInheritanceHandler.java | 13 +++++++------ .../annotations/TestAnnotationInheritance.java | 7 ++++--- .../http2/client/http/HttpConnectionOverHTTP2.java | 4 ++-- .../jetty/osgi/annotations/AnnotationParser.java | 3 +-- .../jetty/plus/annotation/ContainerInitializer.java | 6 +++--- .../jetty/server/session/SessionHandler.java | 4 ++-- .../org/eclipse/jetty/util/ConcurrentHashSet.java | 4 ++++ .../eclipse/jetty/util/thread/QueuedThreadPool.java | 5 +++-- .../jetty/webapp/CachingWebAppClassLoader.java | 4 ++-- 11 files changed, 33 insertions(+), 28 deletions(-) diff --git a/jetty-annotations/src/main/java/org/eclipse/jetty/annotations/AnnotationConfiguration.java b/jetty-annotations/src/main/java/org/eclipse/jetty/annotations/AnnotationConfiguration.java index 41a7e8ccd4d..c0c9f21915b 100644 --- a/jetty-annotations/src/main/java/org/eclipse/jetty/annotations/AnnotationConfiguration.java +++ b/jetty-annotations/src/main/java/org/eclipse/jetty/annotations/AnnotationConfiguration.java @@ -45,7 +45,6 @@ import javax.servlet.annotation.HandlesTypes; import org.eclipse.jetty.annotations.AnnotationParser.Handler; import org.eclipse.jetty.plus.annotation.ContainerInitializer; -import org.eclipse.jetty.util.ConcurrentHashSet; import org.eclipse.jetty.util.MultiException; import org.eclipse.jetty.util.StringUtil; import org.eclipse.jetty.util.TypeUtil; @@ -381,7 +380,7 @@ public class AnnotationConfiguration extends AbstractConfiguration @Override public void postConfigure(WebAppContext context) throws Exception { - ConcurrentHashMap> classMap = (ClassInheritanceMap)context.getAttribute(CLASS_INHERITANCE_MAP); + Map> classMap = (ClassInheritanceMap)context.getAttribute(CLASS_INHERITANCE_MAP); List initializers = (List)context.getAttribute(CONTAINER_INITIALIZERS); context.removeAttribute(CLASS_INHERITANCE_MAP); @@ -596,7 +595,7 @@ public class AnnotationConfiguration extends AbstractConfiguration if (context.getAttribute(CLASS_INHERITANCE_MAP) == null) { //MultiMap map = new MultiMap<>(); - ConcurrentHashMap> map = new ClassInheritanceMap(); + Map> map = new ClassInheritanceMap(); context.setAttribute(CLASS_INHERITANCE_MAP, map); _classInheritanceHandler = new ClassInheritanceHandler(map); } @@ -1072,7 +1071,7 @@ public class AnnotationConfiguration extends AbstractConfiguration return (d!=null && d.getMetaDataComplete() == MetaDataComplete.True); } - public static class ClassInheritanceMap extends ConcurrentHashMap> + public static class ClassInheritanceMap extends ConcurrentHashMap> { @Override diff --git a/jetty-annotations/src/main/java/org/eclipse/jetty/annotations/AnnotationParser.java b/jetty-annotations/src/main/java/org/eclipse/jetty/annotations/AnnotationParser.java index 1520370a86a..4f076cd6284 100644 --- a/jetty-annotations/src/main/java/org/eclipse/jetty/annotations/AnnotationParser.java +++ b/jetty-annotations/src/main/java/org/eclipse/jetty/annotations/AnnotationParser.java @@ -28,10 +28,10 @@ import java.util.Arrays; import java.util.List; import java.util.Locale; import java.util.Set; +import java.util.concurrent.ConcurrentHashMap; import java.util.jar.JarEntry; import java.util.jar.JarInputStream; -import org.eclipse.jetty.util.ConcurrentHashSet; import org.eclipse.jetty.util.Loader; import org.eclipse.jetty.util.MultiException; import org.eclipse.jetty.util.log.Log; @@ -68,7 +68,7 @@ public class AnnotationParser { private static final Logger LOG = Log.getLogger(AnnotationParser.class); - protected Set _parsedClassNames = new ConcurrentHashSet(); + protected Set _parsedClassNames = ConcurrentHashMap.newKeySet(); protected static int ASM_OPCODE_VERSION = Opcodes.ASM5; //compatibility of api diff --git a/jetty-annotations/src/main/java/org/eclipse/jetty/annotations/ClassInheritanceHandler.java b/jetty-annotations/src/main/java/org/eclipse/jetty/annotations/ClassInheritanceHandler.java index faddbfc15bb..d0d0c15d341 100644 --- a/jetty-annotations/src/main/java/org/eclipse/jetty/annotations/ClassInheritanceHandler.java +++ b/jetty-annotations/src/main/java/org/eclipse/jetty/annotations/ClassInheritanceHandler.java @@ -18,11 +18,12 @@ package org.eclipse.jetty.annotations; +import java.util.Map; +import java.util.Set; import java.util.concurrent.ConcurrentHashMap; import org.eclipse.jetty.annotations.AnnotationParser.AbstractHandler; import org.eclipse.jetty.annotations.AnnotationParser.ClassInfo; -import org.eclipse.jetty.util.ConcurrentHashSet; import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.Logger; @@ -35,10 +36,10 @@ public class ClassInheritanceHandler extends AbstractHandler { private static final Logger LOG = Log.getLogger(ClassInheritanceHandler.class); - ConcurrentHashMap> _inheritanceMap; + Map> _inheritanceMap; - public ClassInheritanceHandler(ConcurrentHashMap> map) + public ClassInheritanceHandler(Map> map) { _inheritanceMap = map; } @@ -69,13 +70,13 @@ public class ClassInheritanceHandler extends AbstractHandler { //As it is likely that the interfaceOrSuperClassName is already in the map, try getting it first - ConcurrentHashSet implementingClasses = _inheritanceMap.get(interfaceOrSuperClassName); + Set implementingClasses = _inheritanceMap.get(interfaceOrSuperClassName); //If it isn't in the map, then add it in, but test to make sure that someone else didn't get in //first and add it if (implementingClasses == null) { - implementingClasses = new ConcurrentHashSet(); - ConcurrentHashSet tmp = _inheritanceMap.putIfAbsent(interfaceOrSuperClassName, implementingClasses); + implementingClasses = ConcurrentHashMap.newKeySet(); + Set tmp = _inheritanceMap.putIfAbsent(interfaceOrSuperClassName, implementingClasses); if (tmp != null) implementingClasses = tmp; } diff --git a/jetty-annotations/src/test/java/org/eclipse/jetty/annotations/TestAnnotationInheritance.java b/jetty-annotations/src/test/java/org/eclipse/jetty/annotations/TestAnnotationInheritance.java index 5443b235a74..83699dd11e8 100644 --- a/jetty-annotations/src/test/java/org/eclipse/jetty/annotations/TestAnnotationInheritance.java +++ b/jetty-annotations/src/test/java/org/eclipse/jetty/annotations/TestAnnotationInheritance.java @@ -26,6 +26,8 @@ import static org.junit.Assert.assertTrue; import java.util.ArrayList; import java.util.Collections; import java.util.List; +import java.util.Map; +import java.util.Set; import java.util.concurrent.ConcurrentHashMap; import javax.naming.Context; @@ -35,7 +37,6 @@ import org.eclipse.jetty.annotations.AnnotationParser.AbstractHandler; import org.eclipse.jetty.annotations.AnnotationParser.ClassInfo; import org.eclipse.jetty.annotations.AnnotationParser.FieldInfo; import org.eclipse.jetty.annotations.AnnotationParser.MethodInfo; -import org.eclipse.jetty.util.ConcurrentHashSet; import org.junit.After; import org.junit.Test; @@ -147,7 +148,7 @@ public class TestAnnotationInheritance @Test public void testTypeInheritanceHandling() throws Exception { - ConcurrentHashMap> map = new ConcurrentHashMap>(); + Map> map = new ConcurrentHashMap<>(); AnnotationParser parser = new AnnotationParser(); ClassInheritanceHandler handler = new ClassInheritanceHandler(map); @@ -171,7 +172,7 @@ public class TestAnnotationInheritance assertTrue (map.keySet().contains("org.eclipse.jetty.annotations.ClassA")); assertTrue (map.keySet().contains("org.eclipse.jetty.annotations.InterfaceD")); - ConcurrentHashSet classes = map.get("org.eclipse.jetty.annotations.ClassA"); + Set classes = map.get("org.eclipse.jetty.annotations.ClassA"); assertEquals(1, classes.size()); assertEquals ("org.eclipse.jetty.annotations.ClassB", classes.iterator().next()); diff --git a/jetty-http2/http2-http-client-transport/src/main/java/org/eclipse/jetty/http2/client/http/HttpConnectionOverHTTP2.java b/jetty-http2/http2-http-client-transport/src/main/java/org/eclipse/jetty/http2/client/http/HttpConnectionOverHTTP2.java index cb706094af2..05f8456185f 100644 --- a/jetty-http2/http2-http-client-transport/src/main/java/org/eclipse/jetty/http2/client/http/HttpConnectionOverHTTP2.java +++ b/jetty-http2/http2-http-client-transport/src/main/java/org/eclipse/jetty/http2/client/http/HttpConnectionOverHTTP2.java @@ -20,6 +20,7 @@ package org.eclipse.jetty.http2.client.http; import java.nio.channels.AsynchronousCloseException; import java.util.Set; +import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.TimeoutException; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicInteger; @@ -33,12 +34,11 @@ import org.eclipse.jetty.http.HttpVersion; import org.eclipse.jetty.http2.ErrorCode; import org.eclipse.jetty.http2.api.Session; import org.eclipse.jetty.util.Callback; -import org.eclipse.jetty.util.ConcurrentHashSet; import org.eclipse.jetty.util.thread.Sweeper; public class HttpConnectionOverHTTP2 extends HttpConnection implements Sweeper.Sweepable { - private final Set channels = new ConcurrentHashSet<>(); + private final Set channels = ConcurrentHashMap.newKeySet(); private final AtomicBoolean closed = new AtomicBoolean(); private final AtomicInteger sweeps = new AtomicInteger(); private final Session session; diff --git a/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/annotations/AnnotationParser.java b/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/annotations/AnnotationParser.java index c24ca26a0b4..64668220574 100644 --- a/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/annotations/AnnotationParser.java +++ b/jetty-osgi/jetty-osgi-boot/src/main/java/org/eclipse/jetty/osgi/annotations/AnnotationParser.java @@ -30,7 +30,6 @@ import java.util.TreeSet; import java.util.concurrent.ConcurrentHashMap; import org.eclipse.jetty.osgi.boot.utils.BundleFileLocatorHelperFactory; -import org.eclipse.jetty.util.ConcurrentHashSet; import org.eclipse.jetty.util.resource.Resource; import org.osgi.framework.Bundle; import org.osgi.framework.Constants; @@ -40,7 +39,7 @@ import org.osgi.framework.Constants; */ public class AnnotationParser extends org.eclipse.jetty.annotations.AnnotationParser { - private Set _alreadyParsed = new ConcurrentHashSet(); + private Set _alreadyParsed = ConcurrentHashMap.newKeySet(); private ConcurrentHashMap _uriToBundle = new ConcurrentHashMap(); private ConcurrentHashMap _bundleToResource = new ConcurrentHashMap(); diff --git a/jetty-plus/src/main/java/org/eclipse/jetty/plus/annotation/ContainerInitializer.java b/jetty-plus/src/main/java/org/eclipse/jetty/plus/annotation/ContainerInitializer.java index 98a1efc1dad..636bd65b62e 100644 --- a/jetty-plus/src/main/java/org/eclipse/jetty/plus/annotation/ContainerInitializer.java +++ b/jetty-plus/src/main/java/org/eclipse/jetty/plus/annotation/ContainerInitializer.java @@ -24,13 +24,13 @@ import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Set; +import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.TimeUnit; import java.util.regex.Matcher; import java.util.regex.Pattern; import javax.servlet.ServletContainerInitializer; -import org.eclipse.jetty.util.ConcurrentHashSet; import org.eclipse.jetty.util.Loader; import org.eclipse.jetty.util.StringUtil; import org.eclipse.jetty.util.log.Log; @@ -43,8 +43,8 @@ public class ContainerInitializer final protected ServletContainerInitializer _target; final protected Class[] _interestedTypes; - final protected Set _applicableTypeNames = new ConcurrentHashSet(); - final protected Set _annotatedTypeNames = new ConcurrentHashSet(); + final protected Set _applicableTypeNames = ConcurrentHashMap.newKeySet(); + final protected Set _annotatedTypeNames = ConcurrentHashMap.newKeySet(); public ContainerInitializer (ServletContainerInitializer target, Class[] classes) diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/session/SessionHandler.java b/jetty-server/src/main/java/org/eclipse/jetty/server/session/SessionHandler.java index 948627eb798..eed33686245 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/session/SessionHandler.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/session/SessionHandler.java @@ -29,6 +29,7 @@ import java.util.EventListener; import java.util.HashSet; import java.util.List; import java.util.Set; +import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.CopyOnWriteArrayList; import javax.servlet.AsyncEvent; @@ -54,7 +55,6 @@ import org.eclipse.jetty.server.Server; import org.eclipse.jetty.server.SessionIdManager; import org.eclipse.jetty.server.handler.ContextHandler; import org.eclipse.jetty.server.handler.ScopedHandler; -import org.eclipse.jetty.util.ConcurrentHashSet; import org.eclipse.jetty.util.StringUtil; import org.eclipse.jetty.util.annotation.ManagedAttribute; import org.eclipse.jetty.util.annotation.ManagedObject; @@ -247,7 +247,7 @@ public class SessionHandler extends ScopedHandler protected boolean _usingURLs; protected boolean _usingCookies=true; - protected ConcurrentHashSet _candidateSessionIdsForExpiry = new ConcurrentHashSet(); + protected Set _candidateSessionIdsForExpiry = ConcurrentHashMap.newKeySet(); protected Scheduler _scheduler; protected boolean _ownScheduler = false; diff --git a/jetty-util/src/main/java/org/eclipse/jetty/util/ConcurrentHashSet.java b/jetty-util/src/main/java/org/eclipse/jetty/util/ConcurrentHashSet.java index 21c8c363459..fd70300a324 100644 --- a/jetty-util/src/main/java/org/eclipse/jetty/util/ConcurrentHashSet.java +++ b/jetty-util/src/main/java/org/eclipse/jetty/util/ConcurrentHashSet.java @@ -25,6 +25,10 @@ import java.util.Map; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; +/** + * @deprecated Use Java 8 method {@code ConcurrentHashMap.newKeySet()} instead. + */ +@Deprecated public class ConcurrentHashSet extends AbstractSet implements Set { private final Map _map = new ConcurrentHashMap(); diff --git a/jetty-util/src/main/java/org/eclipse/jetty/util/thread/QueuedThreadPool.java b/jetty-util/src/main/java/org/eclipse/jetty/util/thread/QueuedThreadPool.java index db3c78120e9..4cb6fcfa3c4 100755 --- a/jetty-util/src/main/java/org/eclipse/jetty/util/thread/QueuedThreadPool.java +++ b/jetty-util/src/main/java/org/eclipse/jetty/util/thread/QueuedThreadPool.java @@ -24,14 +24,15 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.List; +import java.util.Set; import java.util.concurrent.BlockingQueue; +import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.RejectedExecutionException; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicLong; import org.eclipse.jetty.util.BlockingArrayQueue; -import org.eclipse.jetty.util.ConcurrentHashSet; import org.eclipse.jetty.util.annotation.ManagedAttribute; import org.eclipse.jetty.util.annotation.ManagedObject; import org.eclipse.jetty.util.annotation.ManagedOperation; @@ -53,7 +54,7 @@ public class QueuedThreadPool extends AbstractLifeCycle implements SizedThreadPo private final AtomicInteger _threadsStarted = new AtomicInteger(); private final AtomicInteger _threadsIdle = new AtomicInteger(); private final AtomicLong _lastShrink = new AtomicLong(); - private final ConcurrentHashSet _threads=new ConcurrentHashSet<>(); + private final Set _threads = ConcurrentHashMap.newKeySet(); private final Object _joinLock = new Object(); private final BlockingQueue _jobs; private final ThreadGroup _threadGroup; diff --git a/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/CachingWebAppClassLoader.java b/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/CachingWebAppClassLoader.java index e82fad6dedf..9dadc3109c3 100644 --- a/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/CachingWebAppClassLoader.java +++ b/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/CachingWebAppClassLoader.java @@ -20,9 +20,9 @@ package org.eclipse.jetty.webapp; import java.io.IOException; import java.net.URL; +import java.util.Set; import java.util.concurrent.ConcurrentHashMap; -import org.eclipse.jetty.util.ConcurrentHashSet; import org.eclipse.jetty.util.annotation.ManagedObject; import org.eclipse.jetty.util.annotation.ManagedOperation; import org.eclipse.jetty.util.log.Log; @@ -40,7 +40,7 @@ public class CachingWebAppClassLoader extends WebAppClassLoader { private static final Logger LOG = Log.getLogger(CachingWebAppClassLoader.class); - private final ConcurrentHashSet _notFound = new ConcurrentHashSet<>(); + private final Set _notFound = ConcurrentHashMap.newKeySet(); private final ConcurrentHashMap _cache = new ConcurrentHashMap<>(); public CachingWebAppClassLoader(ClassLoader parent, Context context) throws IOException