Skip to content

Commit

Permalink
Deprecate ConcurrentHashSet (#1570)
Browse files Browse the repository at this point in the history
Signed-off-by: dreis2211 <christoph.dreis@freenet.de>
  • Loading branch information
dreis2211 authored and gregw committed May 30, 2017
1 parent ae49605 commit e9f398c
Show file tree
Hide file tree
Showing 11 changed files with 33 additions and 28 deletions.
Expand Up @@ -45,7 +45,6 @@

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;
Expand Down Expand Up @@ -381,7 +380,7 @@ public void configure(WebAppContext context) throws Exception
@Override
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);

context.removeAttribute(CLASS_INHERITANCE_MAP);
Expand Down Expand Up @@ -596,7 +595,7 @@ public void createServletContainerInitializerAnnotationHandlers (WebAppContext c
if (context.getAttribute(CLASS_INHERITANCE_MAP) == null)
{
//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);
_classInheritanceHandler = new ClassInheritanceHandler(map);
}
Expand Down Expand Up @@ -1072,7 +1071,7 @@ public boolean isMetaDataComplete (WebDescriptor d)
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
Expand Down
Expand Up @@ -28,10 +28,10 @@
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;
Expand Down Expand Up @@ -68,7 +68,7 @@ public class AnnotationParser
{
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

Expand Down
Expand Up @@ -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;

Expand All @@ -35,10 +36,10 @@ public class ClassInheritanceHandler extends AbstractHandler
{
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;
}
Expand Down Expand Up @@ -69,13 +70,13 @@ private void addToInheritanceMap (String interfaceOrSuperClassName, String imple
{

//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
//first and add it
if (implementingClasses == null)
{
implementingClasses = new ConcurrentHashSet<String>();
ConcurrentHashSet<String> tmp = _inheritanceMap.putIfAbsent(interfaceOrSuperClassName, implementingClasses);
implementingClasses = ConcurrentHashMap.newKeySet();
Set<String> tmp = _inheritanceMap.putIfAbsent(interfaceOrSuperClassName, implementingClasses);
if (tmp != null)
implementingClasses = tmp;
}
Expand Down
Expand Up @@ -26,6 +26,8 @@
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;
Expand All @@ -35,7 +37,6 @@
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;

Expand Down Expand Up @@ -147,7 +148,7 @@ public void testParseClass() throws Exception
@Test
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();
ClassInheritanceHandler handler = new ClassInheritanceHandler(map);
Expand All @@ -171,7 +172,7 @@ class Foo implements InterfaceD

assertTrue (map.keySet().contains("org.eclipse.jetty.annotations.ClassA"));
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 ("org.eclipse.jetty.annotations.ClassB", classes.iterator().next());

Expand Down
Expand Up @@ -20,6 +20,7 @@

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;
Expand All @@ -33,12 +34,11 @@
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<HttpChannel> channels = new ConcurrentHashSet<>();
private final Set<HttpChannel> channels = ConcurrentHashMap.newKeySet();
private final AtomicBoolean closed = new AtomicBoolean();
private final AtomicInteger sweeps = new AtomicInteger();
private final Session session;
Expand Down
Expand Up @@ -30,7 +30,6 @@
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;
Expand All @@ -40,7 +39,7 @@
*/
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<Bundle,Resource> _bundleToResource = new ConcurrentHashMap<Bundle,Resource>();
Expand Down
Expand Up @@ -24,13 +24,13 @@
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;
Expand All @@ -43,8 +43,8 @@ public class ContainerInitializer

final protected ServletContainerInitializer _target;
final protected Class<?>[] _interestedTypes;
final protected Set<String> _applicableTypeNames = new ConcurrentHashSet<String>();
final protected Set<String> _annotatedTypeNames = new ConcurrentHashSet<String>();
final protected Set<String> _applicableTypeNames = ConcurrentHashMap.newKeySet();
final protected Set<String> _annotatedTypeNames = ConcurrentHashMap.newKeySet();


public ContainerInitializer (ServletContainerInitializer target, Class<?>[] classes)
Expand Down
Expand Up @@ -29,6 +29,7 @@
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;
Expand All @@ -54,7 +55,6 @@
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;
Expand Down Expand Up @@ -247,7 +247,7 @@ public Enumeration getIds()
protected boolean _usingURLs;
protected boolean _usingCookies=true;

protected ConcurrentHashSet<String> _candidateSessionIdsForExpiry = new ConcurrentHashSet<String>();
protected Set<String> _candidateSessionIdsForExpiry = ConcurrentHashMap.newKeySet();

protected Scheduler _scheduler;
protected boolean _ownScheduler = false;
Expand Down
Expand Up @@ -25,6 +25,10 @@
import java.util.Set;
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>
{
private final Map<E, Boolean> _map = new ConcurrentHashMap<E, Boolean>();
Expand Down
Expand Up @@ -24,14 +24,15 @@
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;
Expand All @@ -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<Thread> _threads=new ConcurrentHashSet<>();
private final Set<Thread> _threads = ConcurrentHashMap.newKeySet();
private final Object _joinLock = new Object();
private final BlockingQueue<Runnable> _jobs;
private final ThreadGroup _threadGroup;
Expand Down
Expand Up @@ -20,9 +20,9 @@

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;
Expand All @@ -40,7 +40,7 @@ public class CachingWebAppClassLoader extends WebAppClassLoader
{
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<>();

public CachingWebAppClassLoader(ClassLoader parent, Context context) throws IOException
Expand Down

0 comments on commit e9f398c

Please sign in to comment.