Skip to content

Commit

Permalink
[netty#917] Move transport depending ChannelOption to the specific tr…
Browse files Browse the repository at this point in the history
…ansport to make it consistent
  • Loading branch information
Norman Maurer committed Jan 16, 2013
1 parent b7de868 commit 895bce6
Show file tree
Hide file tree
Showing 14 changed files with 134 additions and 72 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
import io.netty.bootstrap.Bootstrap;
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelOption;
import io.netty.channel.sctp.SctpChannel;
import io.netty.channel.sctp.SctpChannelOption;
import io.netty.channel.socket.nio.NioEventLoopGroup;
import io.netty.channel.sctp.nio.NioSctpChannel;
import io.netty.handler.logging.LogLevel;
Expand Down Expand Up @@ -53,7 +53,7 @@ public void run() throws Exception {
try {
b.group(new NioEventLoopGroup())
.channel(NioSctpChannel.class)
.option(ChannelOption.SCTP_NODELAY, true)
.option(SctpChannelOption.SCTP_NODELAY, true)
.remoteAddress(new InetSocketAddress(host, port))
.handler(new ChannelInitializer<SctpChannel>() {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelOption;
import io.netty.channel.sctp.SctpChannel;
import io.netty.channel.sctp.SctpChannelOption;
import io.netty.channel.socket.nio.NioEventLoopGroup;
import io.netty.channel.sctp.nio.NioSctpServerChannel;
import io.netty.handler.logging.LogLevel;
Expand All @@ -46,7 +47,7 @@ public void run() throws Exception {
.channel(NioSctpServerChannel.class)
.option(ChannelOption.SO_BACKLOG, 100)
.localAddress(new InetSocketAddress(port))
.childOption(ChannelOption.SCTP_NODELAY, true)
.childOption(SctpChannelOption.SCTP_NODELAY, true)
.handler(new LoggingHandler(LogLevel.INFO))
.childHandler(new ChannelInitializer<SctpChannel>() {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
import io.netty.bootstrap.Bootstrap;
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelOption;
import io.netty.channel.sctp.SctpChannel;
import io.netty.channel.sctp.SctpChannelOption;
import io.netty.channel.socket.oio.OioEventLoopGroup;
import io.netty.channel.sctp.oio.OioSctpChannel;
import io.netty.handler.logging.LogLevel;
Expand Down Expand Up @@ -53,7 +53,7 @@ public void run() throws Exception {
try {
b.group(new OioEventLoopGroup())
.channel(OioSctpChannel.class)
.option(ChannelOption.SCTP_NODELAY, true)
.option(SctpChannelOption.SCTP_NODELAY, true)
.remoteAddress(new InetSocketAddress(host, port))
.handler(new ChannelInitializer<SctpChannel>() {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelOption;
import io.netty.channel.sctp.SctpChannel;
import io.netty.channel.sctp.SctpChannelOption;
import io.netty.channel.socket.oio.OioEventLoopGroup;
import io.netty.channel.sctp.oio.OioSctpServerChannel;
import io.netty.handler.logging.LogLevel;
Expand All @@ -46,7 +47,7 @@ public void run() throws Exception {
.channel(OioSctpServerChannel.class)
.option(ChannelOption.SO_BACKLOG, 100)
.localAddress(new InetSocketAddress(port))
.childOption(ChannelOption.SCTP_NODELAY, true)
.childOption(SctpChannelOption.SCTP_NODELAY, true)
.handler(new LoggingHandler(LogLevel.INFO))
.childHandler(new ChannelInitializer<SctpChannel>() {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
import java.net.SocketTimeoutException;
import java.nio.channels.NotYetConnectedException;

import static io.netty.channel.rxtx.RxtxChannelOptions.*;
import static io.netty.channel.rxtx.RxtxChannelOption.*;

/**
* A channel to a serial device using the RXTX library.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

import java.util.Map;

import static io.netty.channel.rxtx.RxtxChannelOptions.*;
import static io.netty.channel.rxtx.RxtxChannelOption.*;

/**
* A configuration class for RXTX device connections.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@
import io.netty.channel.rxtx.RxtxChannelConfig.Stopbits;

/**
* Options for configuring a serial port connection
* Option for configuring a serial port connection
*/
public final class RxtxChannelOptions {
public final class RxtxChannelOption<T> extends ChannelOption<T> {
public static final ChannelOption<Integer> BAUD_RATE =
new ChannelOption<Integer>("BAUD_RATE");

Expand All @@ -42,6 +42,7 @@ public final class RxtxChannelOptions {
public static final ChannelOption<Paritybit> PARITY_BIT =
new ChannelOption<Paritybit>("PARITY_BIT");

private RxtxChannelOptions() {
public RxtxChannelOption(String name) {
super(name);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package io.netty.channel.sctp;


import com.sun.nio.sctp.SctpChannel;
import com.sun.nio.sctp.SctpStandardSocketOptions;
import io.netty.buffer.ByteBufAllocator;
Expand All @@ -25,7 +26,7 @@
import java.io.IOException;
import java.util.Map;

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

/**
* The default {@link SctpChannelConfig} implementation for SCTP.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public DefaultSctpServerChannelConfig(
public Map<ChannelOption<?>, Object> getOptions() {
return getOptions(
super.getOptions(),
ChannelOption.SO_RCVBUF, ChannelOption.SO_SNDBUF, ChannelOption.SCTP_INIT_MAXSTREAMS);
ChannelOption.SO_RCVBUF, ChannelOption.SO_SNDBUF, SctpChannelOption.SCTP_INIT_MAXSTREAMS);
}

@SuppressWarnings("unchecked")
Expand All @@ -74,7 +74,7 @@ public <T> boolean setOption(ChannelOption<T> option, T value) {
setReceiveBufferSize((Integer) value);
} else if (option == ChannelOption.SO_SNDBUF) {
setSendBufferSize((Integer) value);
} else if (option == ChannelOption.SCTP_INIT_MAXSTREAMS) {
} else if (option == SCTP_INIT_MAXSTREAMS) {
setInitMaxStreams((InitMaxStreams) value);
} else {
return super.setOption(option, value);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
* 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.channel.sctp;

import io.netty.channel.ChannelOption;

import java.net.SocketAddress;
import java.util.List;

/**
* Option for configuring the SCTP transport
*/
public class SctpChannelOption<T> extends ChannelOption<T> {
public static final ChannelOption<Boolean> SCTP_DISABLE_FRAGMENTS =
new ChannelOption<Boolean>("SCTP_DISABLE_FRAGMENTS");
public static final ChannelOption<Boolean> SCTP_EXPLICIT_COMPLETE =
new ChannelOption<Boolean>("SCTP_EXPLICIT_COMPLETE");
public static final ChannelOption<Integer> SCTP_FRAGMENT_INTERLEAVE =
new ChannelOption<Integer>("SCTP_FRAGMENT_INTERLEAVE");
public static final ChannelOption<List<Integer>> SCTP_INIT_MAXSTREAMS =
new ChannelOption<List<Integer>>("SCTP_INIT_MAXSTREAMS") {
@Override
public void validate(List<Integer> value) {
super.validate(value);
if (value.size() != 2) {
throw new IllegalArgumentException("value must be a List of 2 Integers: " + value);
}
if (value.get(0) == null) {
throw new NullPointerException("value[0]");
}
if (value.get(1) == null) {
throw new NullPointerException("value[1]");
}
}
};

public static final ChannelOption<Boolean> SCTP_NODELAY =
new ChannelOption<Boolean>("SCTP_NODELAY");
public static final ChannelOption<SocketAddress> SCTP_PRIMARY_ADDR =
new ChannelOption<SocketAddress>("SCTP_PRIMARY_ADDR");
public static final ChannelOption<SocketAddress> SCTP_SET_PEER_PRIMARY_ADDR =
new ChannelOption<SocketAddress>("SCTP_SET_PEER_PRIMARY_ADDR");

public SctpChannelOption(String name) {
super(name);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import java.io.IOException;
import java.util.Map;

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

/**
* The default {@link UdtChannelConfig} implementation.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,11 @@
* </tr>
* <tr>
* <td>{@code "protocolReceiveBuferSize"}</td>
* <td>{@link #setProtocolBufferSize(int)}</td>
* <td>{@link #setProtocolReceiveBufferSize(int)}</td>
* <tr>
* <tr>
* <td>{@code "systemReceiveBufferSize"}</td>
* <td>{@link #setSystemBufferSize(int)}</td>
* <td>{@link #setProtocolReceiveBufferSize(int)}</td>
* <tr>
* </table>
* <p>
Expand All @@ -68,30 +68,6 @@
*/
public interface UdtChannelConfig extends ChannelConfig {

/**
* See {@link OptionUDT#Protocol_Receive_Buffer_Size}.
*/
ChannelOption<Integer> PROTOCOL_RECEIVE_BUFFER_SIZE = new ChannelOption<Integer>(
"PROTOCOL_RECEIVE_BUFFER_SIZE");

/**
* See {@link OptionUDT#Protocol_Send_Buffer_Size}.
*/
ChannelOption<Integer> PROTOCOL_SEND_BUFFER_SIZE = new ChannelOption<Integer>(
"PROTOCOL_SEND_BUFFER_SIZE");

/**
* See {@link OptionUDT#System_Receive_Buffer_Size}.
*/
ChannelOption<Integer> SYSTEM_RECEIVE_BUFFER_SIZE = new ChannelOption<Integer>(
"SYSTEM_RECEIVE_BUFFER_SIZE");

/**
* See {@link OptionUDT#System_Send_Buffer_Size}.
*/
ChannelOption<Integer> SYSTEM_SEND_BUFFER_SIZE = new ChannelOption<Integer>(
"SYSTEM_SEND_BUFFER_SIZE");

/**
* Gets {@link KindUDT#ACCEPTOR} channel backlog.
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* 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.channel.udt;

import com.barchart.udt.OptionUDT;
import io.netty.channel.ChannelOption;

/**
* Options for the UDT transport
*/
public class UdtChannelOption<T> extends ChannelOption<T> {

/**
* See {@link OptionUDT#Protocol_Receive_Buffer_Size}.
*/
public static final ChannelOption<Integer> PROTOCOL_RECEIVE_BUFFER_SIZE = new ChannelOption<Integer>(
"PROTOCOL_RECEIVE_BUFFER_SIZE");

/**
* See {@link OptionUDT#Protocol_Send_Buffer_Size}.
*/
public static final ChannelOption<Integer> PROTOCOL_SEND_BUFFER_SIZE = new ChannelOption<Integer>(
"PROTOCOL_SEND_BUFFER_SIZE");

/**
* See {@link OptionUDT#System_Receive_Buffer_Size}.
*/
public static final ChannelOption<Integer> SYSTEM_RECEIVE_BUFFER_SIZE = new ChannelOption<Integer>(
"SYSTEM_RECEIVE_BUFFER_SIZE");

/**
* See {@link OptionUDT#System_Send_Buffer_Size}.
*/
public static final ChannelOption<Integer> SYSTEM_SEND_BUFFER_SIZE = new ChannelOption<Integer>(
"SYSTEM_SEND_BUFFER_SIZE");

public UdtChannelOption(String name) {
super(name);
}
}
31 changes: 0 additions & 31 deletions transport/src/main/java/io/netty/channel/ChannelOption.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@

import java.net.InetAddress;
import java.net.NetworkInterface;
import java.net.SocketAddress;
import java.util.List;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;

Expand Down Expand Up @@ -79,35 +77,6 @@ public class ChannelOption<T> extends UniqueName {
public static final ChannelOption<Boolean> TCP_NODELAY =
new ChannelOption<Boolean>("TCP_NODELAY");

public static final ChannelOption<Boolean> SCTP_DISABLE_FRAGMENTS =
new ChannelOption<Boolean>("SCTP_DISABLE_FRAGMENTS");
public static final ChannelOption<Boolean> SCTP_EXPLICIT_COMPLETE =
new ChannelOption<Boolean>("SCTP_EXPLICIT_COMPLETE");
public static final ChannelOption<Integer> SCTP_FRAGMENT_INTERLEAVE =
new ChannelOption<Integer>("SCTP_FRAGMENT_INTERLEAVE");
public static final ChannelOption<List<Integer>> SCTP_INIT_MAXSTREAMS =
new ChannelOption<List<Integer>>("SCTP_INIT_MAXSTREAMS") {
@Override
public void validate(List<Integer> value) {
super.validate(value);
if (value.size() != 2) {
throw new IllegalArgumentException("value must be a List of 2 Integers: " + value);
}
if (value.get(0) == null) {
throw new NullPointerException("value[0]");
}
if (value.get(1) == null) {
throw new NullPointerException("value[1]");
}
}
};
public static final ChannelOption<Boolean> SCTP_NODELAY =
new ChannelOption<Boolean>("SCTP_NODELAY");
public static final ChannelOption<SocketAddress> SCTP_PRIMARY_ADDR =
new ChannelOption<SocketAddress>("SCTP_PRIMARY_ADDR");
public static final ChannelOption<SocketAddress> SCTP_SET_PEER_PRIMARY_ADDR =
new ChannelOption<SocketAddress>("SCTP_SET_PEER_PRIMARY_ADDR");

public static final ChannelOption<Long> AIO_READ_TIMEOUT =
new ChannelOption<Long>("AIO_READ_TIMEOUT");
public static final ChannelOption<Long> AIO_WRITE_TIMEOUT =
Expand Down

0 comments on commit 895bce6

Please sign in to comment.