Ensure backward-compability with 4.0

Motivation:

Each different *ChannelOption did extend ChannelOption in 4.0, which we changed in 4.1. This is a breaking change in terms of the API so we need to ensure we keep the old hierarchy.

Modifications:

- Let all *ChannelOption extend ChannelOption
- Add back constructor and mark it as @deprecated

Result:

No API breakage between 4.0 and 4.1
This commit is contained in:
Norman Maurer 2015-04-15 22:48:21 +02:00
parent 3850cff0fc
commit b4b14ea19f
6 changed files with 41 additions and 11 deletions

View File

@ -113,4 +113,13 @@ public abstract class ConstantPool<T extends Constant<T>> {
} }
protected abstract T newConstant(int id, String name); protected abstract T newConstant(int id, String name);
@Deprecated
public final int nextId() {
synchronized (constants) {
int id = nextId;
nextId++;
return id;
}
}
} }

View File

@ -18,7 +18,8 @@ package io.netty.channel.epoll;
import io.netty.channel.ChannelOption; import io.netty.channel.ChannelOption;
import io.netty.channel.unix.DomainSocketReadMode; import io.netty.channel.unix.DomainSocketReadMode;
public final class EpollChannelOption { public final class EpollChannelOption<T> extends ChannelOption<T> {
@SuppressWarnings("rawtypes")
private static final Class<EpollChannelOption> T = EpollChannelOption.class; private static final Class<EpollChannelOption> T = EpollChannelOption.class;
public static final ChannelOption<Boolean> TCP_CORK = ChannelOption.valueOf(T, "TCP_CORK"); public static final ChannelOption<Boolean> TCP_CORK = ChannelOption.valueOf(T, "TCP_CORK");
@ -30,5 +31,9 @@ public final class EpollChannelOption {
ChannelOption.valueOf(T, "DOMAIN_SOCKET_READ_MODE"); ChannelOption.valueOf(T, "DOMAIN_SOCKET_READ_MODE");
public static final ChannelOption<EpollMode> EPOLL_MODE = public static final ChannelOption<EpollMode> EPOLL_MODE =
ChannelOption.valueOf(T, "EPOLL_MODE"); ChannelOption.valueOf(T, "EPOLL_MODE");
private EpollChannelOption() { }
@SuppressWarnings({ "unused", "deprecation" })
private EpollChannelOption() {
super(null);
}
} }

View File

@ -20,13 +20,12 @@ import io.netty.channel.rxtx.RxtxChannelConfig.Databits;
import io.netty.channel.rxtx.RxtxChannelConfig.Paritybit; import io.netty.channel.rxtx.RxtxChannelConfig.Paritybit;
import io.netty.channel.rxtx.RxtxChannelConfig.Stopbits; import io.netty.channel.rxtx.RxtxChannelConfig.Stopbits;
import static io.netty.channel.ChannelOption.*;
/** /**
* Option for configuring a serial port connection * Option for configuring a serial port connection
*/ */
public final class RxtxChannelOption { public final class RxtxChannelOption<T> extends ChannelOption<T> {
@SuppressWarnings("rawtypes")
private static final Class<RxtxChannelOption> T = RxtxChannelOption.class; private static final Class<RxtxChannelOption> T = RxtxChannelOption.class;
public static final ChannelOption<Integer> BAUD_RATE = valueOf(T, "BAUD_RATE"); public static final ChannelOption<Integer> BAUD_RATE = valueOf(T, "BAUD_RATE");
@ -38,5 +37,8 @@ public final class RxtxChannelOption {
public static final ChannelOption<Integer> WAIT_TIME = valueOf(T, "WAIT_TIME"); public static final ChannelOption<Integer> WAIT_TIME = valueOf(T, "WAIT_TIME");
public static final ChannelOption<Integer> READ_TIMEOUT = valueOf(T, "READ_TIMEOUT"); public static final ChannelOption<Integer> READ_TIMEOUT = valueOf(T, "READ_TIMEOUT");
private RxtxChannelOption() { } @SuppressWarnings({ "unused", "deprecation" })
private RxtxChannelOption() {
super(null);
}
} }

View File

@ -25,8 +25,9 @@ import static io.netty.channel.ChannelOption.*;
/** /**
* Option for configuring the SCTP transport * Option for configuring the SCTP transport
*/ */
public final class SctpChannelOption { public final class SctpChannelOption<T> extends ChannelOption<T> {
@SuppressWarnings("rawtypes")
private static final Class<SctpChannelOption> T = SctpChannelOption.class; private static final Class<SctpChannelOption> T = SctpChannelOption.class;
public static final ChannelOption<Boolean> SCTP_DISABLE_FRAGMENTS = valueOf(T, "SCTP_DISABLE_FRAGMENTS"); public static final ChannelOption<Boolean> SCTP_DISABLE_FRAGMENTS = valueOf(T, "SCTP_DISABLE_FRAGMENTS");
@ -39,5 +40,8 @@ public final class SctpChannelOption {
public static final ChannelOption<SocketAddress> SCTP_SET_PEER_PRIMARY_ADDR = public static final ChannelOption<SocketAddress> SCTP_SET_PEER_PRIMARY_ADDR =
valueOf(T, "SCTP_SET_PEER_PRIMARY_ADDR"); valueOf(T, "SCTP_SET_PEER_PRIMARY_ADDR");
private SctpChannelOption() { } @SuppressWarnings({ "unused", "deprecation" })
private SctpChannelOption() {
super(null);
}
} }

View File

@ -23,8 +23,9 @@ import static io.netty.channel.ChannelOption.*;
/** /**
* Options for the UDT transport * Options for the UDT transport
*/ */
public final class UdtChannelOption { public final class UdtChannelOption<T> extends ChannelOption<T> {
@SuppressWarnings("rawtypes")
private static final Class<UdtChannelOption> T = UdtChannelOption.class; private static final Class<UdtChannelOption> T = UdtChannelOption.class;
/** /**
@ -48,5 +49,8 @@ public final class UdtChannelOption {
*/ */
public static final ChannelOption<Integer> SYSTEM_SEND_BUFFER_SIZE = valueOf(T, "SYSTEM_SEND_BUFFER_SIZE"); public static final ChannelOption<Integer> SYSTEM_SEND_BUFFER_SIZE = valueOf(T, "SYSTEM_SEND_BUFFER_SIZE");
private UdtChannelOption() { } @SuppressWarnings({ "unused", "deprecation" })
private UdtChannelOption() {
super(null);
}
} }

View File

@ -30,9 +30,10 @@ import java.net.NetworkInterface;
* *
* @param <T> the type of the value which is valid for the {@link ChannelOption} * @param <T> the type of the value which is valid for the {@link ChannelOption}
*/ */
public final class ChannelOption<T> extends AbstractConstant<ChannelOption<T>> { public class ChannelOption<T> extends AbstractConstant<ChannelOption<T>> {
private static final ConstantPool<ChannelOption<Object>> pool = new ConstantPool<ChannelOption<Object>>() { private static final ConstantPool<ChannelOption<Object>> pool = new ConstantPool<ChannelOption<Object>>() {
@SuppressWarnings("deprecation")
@Override @Override
protected ChannelOption<Object> newConstant(int id, String name) { protected ChannelOption<Object> newConstant(int id, String name) {
return new ChannelOption<Object>(id, name); return new ChannelOption<Object>(id, name);
@ -121,6 +122,11 @@ public final class ChannelOption<T> extends AbstractConstant<ChannelOption<T>> {
super(id, name); super(id, name);
} }
@Deprecated
protected ChannelOption(String name) {
this(pool.nextId(), name);
}
/** /**
* Validate the value which is set for the {@link ChannelOption}. Sub-classes * Validate the value which is set for the {@link ChannelOption}. Sub-classes
* may override this for special checks. * may override this for special checks.