Deprecate UniqueName and its subtypes' constructors / Add valueOf() for easier future migration.

This commit is contained in:
Trustin Lee 2013-10-25 20:53:47 +09:00
parent 8930cefab8
commit 8986245b47
7 changed files with 70 additions and 62 deletions

View File

@ -26,16 +26,23 @@ import java.util.concurrent.ConcurrentMap;
*
* @param <T> the type of the {@link Attribute} which can be accessed via this {@link AttributeKey}.
*/
@SuppressWarnings("UnusedDeclaration") // 'T' is used only at compile time
@SuppressWarnings({"UnusedDeclaration", "deprecation"}) // 'T' is used only at compile time
public final class AttributeKey<T> extends UniqueName {
private static final ConcurrentMap<String, Boolean> names = PlatformDependent.newConcurrentHashMap();
/**
* Create a new instance
*
* @param name the name under which the {@link AttributeKey} will be registered
* Creates a new {@link AttributeKey} with the specified {@code name}.
*/
@SuppressWarnings("deprecation")
public static <T> AttributeKey<T> valueOf(String name) {
return new AttributeKey<T>(name);
}
/**
* @deprecated Use {@link #valueOf(String)} instead.
*/
@Deprecated
public AttributeKey(String name) {
super(names, name);
}

View File

@ -30,13 +30,21 @@ public final class Signal extends Error {
private static final ConcurrentMap<String, Boolean> map = PlatformDependent.newConcurrentHashMap();
@SuppressWarnings("deprecation")
private final UniqueName uname;
/**
* Create a new instance
*
* @param name the name under which it is registered
* Creates a new {@link Signal} with the specified {@code name}.
*/
@SuppressWarnings("deprecation")
public static Signal valueOf(String name) {
return new Signal(name);
}
/**
* @deprecated Use {@link #valueOf(String)} instead.
*/
@Deprecated
public Signal(String name) {
super(name);
uname = new UniqueName(map, name);

View File

@ -19,8 +19,11 @@ import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.atomic.AtomicInteger;
/**
* @deprecated Known to have problems with class loaders.
*
* Defines a name that must be unique in the map that is provided during construction.
*/
@Deprecated
public class UniqueName implements Comparable<UniqueName> {
private static final AtomicInteger nextId = new AtomicInteger();

View File

@ -48,6 +48,7 @@ public final class RxtxChannelOption<T> extends ChannelOption<T> {
public static final RxtxChannelOption<Integer> READ_TIMEOUT =
new RxtxChannelOption<Integer>("READ_TIMEOUT");
@SuppressWarnings("deprecation")
private RxtxChannelOption(String name) {
super(name);
}

View File

@ -23,6 +23,7 @@ import java.net.SocketAddress;
/**
* Option for configuring the SCTP transport
*/
@SuppressWarnings("deprecation")
public class SctpChannelOption<T> extends ChannelOption<T> {
public static final SctpChannelOption<Boolean> SCTP_DISABLE_FRAGMENTS =
new SctpChannelOption<Boolean>("SCTP_DISABLE_FRAGMENTS");
@ -40,6 +41,10 @@ public class SctpChannelOption<T> extends ChannelOption<T> {
public static final SctpChannelOption<SocketAddress> SCTP_SET_PEER_PRIMARY_ADDR =
new SctpChannelOption<SocketAddress>("SCTP_SET_PEER_PRIMARY_ADDR");
/**
* @deprecated Will be removed in the future release.
*/
@Deprecated
protected SctpChannelOption(String name) {
super(name);
}

View File

@ -47,6 +47,7 @@ public final class UdtChannelOption<T> extends ChannelOption<T> {
public static final UdtChannelOption<Integer> SYSTEM_SEND_BUFFER_SIZE = new UdtChannelOption<Integer>(
"SYSTEM_SEND_BUFFER_SIZE");
@SuppressWarnings("deprecation")
private UdtChannelOption(String name) {
super(name);
}

View File

@ -31,78 +31,61 @@ import java.util.concurrent.ConcurrentMap;
*
* @param <T> the type of the value which is valid for the {@link ChannelOption}
*/
@SuppressWarnings("deprecation")
public class ChannelOption<T> extends UniqueName {
private static final ConcurrentMap<String, Boolean> names = PlatformDependent.newConcurrentHashMap();
public static final ChannelOption<ByteBufAllocator> ALLOCATOR =
new ChannelOption<ByteBufAllocator>("ALLOCATOR");
public static final ChannelOption<RecvByteBufAllocator> RCVBUF_ALLOCATOR =
new ChannelOption<RecvByteBufAllocator>("RCVBUF_ALLOCATOR");
public static final ChannelOption<MessageSizeEstimator> MESSAGE_SIZE_ESTIMATOR =
new ChannelOption<MessageSizeEstimator>("MESSAGE_SIZE_ESTIMATOR");
public static final ChannelOption<ByteBufAllocator> ALLOCATOR = valueOf("ALLOCATOR");
public static final ChannelOption<RecvByteBufAllocator> RCVBUF_ALLOCATOR = valueOf("RCVBUF_ALLOCATOR");
public static final ChannelOption<MessageSizeEstimator> MESSAGE_SIZE_ESTIMATOR = valueOf("MESSAGE_SIZE_ESTIMATOR");
public static final ChannelOption<Integer> CONNECT_TIMEOUT_MILLIS =
new ChannelOption<Integer>("CONNECT_TIMEOUT_MILLIS");
public static final ChannelOption<Integer> MAX_MESSAGES_PER_READ =
new ChannelOption<Integer>("MAX_MESSAGES_PER_READ");
public static final ChannelOption<Integer> WRITE_SPIN_COUNT =
new ChannelOption<Integer>("WRITE_SPIN_COUNT");
public static final ChannelOption<Integer> WRITE_BUFFER_HIGH_WATER_MARK =
new ChannelOption<Integer>("WRITE_BUFFER_HIGH_WATER_MARK");
public static final ChannelOption<Integer> WRITE_BUFFER_LOW_WATER_MARK =
new ChannelOption<Integer>("WRITE_BUFFER_LOW_WATER_MARK");
public static final ChannelOption<Integer> CONNECT_TIMEOUT_MILLIS = valueOf("CONNECT_TIMEOUT_MILLIS");
public static final ChannelOption<Integer> MAX_MESSAGES_PER_READ = valueOf("MAX_MESSAGES_PER_READ");
public static final ChannelOption<Integer> WRITE_SPIN_COUNT = valueOf("WRITE_SPIN_COUNT");
public static final ChannelOption<Integer> WRITE_BUFFER_HIGH_WATER_MARK = valueOf("WRITE_BUFFER_HIGH_WATER_MARK");
public static final ChannelOption<Integer> WRITE_BUFFER_LOW_WATER_MARK = valueOf("WRITE_BUFFER_LOW_WATER_MARK");
public static final ChannelOption<Boolean> ALLOW_HALF_CLOSURE =
new ChannelOption<Boolean>("ALLOW_HALF_CLOSURE");
public static final ChannelOption<Boolean> AUTO_READ =
new ChannelOption<Boolean>("AUTO_READ");
public static final ChannelOption<Boolean> ALLOW_HALF_CLOSURE = valueOf("ALLOW_HALF_CLOSURE");
public static final ChannelOption<Boolean> AUTO_READ = valueOf("AUTO_READ");
public static final ChannelOption<Boolean> SO_BROADCAST =
new ChannelOption<Boolean>("SO_BROADCAST");
public static final ChannelOption<Boolean> SO_KEEPALIVE =
new ChannelOption<Boolean>("SO_KEEPALIVE");
public static final ChannelOption<Integer> SO_SNDBUF =
new ChannelOption<Integer>("SO_SNDBUF");
public static final ChannelOption<Integer> SO_RCVBUF =
new ChannelOption<Integer>("SO_RCVBUF");
public static final ChannelOption<Boolean> SO_REUSEADDR =
new ChannelOption<Boolean>("SO_REUSEADDR");
public static final ChannelOption<Integer> SO_LINGER =
new ChannelOption<Integer>("SO_LINGER");
public static final ChannelOption<Integer> SO_BACKLOG =
new ChannelOption<Integer>("SO_BACKLOG");
public static final ChannelOption<Integer> SO_TIMEOUT =
new ChannelOption<Integer>("SO_TIMEOUT");
public static final ChannelOption<Boolean> SO_BROADCAST = valueOf("SO_BROADCAST");
public static final ChannelOption<Boolean> SO_KEEPALIVE = valueOf("SO_KEEPALIVE");
public static final ChannelOption<Integer> SO_SNDBUF = valueOf("SO_SNDBUF");
public static final ChannelOption<Integer> SO_RCVBUF = valueOf("SO_RCVBUF");
public static final ChannelOption<Boolean> SO_REUSEADDR = valueOf("SO_REUSEADDR");
public static final ChannelOption<Integer> SO_LINGER = valueOf("SO_LINGER");
public static final ChannelOption<Integer> SO_BACKLOG = valueOf("SO_BACKLOG");
public static final ChannelOption<Integer> SO_TIMEOUT = valueOf("SO_TIMEOUT");
public static final ChannelOption<Integer> IP_TOS =
new ChannelOption<Integer>("IP_TOS");
public static final ChannelOption<InetAddress> IP_MULTICAST_ADDR =
new ChannelOption<InetAddress>("IP_MULTICAST_ADDR");
public static final ChannelOption<NetworkInterface> IP_MULTICAST_IF =
new ChannelOption<NetworkInterface>("IP_MULTICAST_IF");
public static final ChannelOption<Integer> IP_MULTICAST_TTL =
new ChannelOption<Integer>("IP_MULTICAST_TTL");
public static final ChannelOption<Boolean> IP_MULTICAST_LOOP_DISABLED =
new ChannelOption<Boolean>("IP_MULTICAST_LOOP_DISABLED");
public static final ChannelOption<Integer> IP_TOS = valueOf("IP_TOS");
public static final ChannelOption<InetAddress> IP_MULTICAST_ADDR = valueOf("IP_MULTICAST_ADDR");
public static final ChannelOption<NetworkInterface> IP_MULTICAST_IF = valueOf("IP_MULTICAST_IF");
public static final ChannelOption<Integer> IP_MULTICAST_TTL = valueOf("IP_MULTICAST_TTL");
public static final ChannelOption<Boolean> IP_MULTICAST_LOOP_DISABLED = valueOf("IP_MULTICAST_LOOP_DISABLED");
public static final ChannelOption<Boolean> TCP_NODELAY =
new ChannelOption<Boolean>("TCP_NODELAY");
public static final ChannelOption<Boolean> TCP_NODELAY = valueOf("TCP_NODELAY");
@Deprecated
public static final ChannelOption<Long> AIO_READ_TIMEOUT =
new ChannelOption<Long>("AIO_READ_TIMEOUT");
public static final ChannelOption<Long> AIO_READ_TIMEOUT = valueOf("AIO_READ_TIMEOUT");
@Deprecated
public static final ChannelOption<Long> AIO_WRITE_TIMEOUT =
new ChannelOption<Long>("AIO_WRITE_TIMEOUT");
public static final ChannelOption<Long> AIO_WRITE_TIMEOUT = valueOf("AIO_WRITE_TIMEOUT");
@Deprecated
public static final ChannelOption<Boolean> DATAGRAM_CHANNEL_ACTIVE_ON_REGISTRATION =
new ChannelOption<Boolean>("DATAGRAM_CHANNEL_ACTIVE_ON_REGISTRATION");
valueOf("DATAGRAM_CHANNEL_ACTIVE_ON_REGISTRATION");
/**
* Create a new {@link ChannelOption} with the given name. The name needs to be
* unique.
* Creates a new {@link ChannelOption} with the specified {@code name}.
*/
public static <T> ChannelOption<T> valueOf(String name) {
return new ChannelOption<T>(name);
}
/**
* @deprecated Use {@link #valueOf(String)} instead.
*/
@Deprecated
protected ChannelOption(String name) {
super(names, name);
}