diff --git a/common/src/main/java/io/netty/util/internal/ConcurrentSet.java b/common/src/main/java/io/netty/util/internal/ConcurrentSet.java deleted file mode 100644 index a735f4e430..0000000000 --- a/common/src/main/java/io/netty/util/internal/ConcurrentSet.java +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Copyright 2013 The Netty Project - * - * The Netty Project licenses this file to you under the Apache License, - * version 2.0 (the "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ -package io.netty.util.internal; - -import java.io.Serializable; -import java.util.AbstractSet; -import java.util.Iterator; -import java.util.concurrent.ConcurrentMap; - -/** - * @deprecated For removal in Netty 4.2. Please use {@link ConcurrentHashMap#newKeySet()} instead - */ -@Deprecated -public final class ConcurrentSet extends AbstractSet implements Serializable { - - private static final long serialVersionUID = -6761513279741915432L; - - private final ConcurrentMap map; - - /** - * Creates a new instance which wraps the specified {@code map}. - */ - public ConcurrentSet() { - map = PlatformDependent.newConcurrentHashMap(); - } - - @Override - public int size() { - return map.size(); - } - - @Override - public boolean contains(Object o) { - return map.containsKey(o); - } - - @Override - public boolean add(E o) { - return map.putIfAbsent(o, Boolean.TRUE) == null; - } - - @Override - public boolean remove(Object o) { - return map.remove(o) != null; - } - - @Override - public void clear() { - map.clear(); - } - - @Override - public Iterator iterator() { - return map.keySet().iterator(); - } -} diff --git a/common/src/main/java/io/netty/util/internal/ObjectCleaner.java b/common/src/main/java/io/netty/util/internal/ObjectCleaner.java index c8f2353daa..a4cbbfa7cb 100644 --- a/common/src/main/java/io/netty/util/internal/ObjectCleaner.java +++ b/common/src/main/java/io/netty/util/internal/ObjectCleaner.java @@ -22,6 +22,7 @@ import java.lang.ref.WeakReference; import java.security.AccessController; import java.security.PrivilegedAction; import java.util.Set; +import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.atomic.AtomicBoolean; import static io.netty.util.internal.SystemPropertyUtil.getInt; @@ -38,8 +39,8 @@ public final class ObjectCleaner { // Package-private for testing static final String CLEANER_THREAD_NAME = ObjectCleaner.class.getSimpleName() + "Thread"; // This will hold a reference to the AutomaticCleanerReference which will be removed once we called cleanup() - private static final Set LIVE_SET = new ConcurrentSet(); - private static final ReferenceQueue REFERENCE_QUEUE = new ReferenceQueue(); + private static final Set LIVE_SET = ConcurrentHashMap.newKeySet(); + private static final ReferenceQueue REFERENCE_QUEUE = new ReferenceQueue<>(); private static final AtomicBoolean CLEANER_RUNNING = new AtomicBoolean(false); private static final Runnable CLEANER_TASK = new Runnable() { @Override diff --git a/handler/src/main/java/io/netty/handler/ipfilter/UniqueIpFilter.java b/handler/src/main/java/io/netty/handler/ipfilter/UniqueIpFilter.java index 15099bb2a3..fcd6b08a87 100644 --- a/handler/src/main/java/io/netty/handler/ipfilter/UniqueIpFilter.java +++ b/handler/src/main/java/io/netty/handler/ipfilter/UniqueIpFilter.java @@ -20,11 +20,11 @@ import io.netty.channel.ChannelFuture; import io.netty.channel.ChannelFutureListener; import io.netty.channel.ChannelHandler; import io.netty.channel.ChannelHandlerContext; -import io.netty.util.internal.ConcurrentSet; import java.net.InetAddress; import java.net.InetSocketAddress; import java.util.Set; +import java.util.concurrent.ConcurrentHashMap; /** * This class allows one to ensure that at all times for every IP address there is at most one @@ -33,17 +33,17 @@ import java.util.Set; @ChannelHandler.Sharable public class UniqueIpFilter extends AbstractRemoteAddressFilter { - private final Set connected = new ConcurrentSet(); + private final Set connected = ConcurrentHashMap.newKeySet(); @Override - protected boolean accept(ChannelHandlerContext ctx, InetSocketAddress remoteAddress) throws Exception { + protected boolean accept(ChannelHandlerContext ctx, InetSocketAddress remoteAddress) { final InetAddress remoteIp = remoteAddress.getAddress(); if (!connected.add(remoteIp)) { return false; } else { ctx.channel().closeFuture().addListener(new ChannelFutureListener() { @Override - public void operationComplete(ChannelFuture future) throws Exception { + public void operationComplete(ChannelFuture future) { connected.remove(remoteIp); } });