Remove unnecessary parameter in AttributeKey and ChannelOption

- Removed UniqueKey which does nothing
- The valueType parameter was not needed at all because we do not need
  type information in runtime at all.
This commit is contained in:
Trustin Lee 2012-05-31 16:03:57 -07:00
parent 9bb5b34887
commit 468918227a
5 changed files with 32 additions and 67 deletions

View File

@ -36,8 +36,7 @@ import org.jboss.marshalling.Unmarshaller;
public class ContextBoundUnmarshallerProvider extends DefaultUnmarshallerProvider {
private static final AttributeKey<Unmarshaller> UNMARSHALLER = new AttributeKey<Unmarshaller>(
ContextBoundUnmarshallerProvider.class.getName() + ".unmarshaller",
Unmarshaller.class);
ContextBoundUnmarshallerProvider.class.getName() + ".unmarshaller");
public ContextBoundUnmarshallerProvider(MarshallerFactory factory, MarshallingConfiguration config) {
super(factory, config);

View File

@ -37,8 +37,7 @@ import java.io.Serializable;
public class CompatibleObjectEncoder extends MessageToStreamEncoder<Object> {
private static final AttributeKey<ObjectOutputStream> OOS =
new AttributeKey<ObjectOutputStream>(
CompatibleObjectEncoder.class.getName() + ".oos", ObjectOutputStream.class);
new AttributeKey<ObjectOutputStream>(CompatibleObjectEncoder.class.getName() + ".oos");
private final int resetInterval;
private int writtenObjects;

View File

@ -3,11 +3,11 @@ package io.netty.util;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
public final class AttributeKey<T> extends UniqueKey<T> {
public final class AttributeKey<T> extends UniqueName {
private static final ConcurrentMap<String, Boolean> names = new ConcurrentHashMap<String, Boolean>();
public AttributeKey(String name, Class<T> valueType) {
super(names, name, valueType);
public AttributeKey(String name) {
super(names, name);
}
}

View File

@ -1,32 +0,0 @@
package io.netty.util;
import java.util.concurrent.ConcurrentMap;
public class UniqueKey<T> extends UniqueName {
private final Class<T> valueType;
private final String strVal;
public UniqueKey(ConcurrentMap<String, Boolean> map, String name, Class<T> valueType) {
super(map, name, valueType);
this.valueType = valueType;
strVal = name + '[' + valueType.getSimpleName() + ']';
}
@Override
protected void validateArgs(Object... args) {
super.validateArgs(args);
if (args[0] == null) {
throw new NullPointerException("valueType");
}
}
public final Class<T> valueType() {
return valueType;
}
@Override
public String toString() {
return strVal;
}
}

View File

@ -1,6 +1,6 @@
package io.netty.channel;
import io.netty.util.UniqueKey;
import io.netty.util.UniqueName;
import java.net.InetAddress;
import java.net.NetworkInterface;
@ -9,56 +9,55 @@ import java.util.List;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
public class ChannelOption<T> extends UniqueKey<T> {
public class ChannelOption<T> extends UniqueName {
private static final ConcurrentMap<String, Boolean> names = new ConcurrentHashMap<String, Boolean>();
public static final ChannelOption<Integer> CONNECT_TIMEOUT_MILLIS =
new ChannelOption<Integer>("CONNECT_TIMEOUT_MILLIS", Integer.class);
new ChannelOption<Integer>("CONNECT_TIMEOUT_MILLIS");
public static final ChannelOption<Integer> WRITE_SPIN_COUNT =
new ChannelOption<Integer>("WRITE_SPIN_COUNT", Integer.class);
new ChannelOption<Integer>("WRITE_SPIN_COUNT");
public static final ChannelOption<Boolean> SO_BROADCAST =
new ChannelOption<Boolean>("SO_BROADCAST", Boolean.class);
new ChannelOption<Boolean>("SO_BROADCAST");
public static final ChannelOption<Boolean> SO_KEEPALIVE =
new ChannelOption<Boolean>("SO_KEEPALIVE", Boolean.class);
new ChannelOption<Boolean>("SO_KEEPALIVE");
public static final ChannelOption<Integer> SO_SNDBUF =
new ChannelOption<Integer>("SO_SNDBUF", Integer.class);
new ChannelOption<Integer>("SO_SNDBUF");
public static final ChannelOption<Integer> SO_RCVBUF =
new ChannelOption<Integer>("SO_RCVBUF", Integer.class);
new ChannelOption<Integer>("SO_RCVBUF");
public static final ChannelOption<Boolean> SO_REUSEADDR =
new ChannelOption<Boolean>("SO_REUSEADDR", Boolean.class);
new ChannelOption<Boolean>("SO_REUSEADDR");
public static final ChannelOption<Integer> SO_LINGER =
new ChannelOption<Integer>("SO_LINGER", Integer.class);
new ChannelOption<Integer>("SO_LINGER");
public static final ChannelOption<Integer> SO_BACKLOG =
new ChannelOption<Integer>("SO_BACKLOG", Integer.class);
new ChannelOption<Integer>("SO_BACKLOG");
public static final ChannelOption<Integer> IP_TOS =
new ChannelOption<Integer>("IP_TOS", Integer.class);
new ChannelOption<Integer>("IP_TOS");
public static final ChannelOption<InetAddress> IP_MULTICAST_ADDR =
new ChannelOption<InetAddress>("IP_MULTICAST_ADDR", InetAddress.class);
new ChannelOption<InetAddress>("IP_MULTICAST_ADDR");
public static final ChannelOption<NetworkInterface> IP_MULTICAST_IF =
new ChannelOption<NetworkInterface>("IP_MULTICAST_IF", NetworkInterface.class);
new ChannelOption<NetworkInterface>("IP_MULTICAST_IF");
public static final ChannelOption<Integer> IP_MULTICAST_TTL =
new ChannelOption<Integer>("IP_MULTICAST_TTL", Integer.class);
new ChannelOption<Integer>("IP_MULTICAST_TTL");
public static final ChannelOption<Boolean> IP_MULTICAST_LOOP_DISABLED =
new ChannelOption<Boolean>("IP_MULTICAST_LOOP_DISABLED", Boolean.class);
new ChannelOption<Boolean>("IP_MULTICAST_LOOP_DISABLED");
public static final ChannelOption<Integer> UDP_RECEIVE_PACKET_SIZE =
new ChannelOption<Integer>("UDP_RECEIVE_PACKET_SIZE", Integer.class);
new ChannelOption<Integer>("UDP_RECEIVE_PACKET_SIZE");
public static final ChannelOption<Boolean> TCP_NODELAY =
new ChannelOption<Boolean>("TCP_NODELAY", Boolean.class);
new ChannelOption<Boolean>("TCP_NODELAY");
public static final ChannelOption<Boolean> SCTP_DISABLE_FRAGMENTS =
new ChannelOption<Boolean>("SCTP_DISABLE_FRAGMENTS", Boolean.class);
new ChannelOption<Boolean>("SCTP_DISABLE_FRAGMENTS");
public static final ChannelOption<Boolean> SCTP_EXPLICIT_COMPLETE =
new ChannelOption<Boolean>("SCTP_EXPLICIT_COMPLETE", Boolean.class);
new ChannelOption<Boolean>("SCTP_EXPLICIT_COMPLETE");
public static final ChannelOption<Integer> SCTP_FRAGMENT_INTERLEAVE =
new ChannelOption<Integer>("SCTP_FRAGMENT_INTERLEAVE", Integer.class);
@SuppressWarnings("unchecked")
new ChannelOption<Integer>("SCTP_FRAGMENT_INTERLEAVE");
public static final ChannelOption<List<Integer>> SCTP_INIT_MAXSTREAMS =
new ChannelOption<List<Integer>>("SCTP_INIT_MAXSTREAMS", (Class<List<Integer>>)(Class<?>) List.class) {
new ChannelOption<List<Integer>>("SCTP_INIT_MAXSTREAMS") {
@Override
public void validate(List<Integer> value) {
super.validate(value);
@ -74,14 +73,14 @@ public class ChannelOption<T> extends UniqueKey<T> {
}
};
public static final ChannelOption<Boolean> SCTP_NODELAY =
new ChannelOption<Boolean>("SCTP_NODELAY", Boolean.class);
new ChannelOption<Boolean>("SCTP_NODELAY");
public static final ChannelOption<SocketAddress> SCTP_PRIMARY_ADDR =
new ChannelOption<SocketAddress>("SCTP_PRIMARY_ADDR", SocketAddress.class);
new ChannelOption<SocketAddress>("SCTP_PRIMARY_ADDR");
public static final ChannelOption<SocketAddress> SCTP_SET_PEER_PRIMARY_ADDR =
new ChannelOption<SocketAddress>("SCTP_SET_PEER_PRIMARY_ADDR", SocketAddress.class);
new ChannelOption<SocketAddress>("SCTP_SET_PEER_PRIMARY_ADDR");
public ChannelOption(String name, Class<T> valueType) {
super(names, name, valueType);
public ChannelOption(String name) {
super(names, name);
}
public void validate(T value) {