Skip to content

Commit

Permalink
Ensure backward-compability with 4.0
Browse files Browse the repository at this point in the history
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
  • Loading branch information
normanmaurer committed Apr 19, 2015
1 parent 3850cff commit b4b14ea
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 11 deletions.
9 changes: 9 additions & 0 deletions common/src/main/java/io/netty/util/ConstantPool.java
Original file line number Diff line number Diff line change
Expand Up @@ -113,4 +113,13 @@ public T newInstance(String name) {
}

protected abstract T newConstant(int id, String name);

@Deprecated
public final int nextId() {
synchronized (constants) {
int id = nextId;
nextId++;
return id;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
import io.netty.channel.ChannelOption;
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;

public static final ChannelOption<Boolean> TCP_CORK = ChannelOption.valueOf(T, "TCP_CORK");
Expand All @@ -30,5 +31,9 @@ public final class EpollChannelOption {
ChannelOption.valueOf(T, "DOMAIN_SOCKET_READ_MODE");
public static final ChannelOption<EpollMode> EPOLL_MODE =
ChannelOption.valueOf(T, "EPOLL_MODE");
private EpollChannelOption() { }

@SuppressWarnings({ "unused", "deprecation" })
private EpollChannelOption() {
super(null);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,12 @@
import io.netty.channel.rxtx.RxtxChannelConfig.Paritybit;
import io.netty.channel.rxtx.RxtxChannelConfig.Stopbits;

import static io.netty.channel.ChannelOption.*;

/**
* 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;

public static final ChannelOption<Integer> BAUD_RATE = valueOf(T, "BAUD_RATE");
Expand All @@ -38,5 +37,8 @@ public final class RxtxChannelOption {
public static final ChannelOption<Integer> WAIT_TIME = valueOf(T, "WAIT_TIME");
public static final ChannelOption<Integer> READ_TIMEOUT = valueOf(T, "READ_TIMEOUT");

private RxtxChannelOption() { }
@SuppressWarnings({ "unused", "deprecation" })
private RxtxChannelOption() {
super(null);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@
/**
* 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;

public static final ChannelOption<Boolean> SCTP_DISABLE_FRAGMENTS = valueOf(T, "SCTP_DISABLE_FRAGMENTS");
Expand All @@ -39,5 +40,8 @@ public final class SctpChannelOption {
public static final ChannelOption<SocketAddress> SCTP_SET_PEER_PRIMARY_ADDR =
valueOf(T, "SCTP_SET_PEER_PRIMARY_ADDR");

private SctpChannelOption() { }
@SuppressWarnings({ "unused", "deprecation" })
private SctpChannelOption() {
super(null);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@
/**
* 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;

/**
Expand All @@ -48,5 +49,8 @@ public final class UdtChannelOption {
*/
public static final ChannelOption<Integer> SYSTEM_SEND_BUFFER_SIZE = valueOf(T, "SYSTEM_SEND_BUFFER_SIZE");

private UdtChannelOption() { }
@SuppressWarnings({ "unused", "deprecation" })
private UdtChannelOption() {
super(null);
}
}
8 changes: 7 additions & 1 deletion transport/src/main/java/io/netty/channel/ChannelOption.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,10 @@
*
* @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>>() {
@SuppressWarnings("deprecation")
@Override
protected ChannelOption<Object> newConstant(int id, String name) {
return new ChannelOption<Object>(id, name);
Expand Down Expand Up @@ -121,6 +122,11 @@ private ChannelOption(int id, String 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
* may override this for special checks.
Expand Down

0 comments on commit b4b14ea

Please sign in to comment.