Deprecate ConcurrentHashSet (#1570)

Signed-off-by: dreis2211 <christoph.dreis@freenet.de>
This commit is contained in:
Christoph Dreis 2017-05-30 21:46:11 +02:00 committed by Greg Wilkins
parent ae496051de
commit e9f398cf41
11 changed files with 33 additions and 28 deletions

View File

@ -45,7 +45,6 @@ import javax.servlet.annotation.HandlesTypes;
import org.eclipse.jetty.annotations.AnnotationParser.Handler; import org.eclipse.jetty.annotations.AnnotationParser.Handler;
import org.eclipse.jetty.plus.annotation.ContainerInitializer; import org.eclipse.jetty.plus.annotation.ContainerInitializer;
import org.eclipse.jetty.util.ConcurrentHashSet;
import org.eclipse.jetty.util.MultiException; import org.eclipse.jetty.util.MultiException;
import org.eclipse.jetty.util.StringUtil; import org.eclipse.jetty.util.StringUtil;
import org.eclipse.jetty.util.TypeUtil; import org.eclipse.jetty.util.TypeUtil;
@ -381,7 +380,7 @@ public class AnnotationConfiguration extends AbstractConfiguration
@Override @Override
public void postConfigure(WebAppContext context) throws Exception public void postConfigure(WebAppContext context) throws Exception
{ {
ConcurrentHashMap<String, ConcurrentHashSet<String>> classMap = (ClassInheritanceMap)context.getAttribute(CLASS_INHERITANCE_MAP); Map<String, Set<String>> classMap = (ClassInheritanceMap)context.getAttribute(CLASS_INHERITANCE_MAP);
List<ContainerInitializer> initializers = (List<ContainerInitializer>)context.getAttribute(CONTAINER_INITIALIZERS); List<ContainerInitializer> initializers = (List<ContainerInitializer>)context.getAttribute(CONTAINER_INITIALIZERS);
context.removeAttribute(CLASS_INHERITANCE_MAP); context.removeAttribute(CLASS_INHERITANCE_MAP);
@ -596,7 +595,7 @@ public class AnnotationConfiguration extends AbstractConfiguration
if (context.getAttribute(CLASS_INHERITANCE_MAP) == null) if (context.getAttribute(CLASS_INHERITANCE_MAP) == null)
{ {
//MultiMap<String> map = new MultiMap<>(); //MultiMap<String> map = new MultiMap<>();
ConcurrentHashMap<String, ConcurrentHashSet<String>> map = new ClassInheritanceMap(); Map<String, Set<String>> map = new ClassInheritanceMap();
context.setAttribute(CLASS_INHERITANCE_MAP, map); context.setAttribute(CLASS_INHERITANCE_MAP, map);
_classInheritanceHandler = new ClassInheritanceHandler(map); _classInheritanceHandler = new ClassInheritanceHandler(map);
} }
@ -1072,7 +1071,7 @@ public class AnnotationConfiguration extends AbstractConfiguration
return (d!=null && d.getMetaDataComplete() == MetaDataComplete.True); return (d!=null && d.getMetaDataComplete() == MetaDataComplete.True);
} }
public static class ClassInheritanceMap extends ConcurrentHashMap<String, ConcurrentHashSet<String>> public static class ClassInheritanceMap extends ConcurrentHashMap<String, Set<String>>
{ {
@Override @Override

View File

@ -28,10 +28,10 @@ import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.Locale; import java.util.Locale;
import java.util.Set; import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.jar.JarEntry; import java.util.jar.JarEntry;
import java.util.jar.JarInputStream; import java.util.jar.JarInputStream;
import org.eclipse.jetty.util.ConcurrentHashSet;
import org.eclipse.jetty.util.Loader; import org.eclipse.jetty.util.Loader;
import org.eclipse.jetty.util.MultiException; import org.eclipse.jetty.util.MultiException;
import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.Log;
@ -68,7 +68,7 @@ public class AnnotationParser
{ {
private static final Logger LOG = Log.getLogger(AnnotationParser.class); private static final Logger LOG = Log.getLogger(AnnotationParser.class);
protected Set<String> _parsedClassNames = new ConcurrentHashSet<String>(); protected Set<String> _parsedClassNames = ConcurrentHashMap.newKeySet();
protected static int ASM_OPCODE_VERSION = Opcodes.ASM5; //compatibility of api protected static int ASM_OPCODE_VERSION = Opcodes.ASM5; //compatibility of api

View File

@ -18,11 +18,12 @@
package org.eclipse.jetty.annotations; package org.eclipse.jetty.annotations;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import org.eclipse.jetty.annotations.AnnotationParser.AbstractHandler; import org.eclipse.jetty.annotations.AnnotationParser.AbstractHandler;
import org.eclipse.jetty.annotations.AnnotationParser.ClassInfo; 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.Log;
import org.eclipse.jetty.util.log.Logger; 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); private static final Logger LOG = Log.getLogger(ClassInheritanceHandler.class);
ConcurrentHashMap<String, ConcurrentHashSet<String>> _inheritanceMap; Map<String, Set<String>> _inheritanceMap;
public ClassInheritanceHandler(ConcurrentHashMap<String, ConcurrentHashSet<String>> map) public ClassInheritanceHandler(Map<String, Set<String>> map)
{ {
_inheritanceMap = 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 //As it is likely that the interfaceOrSuperClassName is already in the map, try getting it first
ConcurrentHashSet<String> implementingClasses = _inheritanceMap.get(interfaceOrSuperClassName); Set<String> 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 //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 //first and add it
if (implementingClasses == null) if (implementingClasses == null)
{ {
implementingClasses = new ConcurrentHashSet<String>(); implementingClasses = ConcurrentHashMap.newKeySet();
ConcurrentHashSet<String> tmp = _inheritanceMap.putIfAbsent(interfaceOrSuperClassName, implementingClasses); Set<String> tmp = _inheritanceMap.putIfAbsent(interfaceOrSuperClassName, implementingClasses);
if (tmp != null) if (tmp != null)
implementingClasses = tmp; implementingClasses = tmp;
} }

View File

@ -26,6 +26,8 @@ import static org.junit.Assert.assertTrue;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import javax.naming.Context; 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.ClassInfo;
import org.eclipse.jetty.annotations.AnnotationParser.FieldInfo; import org.eclipse.jetty.annotations.AnnotationParser.FieldInfo;
import org.eclipse.jetty.annotations.AnnotationParser.MethodInfo; import org.eclipse.jetty.annotations.AnnotationParser.MethodInfo;
import org.eclipse.jetty.util.ConcurrentHashSet;
import org.junit.After; import org.junit.After;
import org.junit.Test; import org.junit.Test;
@ -147,7 +148,7 @@ public class TestAnnotationInheritance
@Test @Test
public void testTypeInheritanceHandling() throws Exception public void testTypeInheritanceHandling() throws Exception
{ {
ConcurrentHashMap<String, ConcurrentHashSet<String>> map = new ConcurrentHashMap<String, ConcurrentHashSet<String>>(); Map<String, Set<String>> map = new ConcurrentHashMap<>();
AnnotationParser parser = new AnnotationParser(); AnnotationParser parser = new AnnotationParser();
ClassInheritanceHandler handler = new ClassInheritanceHandler(map); 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.ClassA"));
assertTrue (map.keySet().contains("org.eclipse.jetty.annotations.InterfaceD")); assertTrue (map.keySet().contains("org.eclipse.jetty.annotations.InterfaceD"));
ConcurrentHashSet<String> classes = map.get("org.eclipse.jetty.annotations.ClassA"); Set<String> classes = map.get("org.eclipse.jetty.annotations.ClassA");
assertEquals(1, classes.size()); assertEquals(1, classes.size());
assertEquals ("org.eclipse.jetty.annotations.ClassB", classes.iterator().next()); assertEquals ("org.eclipse.jetty.annotations.ClassB", classes.iterator().next());

View File

@ -20,6 +20,7 @@ package org.eclipse.jetty.http2.client.http;
import java.nio.channels.AsynchronousCloseException; import java.nio.channels.AsynchronousCloseException;
import java.util.Set; import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.TimeoutException; import java.util.concurrent.TimeoutException;
import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger; 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.ErrorCode;
import org.eclipse.jetty.http2.api.Session; import org.eclipse.jetty.http2.api.Session;
import org.eclipse.jetty.util.Callback; import org.eclipse.jetty.util.Callback;
import org.eclipse.jetty.util.ConcurrentHashSet;
import org.eclipse.jetty.util.thread.Sweeper; import org.eclipse.jetty.util.thread.Sweeper;
public class HttpConnectionOverHTTP2 extends HttpConnection implements Sweeper.Sweepable public class HttpConnectionOverHTTP2 extends HttpConnection implements Sweeper.Sweepable
{ {
private final Set<HttpChannel> channels = new ConcurrentHashSet<>(); private final Set<HttpChannel> channels = ConcurrentHashMap.newKeySet();
private final AtomicBoolean closed = new AtomicBoolean(); private final AtomicBoolean closed = new AtomicBoolean();
private final AtomicInteger sweeps = new AtomicInteger(); private final AtomicInteger sweeps = new AtomicInteger();
private final Session session; private final Session session;

View File

@ -30,7 +30,6 @@ import java.util.TreeSet;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import org.eclipse.jetty.osgi.boot.utils.BundleFileLocatorHelperFactory; import org.eclipse.jetty.osgi.boot.utils.BundleFileLocatorHelperFactory;
import org.eclipse.jetty.util.ConcurrentHashSet;
import org.eclipse.jetty.util.resource.Resource; import org.eclipse.jetty.util.resource.Resource;
import org.osgi.framework.Bundle; import org.osgi.framework.Bundle;
import org.osgi.framework.Constants; import org.osgi.framework.Constants;
@ -40,7 +39,7 @@ import org.osgi.framework.Constants;
*/ */
public class AnnotationParser extends org.eclipse.jetty.annotations.AnnotationParser public class AnnotationParser extends org.eclipse.jetty.annotations.AnnotationParser
{ {
private Set<URI> _alreadyParsed = new ConcurrentHashSet<URI>(); private Set<URI> _alreadyParsed = ConcurrentHashMap.newKeySet();
private ConcurrentHashMap<URI,Bundle> _uriToBundle = new ConcurrentHashMap<URI, Bundle>(); private ConcurrentHashMap<URI,Bundle> _uriToBundle = new ConcurrentHashMap<URI, Bundle>();
private ConcurrentHashMap<Bundle,Resource> _bundleToResource = new ConcurrentHashMap<Bundle,Resource>(); private ConcurrentHashMap<Bundle,Resource> _bundleToResource = new ConcurrentHashMap<Bundle,Resource>();

View File

@ -24,13 +24,13 @@ import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import javax.servlet.ServletContainerInitializer; import javax.servlet.ServletContainerInitializer;
import org.eclipse.jetty.util.ConcurrentHashSet;
import org.eclipse.jetty.util.Loader; import org.eclipse.jetty.util.Loader;
import org.eclipse.jetty.util.StringUtil; import org.eclipse.jetty.util.StringUtil;
import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.Log;
@ -43,8 +43,8 @@ public class ContainerInitializer
final protected ServletContainerInitializer _target; final protected ServletContainerInitializer _target;
final protected Class<?>[] _interestedTypes; final protected Class<?>[] _interestedTypes;
final protected Set<String> _applicableTypeNames = new ConcurrentHashSet<String>(); final protected Set<String> _applicableTypeNames = ConcurrentHashMap.newKeySet();
final protected Set<String> _annotatedTypeNames = new ConcurrentHashSet<String>(); final protected Set<String> _annotatedTypeNames = ConcurrentHashMap.newKeySet();
public ContainerInitializer (ServletContainerInitializer target, Class<?>[] classes) public ContainerInitializer (ServletContainerInitializer target, Class<?>[] classes)

View File

@ -29,6 +29,7 @@ import java.util.EventListener;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CopyOnWriteArrayList; import java.util.concurrent.CopyOnWriteArrayList;
import javax.servlet.AsyncEvent; 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.SessionIdManager;
import org.eclipse.jetty.server.handler.ContextHandler; import org.eclipse.jetty.server.handler.ContextHandler;
import org.eclipse.jetty.server.handler.ScopedHandler; import org.eclipse.jetty.server.handler.ScopedHandler;
import org.eclipse.jetty.util.ConcurrentHashSet;
import org.eclipse.jetty.util.StringUtil; import org.eclipse.jetty.util.StringUtil;
import org.eclipse.jetty.util.annotation.ManagedAttribute; import org.eclipse.jetty.util.annotation.ManagedAttribute;
import org.eclipse.jetty.util.annotation.ManagedObject; import org.eclipse.jetty.util.annotation.ManagedObject;
@ -247,7 +247,7 @@ public class SessionHandler extends ScopedHandler
protected boolean _usingURLs; protected boolean _usingURLs;
protected boolean _usingCookies=true; protected boolean _usingCookies=true;
protected ConcurrentHashSet<String> _candidateSessionIdsForExpiry = new ConcurrentHashSet<String>(); protected Set<String> _candidateSessionIdsForExpiry = ConcurrentHashMap.newKeySet();
protected Scheduler _scheduler; protected Scheduler _scheduler;
protected boolean _ownScheduler = false; protected boolean _ownScheduler = false;

View File

@ -25,6 +25,10 @@ import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
/**
* @deprecated Use Java 8 method {@code ConcurrentHashMap.newKeySet()} instead.
*/
@Deprecated
public class ConcurrentHashSet<E> extends AbstractSet<E> implements Set<E> public class ConcurrentHashSet<E> extends AbstractSet<E> implements Set<E>
{ {
private final Map<E, Boolean> _map = new ConcurrentHashMap<E, Boolean>(); private final Map<E, Boolean> _map = new ConcurrentHashMap<E, Boolean>();

View File

@ -24,14 +24,15 @@ import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Set;
import java.util.concurrent.BlockingQueue; import java.util.concurrent.BlockingQueue;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.RejectedExecutionException; import java.util.concurrent.RejectedExecutionException;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicLong; import java.util.concurrent.atomic.AtomicLong;
import org.eclipse.jetty.util.BlockingArrayQueue; 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.ManagedAttribute;
import org.eclipse.jetty.util.annotation.ManagedObject; import org.eclipse.jetty.util.annotation.ManagedObject;
import org.eclipse.jetty.util.annotation.ManagedOperation; 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 _threadsStarted = new AtomicInteger();
private final AtomicInteger _threadsIdle = new AtomicInteger(); private final AtomicInteger _threadsIdle = new AtomicInteger();
private final AtomicLong _lastShrink = new AtomicLong(); private final AtomicLong _lastShrink = new AtomicLong();
private final ConcurrentHashSet<Thread> _threads=new ConcurrentHashSet<>(); private final Set<Thread> _threads = ConcurrentHashMap.newKeySet();
private final Object _joinLock = new Object(); private final Object _joinLock = new Object();
private final BlockingQueue<Runnable> _jobs; private final BlockingQueue<Runnable> _jobs;
private final ThreadGroup _threadGroup; private final ThreadGroup _threadGroup;

View File

@ -20,9 +20,9 @@ package org.eclipse.jetty.webapp;
import java.io.IOException; import java.io.IOException;
import java.net.URL; import java.net.URL;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import org.eclipse.jetty.util.ConcurrentHashSet;
import org.eclipse.jetty.util.annotation.ManagedObject; import org.eclipse.jetty.util.annotation.ManagedObject;
import org.eclipse.jetty.util.annotation.ManagedOperation; import org.eclipse.jetty.util.annotation.ManagedOperation;
import org.eclipse.jetty.util.log.Log; 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 static final Logger LOG = Log.getLogger(CachingWebAppClassLoader.class);
private final ConcurrentHashSet<String> _notFound = new ConcurrentHashSet<>(); private final Set<String> _notFound = ConcurrentHashMap.newKeySet();
private final ConcurrentHashMap<String,URL> _cache = new ConcurrentHashMap<>(); private final ConcurrentHashMap<String,URL> _cache = new ConcurrentHashMap<>();
public CachingWebAppClassLoader(ClassLoader parent, Context context) throws IOException public CachingWebAppClassLoader(ClassLoader parent, Context context) throws IOException