Rename classes as result of descussion on #594
This commit is contained in:
parent
d22480c0f4
commit
df72356d7d
|
@ -15,7 +15,7 @@
|
||||||
*/
|
*/
|
||||||
package io.netty.example.discard;
|
package io.netty.example.discard;
|
||||||
|
|
||||||
import io.netty.bootstrap.ClientBootstrap;
|
import io.netty.bootstrap.Bootstrap;
|
||||||
import io.netty.channel.ChannelFuture;
|
import io.netty.channel.ChannelFuture;
|
||||||
import io.netty.channel.socket.nio.NioEventLoopGroup;
|
import io.netty.channel.socket.nio.NioEventLoopGroup;
|
||||||
import io.netty.channel.socket.nio.NioSocketChannel;
|
import io.netty.channel.socket.nio.NioSocketChannel;
|
||||||
|
@ -36,7 +36,7 @@ public class DiscardClient {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void run() throws Exception {
|
public void run() throws Exception {
|
||||||
ClientBootstrap b = new ClientBootstrap();
|
Bootstrap b = new Bootstrap();
|
||||||
try {
|
try {
|
||||||
b.group(new NioEventLoopGroup())
|
b.group(new NioEventLoopGroup())
|
||||||
.channel(NioSocketChannel.class)
|
.channel(NioSocketChannel.class)
|
||||||
|
|
|
@ -15,7 +15,7 @@
|
||||||
*/
|
*/
|
||||||
package io.netty.example.echo;
|
package io.netty.example.echo;
|
||||||
|
|
||||||
import io.netty.bootstrap.ClientBootstrap;
|
import io.netty.bootstrap.Bootstrap;
|
||||||
import io.netty.channel.ChannelFuture;
|
import io.netty.channel.ChannelFuture;
|
||||||
import io.netty.channel.ChannelInitializer;
|
import io.netty.channel.ChannelInitializer;
|
||||||
import io.netty.channel.ChannelOption;
|
import io.netty.channel.ChannelOption;
|
||||||
|
@ -47,7 +47,7 @@ public class EchoClient {
|
||||||
|
|
||||||
public void run() throws Exception {
|
public void run() throws Exception {
|
||||||
// Configure the client.
|
// Configure the client.
|
||||||
ClientBootstrap b = new ClientBootstrap();
|
Bootstrap b = new Bootstrap();
|
||||||
try {
|
try {
|
||||||
b.group(new NioEventLoopGroup())
|
b.group(new NioEventLoopGroup())
|
||||||
.channel(NioSocketChannel.class)
|
.channel(NioSocketChannel.class)
|
||||||
|
|
|
@ -15,7 +15,7 @@
|
||||||
*/
|
*/
|
||||||
package io.netty.example.factorial;
|
package io.netty.example.factorial;
|
||||||
|
|
||||||
import io.netty.bootstrap.ClientBootstrap;
|
import io.netty.bootstrap.Bootstrap;
|
||||||
import io.netty.channel.ChannelFuture;
|
import io.netty.channel.ChannelFuture;
|
||||||
import io.netty.channel.socket.nio.NioEventLoopGroup;
|
import io.netty.channel.socket.nio.NioEventLoopGroup;
|
||||||
import io.netty.channel.socket.nio.NioSocketChannel;
|
import io.netty.channel.socket.nio.NioSocketChannel;
|
||||||
|
@ -37,7 +37,7 @@ public class FactorialClient {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void run() throws Exception {
|
public void run() throws Exception {
|
||||||
ClientBootstrap b = new ClientBootstrap();
|
Bootstrap b = new Bootstrap();
|
||||||
try {
|
try {
|
||||||
b.group(new NioEventLoopGroup())
|
b.group(new NioEventLoopGroup())
|
||||||
.channel(NioSocketChannel.class)
|
.channel(NioSocketChannel.class)
|
||||||
|
|
|
@ -15,7 +15,7 @@
|
||||||
*/
|
*/
|
||||||
package io.netty.example.http.snoop;
|
package io.netty.example.http.snoop;
|
||||||
|
|
||||||
import io.netty.bootstrap.ClientBootstrap;
|
import io.netty.bootstrap.Bootstrap;
|
||||||
import io.netty.channel.Channel;
|
import io.netty.channel.Channel;
|
||||||
import io.netty.channel.socket.nio.NioEventLoopGroup;
|
import io.netty.channel.socket.nio.NioEventLoopGroup;
|
||||||
import io.netty.channel.socket.nio.NioSocketChannel;
|
import io.netty.channel.socket.nio.NioSocketChannel;
|
||||||
|
@ -62,7 +62,7 @@ public class HttpSnoopClient {
|
||||||
boolean ssl = scheme.equalsIgnoreCase("https");
|
boolean ssl = scheme.equalsIgnoreCase("https");
|
||||||
|
|
||||||
// Configure the client.
|
// Configure the client.
|
||||||
ClientBootstrap b = new ClientBootstrap();
|
Bootstrap b = new Bootstrap();
|
||||||
try {
|
try {
|
||||||
b.group(new NioEventLoopGroup())
|
b.group(new NioEventLoopGroup())
|
||||||
.channel(NioSocketChannel.class)
|
.channel(NioSocketChannel.class)
|
||||||
|
|
|
@ -36,7 +36,7 @@
|
||||||
//THE SOFTWARE.
|
//THE SOFTWARE.
|
||||||
package io.netty.example.http.websocketx.client;
|
package io.netty.example.http.websocketx.client;
|
||||||
|
|
||||||
import io.netty.bootstrap.ClientBootstrap;
|
import io.netty.bootstrap.Bootstrap;
|
||||||
import io.netty.buffer.Unpooled;
|
import io.netty.buffer.Unpooled;
|
||||||
import io.netty.channel.Channel;
|
import io.netty.channel.Channel;
|
||||||
import io.netty.channel.ChannelInitializer;
|
import io.netty.channel.ChannelInitializer;
|
||||||
|
@ -65,7 +65,7 @@ public class WebSocketClient {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void run() throws Exception {
|
public void run() throws Exception {
|
||||||
ClientBootstrap b = new ClientBootstrap();
|
Bootstrap b = new Bootstrap();
|
||||||
try {
|
try {
|
||||||
|
|
||||||
String protocol = uri.getScheme();
|
String protocol = uri.getScheme();
|
||||||
|
|
|
@ -15,7 +15,7 @@
|
||||||
*/
|
*/
|
||||||
package io.netty.example.localecho;
|
package io.netty.example.localecho;
|
||||||
|
|
||||||
import io.netty.bootstrap.ClientBootstrap;
|
import io.netty.bootstrap.Bootstrap;
|
||||||
import io.netty.bootstrap.ServerBootstrap;
|
import io.netty.bootstrap.ServerBootstrap;
|
||||||
import io.netty.channel.Channel;
|
import io.netty.channel.Channel;
|
||||||
import io.netty.channel.ChannelFuture;
|
import io.netty.channel.ChannelFuture;
|
||||||
|
@ -43,7 +43,7 @@ public class LocalEcho {
|
||||||
// Address to bind on / connect to.
|
// Address to bind on / connect to.
|
||||||
final LocalAddress addr = new LocalAddress(port);
|
final LocalAddress addr = new LocalAddress(port);
|
||||||
|
|
||||||
ClientBootstrap cb = new ClientBootstrap();
|
Bootstrap cb = new Bootstrap();
|
||||||
ServerBootstrap sb = new ServerBootstrap();
|
ServerBootstrap sb = new ServerBootstrap();
|
||||||
try {
|
try {
|
||||||
// Note that we can use any event loop to ensure certain local channels
|
// Note that we can use any event loop to ensure certain local channels
|
||||||
|
|
|
@ -15,7 +15,7 @@
|
||||||
*/
|
*/
|
||||||
package io.netty.example.localtime;
|
package io.netty.example.localtime;
|
||||||
|
|
||||||
import io.netty.bootstrap.ClientBootstrap;
|
import io.netty.bootstrap.Bootstrap;
|
||||||
import io.netty.channel.Channel;
|
import io.netty.channel.Channel;
|
||||||
import io.netty.channel.socket.nio.NioEventLoopGroup;
|
import io.netty.channel.socket.nio.NioEventLoopGroup;
|
||||||
import io.netty.channel.socket.nio.NioSocketChannel;
|
import io.netty.channel.socket.nio.NioSocketChannel;
|
||||||
|
@ -43,7 +43,7 @@ public class LocalTimeClient {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void run() throws Exception {
|
public void run() throws Exception {
|
||||||
ClientBootstrap b = new ClientBootstrap();
|
Bootstrap b = new Bootstrap();
|
||||||
try {
|
try {
|
||||||
b.group(new NioEventLoopGroup())
|
b.group(new NioEventLoopGroup())
|
||||||
.channel(NioSocketChannel.class)
|
.channel(NioSocketChannel.class)
|
||||||
|
|
|
@ -15,7 +15,7 @@
|
||||||
*/
|
*/
|
||||||
package io.netty.example.objectecho;
|
package io.netty.example.objectecho;
|
||||||
|
|
||||||
import io.netty.bootstrap.ClientBootstrap;
|
import io.netty.bootstrap.Bootstrap;
|
||||||
import io.netty.channel.ChannelInitializer;
|
import io.netty.channel.ChannelInitializer;
|
||||||
import io.netty.channel.socket.SocketChannel;
|
import io.netty.channel.socket.SocketChannel;
|
||||||
import io.netty.channel.socket.nio.NioEventLoopGroup;
|
import io.netty.channel.socket.nio.NioEventLoopGroup;
|
||||||
|
@ -41,7 +41,7 @@ public class ObjectEchoClient {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void run() throws Exception {
|
public void run() throws Exception {
|
||||||
ClientBootstrap b = new ClientBootstrap();
|
Bootstrap b = new Bootstrap();
|
||||||
try {
|
try {
|
||||||
b.group(new NioEventLoopGroup())
|
b.group(new NioEventLoopGroup())
|
||||||
.channel(NioSocketChannel.class)
|
.channel(NioSocketChannel.class)
|
||||||
|
|
|
@ -15,7 +15,7 @@
|
||||||
*/
|
*/
|
||||||
package io.netty.example.proxy;
|
package io.netty.example.proxy;
|
||||||
|
|
||||||
import io.netty.bootstrap.ClientBootstrap;
|
import io.netty.bootstrap.Bootstrap;
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
import io.netty.channel.Channel;
|
import io.netty.channel.Channel;
|
||||||
import io.netty.channel.ChannelFuture;
|
import io.netty.channel.ChannelFuture;
|
||||||
|
@ -43,7 +43,7 @@ public class HexDumpProxyFrontendHandler extends ChannelInboundByteHandlerAdapte
|
||||||
final Channel inboundChannel = ctx.channel();
|
final Channel inboundChannel = ctx.channel();
|
||||||
|
|
||||||
// Start the connection attempt.
|
// Start the connection attempt.
|
||||||
ClientBootstrap b = new ClientBootstrap();
|
Bootstrap b = new Bootstrap();
|
||||||
b.group(inboundChannel.eventLoop())
|
b.group(inboundChannel.eventLoop())
|
||||||
.channel(NioSocketChannel.class)
|
.channel(NioSocketChannel.class)
|
||||||
.remoteAddress(remoteHost, remotePort)
|
.remoteAddress(remoteHost, remotePort)
|
||||||
|
|
|
@ -15,7 +15,7 @@
|
||||||
*/
|
*/
|
||||||
package io.netty.example.qotm;
|
package io.netty.example.qotm;
|
||||||
|
|
||||||
import io.netty.bootstrap.ClientBootstrap;
|
import io.netty.bootstrap.Bootstrap;
|
||||||
import io.netty.buffer.Unpooled;
|
import io.netty.buffer.Unpooled;
|
||||||
import io.netty.channel.Channel;
|
import io.netty.channel.Channel;
|
||||||
import io.netty.channel.ChannelOption;
|
import io.netty.channel.ChannelOption;
|
||||||
|
@ -41,7 +41,7 @@ public class QuoteOfTheMomentClient {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void run() throws Exception {
|
public void run() throws Exception {
|
||||||
ClientBootstrap b = new ClientBootstrap();
|
Bootstrap b = new Bootstrap();
|
||||||
try {
|
try {
|
||||||
b.group(new NioEventLoopGroup())
|
b.group(new NioEventLoopGroup())
|
||||||
.channel(NioDatagramChannel.class)
|
.channel(NioDatagramChannel.class)
|
||||||
|
|
|
@ -15,7 +15,7 @@
|
||||||
*/
|
*/
|
||||||
package io.netty.example.qotm;
|
package io.netty.example.qotm;
|
||||||
|
|
||||||
import io.netty.bootstrap.ClientBootstrap;
|
import io.netty.bootstrap.Bootstrap;
|
||||||
import io.netty.channel.ChannelOption;
|
import io.netty.channel.ChannelOption;
|
||||||
import io.netty.channel.socket.nio.NioDatagramChannel;
|
import io.netty.channel.socket.nio.NioDatagramChannel;
|
||||||
import io.netty.channel.socket.nio.NioEventLoopGroup;
|
import io.netty.channel.socket.nio.NioEventLoopGroup;
|
||||||
|
@ -37,7 +37,7 @@ public class QuoteOfTheMomentServer {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void run() throws Exception {
|
public void run() throws Exception {
|
||||||
ClientBootstrap b = new ClientBootstrap();
|
Bootstrap b = new Bootstrap();
|
||||||
try {
|
try {
|
||||||
b.group(new NioEventLoopGroup())
|
b.group(new NioEventLoopGroup())
|
||||||
.channel(NioDatagramChannel.class)
|
.channel(NioDatagramChannel.class)
|
||||||
|
|
|
@ -15,8 +15,8 @@
|
||||||
*/
|
*/
|
||||||
package io.netty.example.sctp;
|
package io.netty.example.sctp;
|
||||||
|
|
||||||
|
import io.netty.bootstrap.AbstractBootstrap;
|
||||||
import io.netty.bootstrap.Bootstrap;
|
import io.netty.bootstrap.Bootstrap;
|
||||||
import io.netty.bootstrap.ClientBootstrap;
|
|
||||||
import io.netty.channel.ChannelFuture;
|
import io.netty.channel.ChannelFuture;
|
||||||
import io.netty.channel.ChannelInitializer;
|
import io.netty.channel.ChannelInitializer;
|
||||||
import io.netty.channel.ChannelOption;
|
import io.netty.channel.ChannelOption;
|
||||||
|
@ -52,7 +52,7 @@ public class SctpEchoClient {
|
||||||
|
|
||||||
public void run() throws Exception {
|
public void run() throws Exception {
|
||||||
// Configure the client.
|
// Configure the client.
|
||||||
ClientBootstrap b = new ClientBootstrap();
|
Bootstrap b = new Bootstrap();
|
||||||
try {
|
try {
|
||||||
b.group(new NioEventLoopGroup())
|
b.group(new NioEventLoopGroup())
|
||||||
.channel(NioSctpChannel.class)
|
.channel(NioSctpChannel.class)
|
||||||
|
|
|
@ -15,7 +15,7 @@
|
||||||
*/
|
*/
|
||||||
package io.netty.example.securechat;
|
package io.netty.example.securechat;
|
||||||
|
|
||||||
import io.netty.bootstrap.ClientBootstrap;
|
import io.netty.bootstrap.Bootstrap;
|
||||||
import io.netty.channel.Channel;
|
import io.netty.channel.Channel;
|
||||||
import io.netty.channel.ChannelFuture;
|
import io.netty.channel.ChannelFuture;
|
||||||
import io.netty.channel.socket.nio.NioEventLoopGroup;
|
import io.netty.channel.socket.nio.NioEventLoopGroup;
|
||||||
|
@ -39,7 +39,7 @@ public class SecureChatClient {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void run() throws Exception {
|
public void run() throws Exception {
|
||||||
ClientBootstrap b = new ClientBootstrap();
|
Bootstrap b = new Bootstrap();
|
||||||
try {
|
try {
|
||||||
b.group(new NioEventLoopGroup())
|
b.group(new NioEventLoopGroup())
|
||||||
.channel(NioSocketChannel.class)
|
.channel(NioSocketChannel.class)
|
||||||
|
|
|
@ -15,7 +15,7 @@
|
||||||
*/
|
*/
|
||||||
package io.netty.example.telnet;
|
package io.netty.example.telnet;
|
||||||
|
|
||||||
import io.netty.bootstrap.ClientBootstrap;
|
import io.netty.bootstrap.Bootstrap;
|
||||||
import io.netty.channel.Channel;
|
import io.netty.channel.Channel;
|
||||||
import io.netty.channel.ChannelFuture;
|
import io.netty.channel.ChannelFuture;
|
||||||
import io.netty.channel.socket.nio.NioEventLoopGroup;
|
import io.netty.channel.socket.nio.NioEventLoopGroup;
|
||||||
|
@ -38,7 +38,7 @@ public class TelnetClient {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void run() throws Exception {
|
public void run() throws Exception {
|
||||||
ClientBootstrap b = new ClientBootstrap();
|
Bootstrap b = new Bootstrap();
|
||||||
try {
|
try {
|
||||||
b.group(new NioEventLoopGroup())
|
b.group(new NioEventLoopGroup())
|
||||||
.channel(NioSocketChannel.class)
|
.channel(NioSocketChannel.class)
|
||||||
|
|
|
@ -15,7 +15,7 @@
|
||||||
*/
|
*/
|
||||||
package io.netty.example.uptime;
|
package io.netty.example.uptime;
|
||||||
|
|
||||||
import io.netty.bootstrap.ClientBootstrap;
|
import io.netty.bootstrap.Bootstrap;
|
||||||
import io.netty.channel.ChannelInitializer;
|
import io.netty.channel.ChannelInitializer;
|
||||||
import io.netty.channel.EventLoopGroup;
|
import io.netty.channel.EventLoopGroup;
|
||||||
import io.netty.channel.socket.SocketChannel;
|
import io.netty.channel.socket.SocketChannel;
|
||||||
|
@ -50,14 +50,14 @@ public class UptimeClient {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void run() {
|
public void run() {
|
||||||
configureBootstrap(new ClientBootstrap()).connect();
|
configureBootstrap(new Bootstrap()).connect();
|
||||||
}
|
}
|
||||||
|
|
||||||
private ClientBootstrap configureBootstrap(ClientBootstrap b) {
|
private Bootstrap configureBootstrap(Bootstrap b) {
|
||||||
return configureBootstrap(b, new NioEventLoopGroup());
|
return configureBootstrap(b, new NioEventLoopGroup());
|
||||||
}
|
}
|
||||||
|
|
||||||
ClientBootstrap configureBootstrap(ClientBootstrap b, EventLoopGroup g) {
|
Bootstrap configureBootstrap(Bootstrap b, EventLoopGroup g) {
|
||||||
b.group(g)
|
b.group(g)
|
||||||
.channel(NioSocketChannel.class)
|
.channel(NioSocketChannel.class)
|
||||||
.remoteAddress(host, port)
|
.remoteAddress(host, port)
|
||||||
|
|
|
@ -15,7 +15,7 @@
|
||||||
*/
|
*/
|
||||||
package io.netty.example.uptime;
|
package io.netty.example.uptime;
|
||||||
|
|
||||||
import io.netty.bootstrap.ClientBootstrap;
|
import io.netty.bootstrap.Bootstrap;
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
import io.netty.channel.ChannelHandler.Sharable;
|
import io.netty.channel.ChannelHandler.Sharable;
|
||||||
import io.netty.channel.ChannelHandlerContext;
|
import io.netty.channel.ChannelHandlerContext;
|
||||||
|
@ -84,7 +84,7 @@ public class UptimeClientHandler extends ChannelInboundByteHandlerAdapter {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
println("Reconnecting to: " + ctx.channel().remoteAddress());
|
println("Reconnecting to: " + ctx.channel().remoteAddress());
|
||||||
client.configureBootstrap(new ClientBootstrap(), loop).connect();
|
client.configureBootstrap(new Bootstrap(), loop).connect();
|
||||||
}
|
}
|
||||||
}, UptimeClient.RECONNECT_DELAY, TimeUnit.SECONDS);
|
}, UptimeClient.RECONNECT_DELAY, TimeUnit.SECONDS);
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,7 +15,7 @@
|
||||||
*/
|
*/
|
||||||
package io.netty.testsuite.transport.socket;
|
package io.netty.testsuite.transport.socket;
|
||||||
|
|
||||||
import io.netty.bootstrap.ClientBootstrap;
|
import io.netty.bootstrap.Bootstrap;
|
||||||
import io.netty.logging.InternalLogger;
|
import io.netty.logging.InternalLogger;
|
||||||
import io.netty.logging.InternalLoggerFactory;
|
import io.netty.logging.InternalLoggerFactory;
|
||||||
import io.netty.testsuite.transport.socket.SocketTestPermutation.Factory;
|
import io.netty.testsuite.transport.socket.SocketTestPermutation.Factory;
|
||||||
|
@ -32,19 +32,19 @@ import org.junit.rules.TestName;
|
||||||
|
|
||||||
public abstract class AbstractClientSocketTest {
|
public abstract class AbstractClientSocketTest {
|
||||||
|
|
||||||
private static final List<Factory<ClientBootstrap>> COMBO = SocketTestPermutation.clientSocket();
|
private static final List<Factory<Bootstrap>> COMBO = SocketTestPermutation.clientSocket();
|
||||||
|
|
||||||
@Rule
|
@Rule
|
||||||
public final TestName testName = new TestName();
|
public final TestName testName = new TestName();
|
||||||
|
|
||||||
protected final InternalLogger logger = InternalLoggerFactory.getInstance(getClass());
|
protected final InternalLogger logger = InternalLoggerFactory.getInstance(getClass());
|
||||||
|
|
||||||
protected volatile ClientBootstrap cb;
|
protected volatile Bootstrap cb;
|
||||||
protected volatile InetSocketAddress addr;
|
protected volatile InetSocketAddress addr;
|
||||||
|
|
||||||
protected void run() throws Throwable {
|
protected void run() throws Throwable {
|
||||||
int i = 0;
|
int i = 0;
|
||||||
for (Factory<ClientBootstrap> e: COMBO) {
|
for (Factory<Bootstrap> e: COMBO) {
|
||||||
cb = e.newInstance();
|
cb = e.newInstance();
|
||||||
addr = new InetSocketAddress(
|
addr = new InetSocketAddress(
|
||||||
NetworkConstants.LOCALHOST, TestUtils.getFreePort());
|
NetworkConstants.LOCALHOST, TestUtils.getFreePort());
|
||||||
|
@ -54,7 +54,7 @@ public abstract class AbstractClientSocketTest {
|
||||||
"Running: %s %d of %d", testName.getMethodName(), ++ i, COMBO.size()));
|
"Running: %s %d of %d", testName.getMethodName(), ++ i, COMBO.size()));
|
||||||
try {
|
try {
|
||||||
Method m = getClass().getDeclaredMethod(
|
Method m = getClass().getDeclaredMethod(
|
||||||
testName.getMethodName(), ClientBootstrap.class);
|
testName.getMethodName(), Bootstrap.class);
|
||||||
m.invoke(this, cb);
|
m.invoke(this, cb);
|
||||||
} catch (InvocationTargetException ex) {
|
} catch (InvocationTargetException ex) {
|
||||||
throw ex.getCause();
|
throw ex.getCause();
|
||||||
|
|
|
@ -15,8 +15,8 @@
|
||||||
*/
|
*/
|
||||||
package io.netty.testsuite.transport.socket;
|
package io.netty.testsuite.transport.socket;
|
||||||
|
|
||||||
|
import io.netty.bootstrap.AbstractBootstrap;
|
||||||
import io.netty.bootstrap.Bootstrap;
|
import io.netty.bootstrap.Bootstrap;
|
||||||
import io.netty.bootstrap.ClientBootstrap;
|
|
||||||
import io.netty.logging.InternalLogger;
|
import io.netty.logging.InternalLogger;
|
||||||
import io.netty.logging.InternalLoggerFactory;
|
import io.netty.logging.InternalLoggerFactory;
|
||||||
import io.netty.testsuite.transport.socket.SocketTestPermutation.Factory;
|
import io.netty.testsuite.transport.socket.SocketTestPermutation.Factory;
|
||||||
|
@ -34,7 +34,7 @@ import org.junit.rules.TestName;
|
||||||
|
|
||||||
public abstract class AbstractDatagramTest {
|
public abstract class AbstractDatagramTest {
|
||||||
|
|
||||||
private static final List<Entry<Factory<ClientBootstrap>, Factory<ClientBootstrap>>> COMBO =
|
private static final List<Entry<Factory<Bootstrap>, Factory<Bootstrap>>> COMBO =
|
||||||
SocketTestPermutation.datagram();
|
SocketTestPermutation.datagram();
|
||||||
|
|
||||||
@Rule
|
@Rule
|
||||||
|
@ -42,13 +42,13 @@ public abstract class AbstractDatagramTest {
|
||||||
|
|
||||||
protected final InternalLogger logger = InternalLoggerFactory.getInstance(getClass());
|
protected final InternalLogger logger = InternalLoggerFactory.getInstance(getClass());
|
||||||
|
|
||||||
protected volatile ClientBootstrap sb;
|
protected volatile Bootstrap sb;
|
||||||
protected volatile ClientBootstrap cb;
|
protected volatile Bootstrap cb;
|
||||||
protected volatile InetSocketAddress addr;
|
protected volatile InetSocketAddress addr;
|
||||||
|
|
||||||
protected void run() throws Throwable {
|
protected void run() throws Throwable {
|
||||||
int i = 0;
|
int i = 0;
|
||||||
for (Entry<Factory<ClientBootstrap>, Factory<ClientBootstrap>> e: COMBO) {
|
for (Entry<Factory<Bootstrap>, Factory<Bootstrap>> e: COMBO) {
|
||||||
sb = e.getKey().newInstance();
|
sb = e.getKey().newInstance();
|
||||||
cb = e.getValue().newInstance();
|
cb = e.getValue().newInstance();
|
||||||
addr = new InetSocketAddress(
|
addr = new InetSocketAddress(
|
||||||
|
@ -60,7 +60,7 @@ public abstract class AbstractDatagramTest {
|
||||||
"Running: %s %d of %d", testName.getMethodName(), ++ i, COMBO.size()));
|
"Running: %s %d of %d", testName.getMethodName(), ++ i, COMBO.size()));
|
||||||
try {
|
try {
|
||||||
Method m = getClass().getDeclaredMethod(
|
Method m = getClass().getDeclaredMethod(
|
||||||
testName.getMethodName(), Bootstrap.class, Bootstrap.class);
|
testName.getMethodName(), AbstractBootstrap.class, AbstractBootstrap.class);
|
||||||
m.invoke(this, sb, cb);
|
m.invoke(this, sb, cb);
|
||||||
} catch (InvocationTargetException ex) {
|
} catch (InvocationTargetException ex) {
|
||||||
throw ex.getCause();
|
throw ex.getCause();
|
||||||
|
|
|
@ -15,7 +15,7 @@
|
||||||
*/
|
*/
|
||||||
package io.netty.testsuite.transport.socket;
|
package io.netty.testsuite.transport.socket;
|
||||||
|
|
||||||
import io.netty.bootstrap.ClientBootstrap;
|
import io.netty.bootstrap.Bootstrap;
|
||||||
import io.netty.bootstrap.ServerBootstrap;
|
import io.netty.bootstrap.ServerBootstrap;
|
||||||
import io.netty.logging.InternalLogger;
|
import io.netty.logging.InternalLogger;
|
||||||
import io.netty.logging.InternalLoggerFactory;
|
import io.netty.logging.InternalLoggerFactory;
|
||||||
|
@ -34,7 +34,7 @@ import org.junit.rules.TestName;
|
||||||
|
|
||||||
public abstract class AbstractSocketTest {
|
public abstract class AbstractSocketTest {
|
||||||
|
|
||||||
private static final List<Entry<Factory<ServerBootstrap>, Factory<ClientBootstrap>>> COMBO =
|
private static final List<Entry<Factory<ServerBootstrap>, Factory<Bootstrap>>> COMBO =
|
||||||
SocketTestPermutation.socket();
|
SocketTestPermutation.socket();
|
||||||
|
|
||||||
@Rule
|
@Rule
|
||||||
|
@ -43,13 +43,13 @@ public abstract class AbstractSocketTest {
|
||||||
protected final InternalLogger logger = InternalLoggerFactory.getInstance(getClass());
|
protected final InternalLogger logger = InternalLoggerFactory.getInstance(getClass());
|
||||||
|
|
||||||
protected volatile ServerBootstrap sb;
|
protected volatile ServerBootstrap sb;
|
||||||
protected volatile ClientBootstrap cb;
|
protected volatile Bootstrap cb;
|
||||||
protected volatile InetSocketAddress addr;
|
protected volatile InetSocketAddress addr;
|
||||||
protected volatile Factory<ClientBootstrap> currentBootstrap;
|
protected volatile Factory<Bootstrap> currentBootstrap;
|
||||||
|
|
||||||
protected void run() throws Throwable {
|
protected void run() throws Throwable {
|
||||||
int i = 0;
|
int i = 0;
|
||||||
for (Entry<Factory<ServerBootstrap>, Factory<ClientBootstrap>> e: COMBO) {
|
for (Entry<Factory<ServerBootstrap>, Factory<Bootstrap>> e: COMBO) {
|
||||||
currentBootstrap = e.getValue();
|
currentBootstrap = e.getValue();
|
||||||
sb = e.getKey().newInstance();
|
sb = e.getKey().newInstance();
|
||||||
cb = e.getValue().newInstance();
|
cb = e.getValue().newInstance();
|
||||||
|
@ -62,7 +62,7 @@ public abstract class AbstractSocketTest {
|
||||||
"Running: %s %d of %d", testName.getMethodName(), ++ i, COMBO.size()));
|
"Running: %s %d of %d", testName.getMethodName(), ++ i, COMBO.size()));
|
||||||
try {
|
try {
|
||||||
Method m = getClass().getDeclaredMethod(
|
Method m = getClass().getDeclaredMethod(
|
||||||
testName.getMethodName(), ServerBootstrap.class, ClientBootstrap.class);
|
testName.getMethodName(), ServerBootstrap.class, Bootstrap.class);
|
||||||
m.invoke(this, sb, cb);
|
m.invoke(this, sb, cb);
|
||||||
} catch (InvocationTargetException ex) {
|
} catch (InvocationTargetException ex) {
|
||||||
throw ex.getCause();
|
throw ex.getCause();
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
package io.netty.testsuite.transport.socket;
|
package io.netty.testsuite.transport.socket;
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
import io.netty.bootstrap.Bootstrap;
|
import io.netty.bootstrap.AbstractBootstrap;
|
||||||
import io.netty.buffer.Unpooled;
|
import io.netty.buffer.Unpooled;
|
||||||
import io.netty.channel.Channel;
|
import io.netty.channel.Channel;
|
||||||
import io.netty.channel.ChannelHandlerContext;
|
import io.netty.channel.ChannelHandlerContext;
|
||||||
|
@ -40,7 +40,7 @@ public class DatagramMulticastTest extends AbstractDatagramTest {
|
||||||
run();
|
run();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testMulticast(Bootstrap sb, Bootstrap cb) throws Throwable {
|
public void testMulticast(AbstractBootstrap sb, AbstractBootstrap cb) throws Throwable {
|
||||||
MulticastTestHandler mhandler = new MulticastTestHandler();
|
MulticastTestHandler mhandler = new MulticastTestHandler();
|
||||||
|
|
||||||
sb.handler(new ChannelInboundMessageHandlerAdapter<DatagramPacket>() {
|
sb.handler(new ChannelInboundMessageHandlerAdapter<DatagramPacket>() {
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
package io.netty.testsuite.transport.socket;
|
package io.netty.testsuite.transport.socket;
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
import io.netty.bootstrap.Bootstrap;
|
import io.netty.bootstrap.AbstractBootstrap;
|
||||||
import io.netty.buffer.Unpooled;
|
import io.netty.buffer.Unpooled;
|
||||||
import io.netty.channel.Channel;
|
import io.netty.channel.Channel;
|
||||||
import io.netty.channel.ChannelHandlerContext;
|
import io.netty.channel.ChannelHandlerContext;
|
||||||
|
@ -36,7 +36,7 @@ public class DatagramUnicastTest extends AbstractDatagramTest {
|
||||||
run();
|
run();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testSimpleSend(Bootstrap sb, Bootstrap cb) throws Throwable {
|
public void testSimpleSend(AbstractBootstrap sb, AbstractBootstrap cb) throws Throwable {
|
||||||
final CountDownLatch latch = new CountDownLatch(1);
|
final CountDownLatch latch = new CountDownLatch(1);
|
||||||
|
|
||||||
sb.handler(new ChannelInboundMessageHandlerAdapter<DatagramPacket>() {
|
sb.handler(new ChannelInboundMessageHandlerAdapter<DatagramPacket>() {
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
package io.netty.testsuite.transport.socket;
|
package io.netty.testsuite.transport.socket;
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
import io.netty.bootstrap.ClientBootstrap;
|
import io.netty.bootstrap.Bootstrap;
|
||||||
import io.netty.bootstrap.ServerBootstrap;
|
import io.netty.bootstrap.ServerBootstrap;
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
import io.netty.buffer.Unpooled;
|
import io.netty.buffer.Unpooled;
|
||||||
|
@ -44,7 +44,7 @@ public class SocketEchoTest extends AbstractSocketTest {
|
||||||
run();
|
run();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testSimpleEcho(ServerBootstrap sb, ClientBootstrap cb) throws Throwable {
|
public void testSimpleEcho(ServerBootstrap sb, Bootstrap cb) throws Throwable {
|
||||||
testSimpleEcho0(sb, cb, Integer.MAX_VALUE);
|
testSimpleEcho0(sb, cb, Integer.MAX_VALUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -53,11 +53,11 @@ public class SocketEchoTest extends AbstractSocketTest {
|
||||||
run();
|
run();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testSimpleEchoWithBoundedBuffer(ServerBootstrap sb, ClientBootstrap cb) throws Throwable {
|
public void testSimpleEchoWithBoundedBuffer(ServerBootstrap sb, Bootstrap cb) throws Throwable {
|
||||||
testSimpleEcho0(sb, cb, 32);
|
testSimpleEcho0(sb, cb, 32);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void testSimpleEcho0(ServerBootstrap sb, ClientBootstrap cb, int maxInboundBufferSize) throws Throwable {
|
private static void testSimpleEcho0(ServerBootstrap sb, Bootstrap cb, int maxInboundBufferSize) throws Throwable {
|
||||||
EchoHandler sh = new EchoHandler(maxInboundBufferSize);
|
EchoHandler sh = new EchoHandler(maxInboundBufferSize);
|
||||||
EchoHandler ch = new EchoHandler(maxInboundBufferSize);
|
EchoHandler ch = new EchoHandler(maxInboundBufferSize);
|
||||||
|
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
package io.netty.testsuite.transport.socket;
|
package io.netty.testsuite.transport.socket;
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
import io.netty.bootstrap.ClientBootstrap;
|
import io.netty.bootstrap.Bootstrap;
|
||||||
import io.netty.bootstrap.ServerBootstrap;
|
import io.netty.bootstrap.ServerBootstrap;
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
import io.netty.buffer.Unpooled;
|
import io.netty.buffer.Unpooled;
|
||||||
|
@ -47,7 +47,7 @@ public class SocketFixedLengthEchoTest extends AbstractSocketTest {
|
||||||
run();
|
run();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testFixedLengthEcho(ServerBootstrap sb, ClientBootstrap cb) throws Throwable {
|
public void testFixedLengthEcho(ServerBootstrap sb, Bootstrap cb) throws Throwable {
|
||||||
final EchoHandler sh = new EchoHandler();
|
final EchoHandler sh = new EchoHandler();
|
||||||
final EchoHandler ch = new EchoHandler();
|
final EchoHandler ch = new EchoHandler();
|
||||||
|
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
package io.netty.testsuite.transport.socket;
|
package io.netty.testsuite.transport.socket;
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
import io.netty.bootstrap.ClientBootstrap;
|
import io.netty.bootstrap.Bootstrap;
|
||||||
import io.netty.bootstrap.ServerBootstrap;
|
import io.netty.bootstrap.ServerBootstrap;
|
||||||
import io.netty.channel.Channel;
|
import io.netty.channel.Channel;
|
||||||
import io.netty.channel.ChannelHandlerContext;
|
import io.netty.channel.ChannelHandlerContext;
|
||||||
|
@ -55,7 +55,7 @@ public class SocketObjectEchoTest extends AbstractSocketTest {
|
||||||
run();
|
run();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testObjectEcho(ServerBootstrap sb, ClientBootstrap cb) throws Throwable {
|
public void testObjectEcho(ServerBootstrap sb, Bootstrap cb) throws Throwable {
|
||||||
final EchoHandler sh = new EchoHandler();
|
final EchoHandler sh = new EchoHandler();
|
||||||
final EchoHandler ch = new EchoHandler();
|
final EchoHandler ch = new EchoHandler();
|
||||||
|
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
package io.netty.testsuite.transport.socket;
|
package io.netty.testsuite.transport.socket;
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
import io.netty.bootstrap.ClientBootstrap;
|
import io.netty.bootstrap.Bootstrap;
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
import io.netty.buffer.Unpooled;
|
import io.netty.buffer.Unpooled;
|
||||||
import io.netty.channel.ChannelHandlerContext;
|
import io.netty.channel.ChannelHandlerContext;
|
||||||
|
@ -37,7 +37,7 @@ public class SocketShutdownOutputBySelfTest extends AbstractClientSocketTest {
|
||||||
run();
|
run();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testShutdownOutput(ClientBootstrap cb) throws Throwable {
|
public void testShutdownOutput(Bootstrap cb) throws Throwable {
|
||||||
TestHandler h = new TestHandler();
|
TestHandler h = new TestHandler();
|
||||||
ServerSocket ss = new ServerSocket();
|
ServerSocket ss = new ServerSocket();
|
||||||
Socket s = null;
|
Socket s = null;
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
package io.netty.testsuite.transport.socket;
|
package io.netty.testsuite.transport.socket;
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
import io.netty.bootstrap.ClientBootstrap;
|
import io.netty.bootstrap.Bootstrap;
|
||||||
import io.netty.bootstrap.ServerBootstrap;
|
import io.netty.bootstrap.ServerBootstrap;
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
import io.netty.buffer.Unpooled;
|
import io.netty.buffer.Unpooled;
|
||||||
|
@ -175,7 +175,7 @@ public class SocketSpdyEchoTest extends AbstractSocketTest {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testSpdyEcho(ServerBootstrap sb, ClientBootstrap cb) throws Throwable {
|
public void testSpdyEcho(ServerBootstrap sb, Bootstrap cb) throws Throwable {
|
||||||
|
|
||||||
ByteBuf frames = createFrames(version);
|
ByteBuf frames = createFrames(version);
|
||||||
|
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
package io.netty.testsuite.transport.socket;
|
package io.netty.testsuite.transport.socket;
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
import io.netty.bootstrap.ClientBootstrap;
|
import io.netty.bootstrap.Bootstrap;
|
||||||
import io.netty.bootstrap.ServerBootstrap;
|
import io.netty.bootstrap.ServerBootstrap;
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
import io.netty.buffer.Unpooled;
|
import io.netty.buffer.Unpooled;
|
||||||
|
@ -67,7 +67,7 @@ public class SocketSslEchoTest extends AbstractSocketTest {
|
||||||
run();
|
run();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testSslEcho(ServerBootstrap sb, ClientBootstrap cb) throws Throwable {
|
public void testSslEcho(ServerBootstrap sb, Bootstrap cb) throws Throwable {
|
||||||
final EchoHandler sh = new EchoHandler(true);
|
final EchoHandler sh = new EchoHandler(true);
|
||||||
final EchoHandler ch = new EchoHandler(false);
|
final EchoHandler ch = new EchoHandler(false);
|
||||||
|
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
package io.netty.testsuite.transport.socket;
|
package io.netty.testsuite.transport.socket;
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
import io.netty.bootstrap.ClientBootstrap;
|
import io.netty.bootstrap.Bootstrap;
|
||||||
import io.netty.bootstrap.ServerBootstrap;
|
import io.netty.bootstrap.ServerBootstrap;
|
||||||
import io.netty.channel.Channel;
|
import io.netty.channel.Channel;
|
||||||
import io.netty.channel.ChannelHandlerContext;
|
import io.netty.channel.ChannelHandlerContext;
|
||||||
|
@ -57,7 +57,7 @@ public class SocketStringEchoTest extends AbstractSocketTest {
|
||||||
run();
|
run();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testStringEcho(ServerBootstrap sb, ClientBootstrap cb) throws Throwable {
|
public void testStringEcho(ServerBootstrap sb, Bootstrap cb) throws Throwable {
|
||||||
final StringEchoHandler sh = new StringEchoHandler();
|
final StringEchoHandler sh = new StringEchoHandler();
|
||||||
final StringEchoHandler ch = new StringEchoHandler();
|
final StringEchoHandler ch = new StringEchoHandler();
|
||||||
|
|
||||||
|
|
|
@ -15,8 +15,8 @@
|
||||||
*/
|
*/
|
||||||
package io.netty.testsuite.transport.socket;
|
package io.netty.testsuite.transport.socket;
|
||||||
|
|
||||||
import io.netty.bootstrap.Bootstrap.ChannelFactory;
|
import io.netty.bootstrap.AbstractBootstrap.ChannelFactory;
|
||||||
import io.netty.bootstrap.ClientBootstrap;
|
import io.netty.bootstrap.Bootstrap;
|
||||||
import io.netty.bootstrap.ServerBootstrap;
|
import io.netty.bootstrap.ServerBootstrap;
|
||||||
import io.netty.channel.Channel;
|
import io.netty.channel.Channel;
|
||||||
import io.netty.channel.socket.InternetProtocolFamily;
|
import io.netty.channel.socket.InternetProtocolFamily;
|
||||||
|
@ -38,34 +38,34 @@ import java.util.Map.Entry;
|
||||||
|
|
||||||
final class SocketTestPermutation {
|
final class SocketTestPermutation {
|
||||||
|
|
||||||
static List<Entry<Factory<ServerBootstrap>, Factory<ClientBootstrap>>> socket() {
|
static List<Entry<Factory<ServerBootstrap>, Factory<Bootstrap>>> socket() {
|
||||||
List<Entry<Factory<ServerBootstrap>, Factory<ClientBootstrap>>> list =
|
List<Entry<Factory<ServerBootstrap>, Factory<Bootstrap>>> list =
|
||||||
new ArrayList<Entry<Factory<ServerBootstrap>, Factory<ClientBootstrap>>>();
|
new ArrayList<Entry<Factory<ServerBootstrap>, Factory<Bootstrap>>>();
|
||||||
|
|
||||||
// Make the list of ServerBootstrap factories.
|
// Make the list of ServerBootstrap factories.
|
||||||
List<Factory<ServerBootstrap>> sbfs = serverSocket();
|
List<Factory<ServerBootstrap>> sbfs = serverSocket();
|
||||||
|
|
||||||
// Make the list of Bootstrap factories.
|
// Make the list of Bootstrap factories.
|
||||||
List<Factory<ClientBootstrap>> cbfs = clientSocket();
|
List<Factory<Bootstrap>> cbfs = clientSocket();
|
||||||
|
|
||||||
// Populate the combinations
|
// Populate the combinations
|
||||||
for (Factory<ServerBootstrap> sbf: sbfs) {
|
for (Factory<ServerBootstrap> sbf: sbfs) {
|
||||||
for (Factory<ClientBootstrap> cbf: cbfs) {
|
for (Factory<Bootstrap> cbf: cbfs) {
|
||||||
final Factory<ServerBootstrap> sbf0 = sbf;
|
final Factory<ServerBootstrap> sbf0 = sbf;
|
||||||
final Factory<ClientBootstrap> cbf0 = cbf;
|
final Factory<Bootstrap> cbf0 = cbf;
|
||||||
list.add(new Entry<Factory<ServerBootstrap>, Factory<ClientBootstrap>>() {
|
list.add(new Entry<Factory<ServerBootstrap>, Factory<Bootstrap>>() {
|
||||||
@Override
|
@Override
|
||||||
public Factory<ServerBootstrap> getKey() {
|
public Factory<ServerBootstrap> getKey() {
|
||||||
return sbf0;
|
return sbf0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Factory<ClientBootstrap> getValue() {
|
public Factory<Bootstrap> getValue() {
|
||||||
return cbf0;
|
return cbf0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Factory<ClientBootstrap> setValue(Factory<ClientBootstrap> value) {
|
public Factory<Bootstrap> setValue(Factory<Bootstrap> value) {
|
||||||
throw new UnsupportedOperationException();
|
throw new UnsupportedOperationException();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -78,17 +78,17 @@ final class SocketTestPermutation {
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
static List<Entry<Factory<ClientBootstrap>, Factory<ClientBootstrap>>> datagram() {
|
static List<Entry<Factory<Bootstrap>, Factory<Bootstrap>>> datagram() {
|
||||||
List<Entry<Factory<ClientBootstrap>, Factory<ClientBootstrap>>> list =
|
List<Entry<Factory<Bootstrap>, Factory<Bootstrap>>> list =
|
||||||
new ArrayList<Entry<Factory<ClientBootstrap>, Factory<ClientBootstrap>>>();
|
new ArrayList<Entry<Factory<Bootstrap>, Factory<Bootstrap>>>();
|
||||||
|
|
||||||
// Make the list of Bootstrap factories.
|
// Make the list of Bootstrap factories.
|
||||||
List<Factory<ClientBootstrap>> bfs =
|
List<Factory<Bootstrap>> bfs =
|
||||||
new ArrayList<Factory<ClientBootstrap>>();
|
new ArrayList<Factory<Bootstrap>>();
|
||||||
bfs.add(new Factory<ClientBootstrap>() {
|
bfs.add(new Factory<Bootstrap>() {
|
||||||
@Override
|
@Override
|
||||||
public ClientBootstrap newInstance() {
|
public Bootstrap newInstance() {
|
||||||
return new ClientBootstrap().group(new NioEventLoopGroup()).channelFactory(new ChannelFactory() {
|
return new Bootstrap().group(new NioEventLoopGroup()).channelFactory(new ChannelFactory() {
|
||||||
@Override
|
@Override
|
||||||
public Channel newChannel() {
|
public Channel newChannel() {
|
||||||
return new NioDatagramChannel(InternetProtocolFamily.IPv4);
|
return new NioDatagramChannel(InternetProtocolFamily.IPv4);
|
||||||
|
@ -96,31 +96,31 @@ final class SocketTestPermutation {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
bfs.add(new Factory<ClientBootstrap>() {
|
bfs.add(new Factory<Bootstrap>() {
|
||||||
@Override
|
@Override
|
||||||
public ClientBootstrap newInstance() {
|
public Bootstrap newInstance() {
|
||||||
return new ClientBootstrap().group(new OioEventLoopGroup()).channel(OioDatagramChannel.class);
|
return new Bootstrap().group(new OioEventLoopGroup()).channel(OioDatagramChannel.class);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Populate the combinations
|
// Populate the combinations
|
||||||
for (Factory<ClientBootstrap> sbf: bfs) {
|
for (Factory<Bootstrap> sbf: bfs) {
|
||||||
for (Factory<ClientBootstrap> cbf: bfs) {
|
for (Factory<Bootstrap> cbf: bfs) {
|
||||||
final Factory<ClientBootstrap> sbf0 = sbf;
|
final Factory<Bootstrap> sbf0 = sbf;
|
||||||
final Factory<ClientBootstrap> cbf0 = cbf;
|
final Factory<Bootstrap> cbf0 = cbf;
|
||||||
list.add(new Entry<Factory<ClientBootstrap>, Factory<ClientBootstrap>>() {
|
list.add(new Entry<Factory<Bootstrap>, Factory<Bootstrap>>() {
|
||||||
@Override
|
@Override
|
||||||
public Factory<ClientBootstrap> getKey() {
|
public Factory<Bootstrap> getKey() {
|
||||||
return sbf0;
|
return sbf0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Factory<ClientBootstrap> getValue() {
|
public Factory<Bootstrap> getValue() {
|
||||||
return cbf0;
|
return cbf0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Factory<ClientBootstrap> setValue(Factory<ClientBootstrap> value) {
|
public Factory<Bootstrap> setValue(Factory<Bootstrap> value) {
|
||||||
throw new UnsupportedOperationException();
|
throw new UnsupportedOperationException();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -168,19 +168,19 @@ final class SocketTestPermutation {
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
static List<Factory<ClientBootstrap>> clientSocket() {
|
static List<Factory<Bootstrap>> clientSocket() {
|
||||||
List<Factory<ClientBootstrap>> list = new ArrayList<Factory<ClientBootstrap>>();
|
List<Factory<Bootstrap>> list = new ArrayList<Factory<Bootstrap>>();
|
||||||
list.add(new Factory<ClientBootstrap>() {
|
list.add(new Factory<Bootstrap>() {
|
||||||
@Override
|
@Override
|
||||||
public ClientBootstrap newInstance() {
|
public Bootstrap newInstance() {
|
||||||
return new ClientBootstrap().group(new NioEventLoopGroup()).channel(NioSocketChannel.class);
|
return new Bootstrap().group(new NioEventLoopGroup()).channel(NioSocketChannel.class);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
list.add(new Factory<ClientBootstrap>() {
|
list.add(new Factory<Bootstrap>() {
|
||||||
@Override
|
@Override
|
||||||
public ClientBootstrap newInstance() {
|
public Bootstrap newInstance() {
|
||||||
final AioEventLoopGroup loop = new AioEventLoopGroup();
|
final AioEventLoopGroup loop = new AioEventLoopGroup();
|
||||||
return new ClientBootstrap().group(loop).channelFactory(new ChannelFactory() {
|
return new Bootstrap().group(loop).channelFactory(new ChannelFactory() {
|
||||||
@Override
|
@Override
|
||||||
public Channel newChannel() {
|
public Channel newChannel() {
|
||||||
return new AioSocketChannel(loop);
|
return new AioSocketChannel(loop);
|
||||||
|
@ -188,10 +188,10 @@ final class SocketTestPermutation {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
list.add(new Factory<ClientBootstrap>() {
|
list.add(new Factory<Bootstrap>() {
|
||||||
@Override
|
@Override
|
||||||
public ClientBootstrap newInstance() {
|
public Bootstrap newInstance() {
|
||||||
return new ClientBootstrap().group(new OioEventLoopGroup()).channel(OioSocketChannel.class);
|
return new Bootstrap().group(new OioEventLoopGroup()).channel(OioSocketChannel.class);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return list;
|
return list;
|
||||||
|
|
|
@ -0,0 +1,256 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2012 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.bootstrap;
|
||||||
|
|
||||||
|
import java.net.InetAddress;
|
||||||
|
import java.net.InetSocketAddress;
|
||||||
|
import java.net.SocketAddress;
|
||||||
|
import java.util.LinkedHashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import io.netty.channel.Channel;
|
||||||
|
import io.netty.channel.EventLoopGroup;
|
||||||
|
import io.netty.channel.ChannelFuture;
|
||||||
|
import io.netty.channel.ChannelOption;
|
||||||
|
import io.netty.channel.ChannelHandler;
|
||||||
|
import io.netty.channel.ChannelException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@link AbstractBootstrap} is a helper class that makes it easy to bootstrap a {@link Channel}. It support
|
||||||
|
* method-chaining to provide an easy way to configure the {@link AbstractBootstrap}.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public abstract class AbstractBootstrap<B extends AbstractBootstrap<?>> {
|
||||||
|
private EventLoopGroup group;
|
||||||
|
private ChannelFactory factory;
|
||||||
|
private SocketAddress localAddress;
|
||||||
|
private final Map<ChannelOption<?>, Object> options = new LinkedHashMap<ChannelOption<?>, Object>();
|
||||||
|
private ChannelHandler handler;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The {@link EventLoopGroup} which is used to handle all the events for the to-be-creates
|
||||||
|
* {@link Channel}
|
||||||
|
*/
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
public B group(EventLoopGroup group) {
|
||||||
|
if (group == null) {
|
||||||
|
throw new NullPointerException("group");
|
||||||
|
}
|
||||||
|
if (this.group != null) {
|
||||||
|
throw new IllegalStateException("group set already");
|
||||||
|
}
|
||||||
|
this.group = group;
|
||||||
|
return (B) this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The {@link Class} which is used to create {@link Channel} instances from.
|
||||||
|
* You either use this or {@link #channelFactory(ChannelFactory)} if your
|
||||||
|
* {@link Channel} implementation has no no-args constructor.
|
||||||
|
*/
|
||||||
|
public B channel(Class<? extends Channel> channelClass) {
|
||||||
|
if (channelClass == null) {
|
||||||
|
throw new NullPointerException("channelClass");
|
||||||
|
}
|
||||||
|
return channelFactory(new BootstrapChannelFactory(channelClass));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@link ChannelFactory} which is used to create {@link Channel} instances from
|
||||||
|
* when calling {@link #bind()}. This method is usually only used if {@link #channel(Class)}
|
||||||
|
* is not working for you because of some more complex needs. If your {@link Channel} implementation
|
||||||
|
* has a no-args constructor, its highly recommend to just use {@link #channel(Class)} for
|
||||||
|
* simplify your code.
|
||||||
|
*/
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
public B channelFactory(ChannelFactory factory) {
|
||||||
|
if (factory == null) {
|
||||||
|
throw new NullPointerException("factory");
|
||||||
|
}
|
||||||
|
if (this.factory != null) {
|
||||||
|
throw new IllegalStateException("factory set already");
|
||||||
|
}
|
||||||
|
|
||||||
|
this.factory = factory;
|
||||||
|
return (B) this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The {@link SocketAddress} which is used to bind the local "end" to.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
public B localAddress(SocketAddress localAddress) {
|
||||||
|
this.localAddress = localAddress;
|
||||||
|
return (B) this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* See {@link #localAddress(SocketAddress)}
|
||||||
|
*/
|
||||||
|
public B localAddress(int port) {
|
||||||
|
return localAddress(new InetSocketAddress(port));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* See {@link #localAddress(SocketAddress)}
|
||||||
|
*/
|
||||||
|
public B localAddress(String host, int port) {
|
||||||
|
return localAddress(new InetSocketAddress(host, port));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* See {@link #localAddress(SocketAddress)}
|
||||||
|
*/
|
||||||
|
public B localAddress(InetAddress host, int port) {
|
||||||
|
return localAddress(new InetSocketAddress(host, port));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Allow to specify a {@link ChannelOption} which is used for the {@link Channel} instances once they got
|
||||||
|
* created. Use a value of <code>null</code> to remove a previous set {@link ChannelOption}.
|
||||||
|
*/
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
public <T> B option(ChannelOption<T> option, T value) {
|
||||||
|
if (option == null) {
|
||||||
|
throw new NullPointerException("option");
|
||||||
|
}
|
||||||
|
if (value == null) {
|
||||||
|
options.remove(option);
|
||||||
|
} else {
|
||||||
|
options.put(option, value);
|
||||||
|
}
|
||||||
|
return (B) this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Shutdown the {@link AbstractBootstrap} and the {@link EventLoopGroup} which is
|
||||||
|
* used by it. Only call this if you don't share the {@link EventLoopGroup}
|
||||||
|
* between different {@link AbstractBootstrap}'s.
|
||||||
|
*/
|
||||||
|
public void shutdown() {
|
||||||
|
if (group != null) {
|
||||||
|
group.shutdown();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Validate all the parameters. Sub-classes may override this, but should
|
||||||
|
* call the super method in that case.
|
||||||
|
*/
|
||||||
|
protected void validate() {
|
||||||
|
if (group == null) {
|
||||||
|
throw new IllegalStateException("group not set");
|
||||||
|
}
|
||||||
|
if (factory == null) {
|
||||||
|
throw new IllegalStateException("factory not set");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected final void validate(ChannelFuture future) {
|
||||||
|
if (future == null) {
|
||||||
|
throw new NullPointerException("future");
|
||||||
|
}
|
||||||
|
validate();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new {@link Channel} and bind it.
|
||||||
|
*/
|
||||||
|
public ChannelFuture bind() {
|
||||||
|
validate();
|
||||||
|
Channel channel = factory().newChannel();
|
||||||
|
return bind(channel.newFuture());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* the {@link ChannelHandler} to use for serving the requests.
|
||||||
|
*/
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
public B handler(ChannelHandler handler) {
|
||||||
|
if (handler == null) {
|
||||||
|
throw new NullPointerException("handler");
|
||||||
|
}
|
||||||
|
this.handler = handler;
|
||||||
|
return (B) this;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected static boolean ensureOpen(ChannelFuture future) {
|
||||||
|
if (!future.channel().isOpen()) {
|
||||||
|
// Registration was successful but the channel was closed due to some failure in
|
||||||
|
// handler.
|
||||||
|
future.setFailure(new ChannelException("initialization failure"));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Bind the {@link Channel} of the given {@link ChannelFactory}.
|
||||||
|
*/
|
||||||
|
public abstract ChannelFuture bind(ChannelFuture future);
|
||||||
|
|
||||||
|
protected final SocketAddress localAddress() {
|
||||||
|
return localAddress;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected final ChannelFactory factory() {
|
||||||
|
return factory;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected final ChannelHandler handler() {
|
||||||
|
return handler;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected final EventLoopGroup group() {
|
||||||
|
return group;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected final Map<ChannelOption<?>, Object> options() {
|
||||||
|
return options;
|
||||||
|
}
|
||||||
|
|
||||||
|
private final class BootstrapChannelFactory implements ChannelFactory {
|
||||||
|
private final Class<? extends Channel> clazz;
|
||||||
|
|
||||||
|
BootstrapChannelFactory(Class<? extends Channel> clazz) {
|
||||||
|
this.clazz = clazz;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Channel newChannel() {
|
||||||
|
try {
|
||||||
|
return clazz.newInstance();
|
||||||
|
} catch (Throwable t) {
|
||||||
|
throw new ChannelException("Unable to create Channel from class " + clazz, t);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Factory that is responsible to create new {@link Channel}'s on {@link AbstractBootstrap#bind()}
|
||||||
|
* requests.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public interface ChannelFactory {
|
||||||
|
/**
|
||||||
|
* {@link Channel} to use in the {@link AbstractBootstrap}
|
||||||
|
*/
|
||||||
|
Channel newChannel();
|
||||||
|
}
|
||||||
|
}
|
|
@ -13,244 +13,170 @@
|
||||||
* License for the specific language governing permissions and limitations
|
* License for the specific language governing permissions and limitations
|
||||||
* under the License.
|
* under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package io.netty.bootstrap;
|
package io.netty.bootstrap;
|
||||||
|
|
||||||
|
import io.netty.channel.Channel;
|
||||||
|
import io.netty.channel.ChannelHandler;
|
||||||
|
import io.netty.channel.ChannelPipeline;
|
||||||
|
import io.netty.channel.ChannelFutureListener;
|
||||||
|
import io.netty.channel.ChannelFuture;
|
||||||
|
import io.netty.channel.ChannelOption;
|
||||||
|
import io.netty.logging.InternalLogger;
|
||||||
|
import io.netty.logging.InternalLoggerFactory;
|
||||||
|
|
||||||
import java.net.InetAddress;
|
import java.net.InetAddress;
|
||||||
import java.net.InetSocketAddress;
|
import java.net.InetSocketAddress;
|
||||||
import java.net.SocketAddress;
|
import java.net.SocketAddress;
|
||||||
import java.util.LinkedHashMap;
|
import java.nio.channels.ClosedChannelException;
|
||||||
import java.util.Map;
|
import java.util.Map.Entry;
|
||||||
|
|
||||||
import io.netty.channel.Channel;
|
|
||||||
import io.netty.channel.EventLoopGroup;
|
|
||||||
import io.netty.channel.ChannelFuture;
|
|
||||||
import io.netty.channel.ChannelOption;
|
|
||||||
import io.netty.channel.ChannelHandler;
|
|
||||||
import io.netty.channel.ChannelException;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@link Bootstrap} is a helper class that makes it easy to bootstrap a {@link Channel}. It support
|
* A {@link Bootstrap} that makes it easy to bootstrap a {@link Channel} to use
|
||||||
* method-chaining to provide an easy way to configure the {@link Bootstrap}.
|
* for clients.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public abstract class Bootstrap<B extends Bootstrap<?>> {
|
public class Bootstrap extends AbstractBootstrap<Bootstrap> {
|
||||||
private EventLoopGroup group;
|
|
||||||
private ChannelFactory factory;
|
private static final InternalLogger logger = InternalLoggerFactory.getInstance(Bootstrap.class);
|
||||||
private SocketAddress localAddress;
|
private SocketAddress remoteAddress;
|
||||||
private final Map<ChannelOption<?>, Object> options = new LinkedHashMap<ChannelOption<?>, Object>();
|
|
||||||
private ChannelHandler handler;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The {@link EventLoopGroup} which is used to handle all the events for the to-be-creates
|
* The {@link SocketAddress} to connect to once the {@link #connect()} method
|
||||||
* {@link Channel}
|
* is called.
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("unchecked")
|
public Bootstrap remoteAddress(SocketAddress remoteAddress) {
|
||||||
public B group(EventLoopGroup group) {
|
this.remoteAddress = remoteAddress;
|
||||||
if (group == null) {
|
return this;
|
||||||
throw new NullPointerException("group");
|
|
||||||
}
|
|
||||||
if (this.group != null) {
|
|
||||||
throw new IllegalStateException("group set already");
|
|
||||||
}
|
|
||||||
this.group = group;
|
|
||||||
return (B) this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The {@link Class} which is used to create {@link Channel} instances from.
|
* See {@link #remoteAddress(SocketAddress)}
|
||||||
* You either use this or {@link #channelFactory(ChannelFactory)} if your
|
|
||||||
* {@link Channel} implementation has no no-args constructor.
|
|
||||||
*/
|
*/
|
||||||
public B channel(Class<? extends Channel> channelClass) {
|
public Bootstrap remoteAddress(String host, int port) {
|
||||||
if (channelClass == null) {
|
remoteAddress = new InetSocketAddress(host, port);
|
||||||
throw new NullPointerException("channelClass");
|
return this;
|
||||||
}
|
|
||||||
return channelFactory(new BootstrapChannelFactory(channelClass));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@link ChannelFactory} which is used to create {@link Channel} instances from
|
* See {@link #remoteAddress(SocketAddress)}
|
||||||
* when calling {@link #bind()}. This method is usually only used if {@link #channel(Class)}
|
|
||||||
* is not working for you because of some more complex needs. If your {@link Channel} implementation
|
|
||||||
* has a no-args constructor, its highly recommend to just use {@link #channel(Class)} for
|
|
||||||
* simplify your code.
|
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("unchecked")
|
public Bootstrap remoteAddress(InetAddress host, int port) {
|
||||||
public B channelFactory(ChannelFactory factory) {
|
remoteAddress = new InetSocketAddress(host, port);
|
||||||
if (factory == null) {
|
return this;
|
||||||
throw new NullPointerException("factory");
|
}
|
||||||
}
|
|
||||||
if (this.factory != null) {
|
@Override
|
||||||
throw new IllegalStateException("factory set already");
|
public ChannelFuture bind(ChannelFuture future) {
|
||||||
|
validate(future);
|
||||||
|
if (localAddress() == null) {
|
||||||
|
throw new IllegalStateException("localAddress not set");
|
||||||
}
|
}
|
||||||
|
|
||||||
this.factory = factory;
|
try {
|
||||||
return (B) this;
|
init(future.channel());
|
||||||
|
} catch (Throwable t) {
|
||||||
|
future.setFailure(t);
|
||||||
|
return future;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!ensureOpen(future)) {
|
||||||
|
return future;
|
||||||
|
}
|
||||||
|
|
||||||
|
return future.channel().bind(localAddress(), future).addListener(ChannelFutureListener.CLOSE_ON_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The {@link SocketAddress} which is used to bind the local "end" to.
|
* Connect a {@link Channel} to the remote peer.
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("unchecked")
|
public ChannelFuture connect() {
|
||||||
public B localAddress(SocketAddress localAddress) {
|
|
||||||
this.localAddress = localAddress;
|
|
||||||
return (B) this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* See {@link #localAddress(SocketAddress)}
|
|
||||||
*/
|
|
||||||
public B localAddress(int port) {
|
|
||||||
return localAddress(new InetSocketAddress(port));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* See {@link #localAddress(SocketAddress)}
|
|
||||||
*/
|
|
||||||
public B localAddress(String host, int port) {
|
|
||||||
return localAddress(new InetSocketAddress(host, port));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* See {@link #localAddress(SocketAddress)}
|
|
||||||
*/
|
|
||||||
public B localAddress(InetAddress host, int port) {
|
|
||||||
return localAddress(new InetSocketAddress(host, port));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Allow to specify a {@link ChannelOption} which is used for the {@link Channel} instances once they got
|
|
||||||
* created. Use a value of <code>null</code> to remove a previous set {@link ChannelOption}.
|
|
||||||
*/
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
public <T> B option(ChannelOption<T> option, T value) {
|
|
||||||
if (option == null) {
|
|
||||||
throw new NullPointerException("option");
|
|
||||||
}
|
|
||||||
if (value == null) {
|
|
||||||
options.remove(option);
|
|
||||||
} else {
|
|
||||||
options.put(option, value);
|
|
||||||
}
|
|
||||||
return (B) this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Shutdown the {@link Bootstrap} and the {@link EventLoopGroup} which is
|
|
||||||
* used by it. Only call this if you don't share the {@link EventLoopGroup}
|
|
||||||
* between different {@link Bootstrap}'s.
|
|
||||||
*/
|
|
||||||
public void shutdown() {
|
|
||||||
if (group != null) {
|
|
||||||
group.shutdown();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Validate all the parameters. Sub-classes may override this, but should
|
|
||||||
* call the super method in that case.
|
|
||||||
*/
|
|
||||||
protected void validate() {
|
|
||||||
if (group == null) {
|
|
||||||
throw new IllegalStateException("group not set");
|
|
||||||
}
|
|
||||||
if (factory == null) {
|
|
||||||
throw new IllegalStateException("factory not set");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected final void validate(ChannelFuture future) {
|
|
||||||
if (future == null) {
|
|
||||||
throw new NullPointerException("future");
|
|
||||||
}
|
|
||||||
validate();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a new {@link Channel} and bind it.
|
|
||||||
*/
|
|
||||||
public ChannelFuture bind() {
|
|
||||||
validate();
|
validate();
|
||||||
Channel channel = factory().newChannel();
|
Channel channel = factory().newChannel();
|
||||||
return bind(channel.newFuture());
|
return connect(channel.newFuture());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* the {@link ChannelHandler} to use for serving the requests.
|
* See {@link #connect()}
|
||||||
*/
|
*/
|
||||||
|
public ChannelFuture connect(ChannelFuture future) {
|
||||||
|
validate(future);
|
||||||
|
if (remoteAddress == null) {
|
||||||
|
throw new IllegalStateException("remoteAddress not set");
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
init(future.channel());
|
||||||
|
} catch (Throwable t) {
|
||||||
|
future.setFailure(t);
|
||||||
|
return future;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!ensureOpen(future)) {
|
||||||
|
return future;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (localAddress() == null) {
|
||||||
|
future.channel().connect(remoteAddress, future);
|
||||||
|
} else {
|
||||||
|
future.channel().connect(remoteAddress, localAddress(), future);
|
||||||
|
}
|
||||||
|
return future.addListener(ChannelFutureListener.CLOSE_ON_FAILURE);
|
||||||
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public B handler(ChannelHandler handler) {
|
private void init(Channel channel) throws Exception {
|
||||||
if (handler == null) {
|
if (channel.isActive()) {
|
||||||
throw new NullPointerException("handler");
|
throw new IllegalStateException("channel already active:: " + channel);
|
||||||
}
|
}
|
||||||
this.handler = handler;
|
if (channel.isRegistered()) {
|
||||||
return (B) this;
|
throw new IllegalStateException("channel already registered: " + channel);
|
||||||
}
|
|
||||||
|
|
||||||
protected static boolean ensureOpen(ChannelFuture future) {
|
|
||||||
if (!future.channel().isOpen()) {
|
|
||||||
// Registration was successful but the channel was closed due to some failure in
|
|
||||||
// handler.
|
|
||||||
future.setFailure(new ChannelException("initialization failure"));
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
return true;
|
if (!channel.isOpen()) {
|
||||||
}
|
throw new ClosedChannelException();
|
||||||
|
|
||||||
/**
|
|
||||||
* Bind the {@link Channel} of the given {@link ChannelFactory}.
|
|
||||||
*/
|
|
||||||
public abstract ChannelFuture bind(ChannelFuture future);
|
|
||||||
|
|
||||||
protected final SocketAddress localAddress() {
|
|
||||||
return localAddress;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected final ChannelFactory factory() {
|
|
||||||
return factory;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected final ChannelHandler handler() {
|
|
||||||
return handler;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected final EventLoopGroup group() {
|
|
||||||
return group;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected final Map<ChannelOption<?>, Object> options() {
|
|
||||||
return options;
|
|
||||||
}
|
|
||||||
|
|
||||||
private final class BootstrapChannelFactory implements ChannelFactory {
|
|
||||||
private final Class<? extends Channel> clazz;
|
|
||||||
|
|
||||||
BootstrapChannelFactory(Class<? extends Channel> clazz) {
|
|
||||||
this.clazz = clazz;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
ChannelPipeline p = channel.pipeline();
|
||||||
public Channel newChannel() {
|
p.addLast(handler());
|
||||||
|
|
||||||
|
for (Entry<ChannelOption<?>, Object> e: options().entrySet()) {
|
||||||
try {
|
try {
|
||||||
return clazz.newInstance();
|
if (!channel.config().setOption((ChannelOption<Object>) e.getKey(), e.getValue())) {
|
||||||
|
logger.warn("Unknown channel option: " + e);
|
||||||
|
}
|
||||||
} catch (Throwable t) {
|
} catch (Throwable t) {
|
||||||
throw new ChannelException("Unable to create Channel from class " + clazz, t);
|
logger.warn("Failed to set a channel option: " + channel, t);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
group().register(channel).syncUninterruptibly();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void validate() {
|
||||||
|
super.validate();
|
||||||
|
if (handler() == null) {
|
||||||
|
throw new IllegalStateException("handler not set");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Factory that is responsible to create new {@link Channel}'s on {@link Bootstrap#bind()}
|
* Create a new {@link Bootstrap} using this "full-setup" {@link Bootstrap} as template.
|
||||||
* requests.
|
* Only the given parameters are replaced, the rest is configured exactly the same way as the template.
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public interface ChannelFactory {
|
public Bootstrap newBootstrap(SocketAddress localAddress, SocketAddress remoteAddress, ChannelHandler handler) {
|
||||||
/**
|
validate();
|
||||||
* {@link Channel} to use in the {@link Bootstrap}
|
Bootstrap cb = new Bootstrap().handler(handler).channelFactory(factory()).group(group())
|
||||||
*/
|
.localAddress(localAddress).remoteAddress(remoteAddress);
|
||||||
Channel newChannel();
|
cb.options().putAll(options());
|
||||||
|
return cb;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new {@link Bootstrap} using this "full-setup" {@link Bootstrap} as template.
|
||||||
|
* Only the given parameters are replaced, the rest is configured exactly the same way as the template.
|
||||||
|
*/
|
||||||
|
public Bootstrap newBootstrap(SocketAddress localAddress, SocketAddress remoteAddress) {
|
||||||
|
return newBootstrap(localAddress, remoteAddress, handler());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,182 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright 2012 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.bootstrap;
|
|
||||||
|
|
||||||
import io.netty.channel.Channel;
|
|
||||||
import io.netty.channel.ChannelHandler;
|
|
||||||
import io.netty.channel.ChannelPipeline;
|
|
||||||
import io.netty.channel.ChannelFutureListener;
|
|
||||||
import io.netty.channel.ChannelFuture;
|
|
||||||
import io.netty.channel.ChannelOption;
|
|
||||||
import io.netty.logging.InternalLogger;
|
|
||||||
import io.netty.logging.InternalLoggerFactory;
|
|
||||||
|
|
||||||
import java.net.InetAddress;
|
|
||||||
import java.net.InetSocketAddress;
|
|
||||||
import java.net.SocketAddress;
|
|
||||||
import java.nio.channels.ClosedChannelException;
|
|
||||||
import java.util.Map.Entry;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A {@link Bootstrap} that makes it easy to bootstrap a {@link Channel} to use
|
|
||||||
* for clients.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public class ClientBootstrap extends Bootstrap<ClientBootstrap> {
|
|
||||||
|
|
||||||
private static final InternalLogger logger = InternalLoggerFactory.getInstance(ClientBootstrap.class);
|
|
||||||
private SocketAddress remoteAddress;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The {@link SocketAddress} to connect to once the {@link #connect()} method
|
|
||||||
* is called.
|
|
||||||
*/
|
|
||||||
public ClientBootstrap remoteAddress(SocketAddress remoteAddress) {
|
|
||||||
this.remoteAddress = remoteAddress;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* See {@link #remoteAddress(SocketAddress)}
|
|
||||||
*/
|
|
||||||
public ClientBootstrap remoteAddress(String host, int port) {
|
|
||||||
remoteAddress = new InetSocketAddress(host, port);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* See {@link #remoteAddress(SocketAddress)}
|
|
||||||
*/
|
|
||||||
public ClientBootstrap remoteAddress(InetAddress host, int port) {
|
|
||||||
remoteAddress = new InetSocketAddress(host, port);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ChannelFuture bind(ChannelFuture future) {
|
|
||||||
validate(future);
|
|
||||||
if (localAddress() == null) {
|
|
||||||
throw new IllegalStateException("localAddress not set");
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
init(future.channel());
|
|
||||||
} catch (Throwable t) {
|
|
||||||
future.setFailure(t);
|
|
||||||
return future;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!ensureOpen(future)) {
|
|
||||||
return future;
|
|
||||||
}
|
|
||||||
|
|
||||||
return future.channel().bind(localAddress(), future).addListener(ChannelFutureListener.CLOSE_ON_FAILURE);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Connect a {@link Channel} to the remote peer.
|
|
||||||
*/
|
|
||||||
public ChannelFuture connect() {
|
|
||||||
validate();
|
|
||||||
Channel channel = factory().newChannel();
|
|
||||||
return connect(channel.newFuture());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* See {@link #connect()}
|
|
||||||
*/
|
|
||||||
public ChannelFuture connect(ChannelFuture future) {
|
|
||||||
validate(future);
|
|
||||||
if (remoteAddress == null) {
|
|
||||||
throw new IllegalStateException("remoteAddress not set");
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
init(future.channel());
|
|
||||||
} catch (Throwable t) {
|
|
||||||
future.setFailure(t);
|
|
||||||
return future;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!ensureOpen(future)) {
|
|
||||||
return future;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (localAddress() == null) {
|
|
||||||
future.channel().connect(remoteAddress, future);
|
|
||||||
} else {
|
|
||||||
future.channel().connect(remoteAddress, localAddress(), future);
|
|
||||||
}
|
|
||||||
return future.addListener(ChannelFutureListener.CLOSE_ON_FAILURE);
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
private void init(Channel channel) throws Exception {
|
|
||||||
if (channel.isActive()) {
|
|
||||||
throw new IllegalStateException("channel already active:: " + channel);
|
|
||||||
}
|
|
||||||
if (channel.isRegistered()) {
|
|
||||||
throw new IllegalStateException("channel already registered: " + channel);
|
|
||||||
}
|
|
||||||
if (!channel.isOpen()) {
|
|
||||||
throw new ClosedChannelException();
|
|
||||||
}
|
|
||||||
|
|
||||||
ChannelPipeline p = channel.pipeline();
|
|
||||||
p.addLast(handler());
|
|
||||||
|
|
||||||
for (Entry<ChannelOption<?>, Object> e: options().entrySet()) {
|
|
||||||
try {
|
|
||||||
if (!channel.config().setOption((ChannelOption<Object>) e.getKey(), e.getValue())) {
|
|
||||||
logger.warn("Unknown channel option: " + e);
|
|
||||||
}
|
|
||||||
} catch (Throwable t) {
|
|
||||||
logger.warn("Failed to set a channel option: " + channel, t);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
group().register(channel).syncUninterruptibly();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void validate() {
|
|
||||||
super.validate();
|
|
||||||
if (handler() == null) {
|
|
||||||
throw new IllegalStateException("handler not set");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a new {@link ClientBootstrap} using this "full-setup" {@link ClientBootstrap} as template.
|
|
||||||
* Only the given parameters are replaced, the rest is configured exactly the same way as the template.
|
|
||||||
*/
|
|
||||||
public ClientBootstrap newBootstrap(SocketAddress localAddress, SocketAddress remoteAddress, ChannelHandler handler) {
|
|
||||||
validate();
|
|
||||||
ClientBootstrap cb = new ClientBootstrap().handler(handler).channelFactory(factory()).group(group()).localAddress(localAddress).remoteAddress(remoteAddress);
|
|
||||||
cb.options().putAll(options());
|
|
||||||
|
|
||||||
return cb;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a new {@link ClientBootstrap} using this "full-setup" {@link ClientBootstrap} as template.
|
|
||||||
* Only the given parameters are replaced, the rest is configured exactly the same way as the template.
|
|
||||||
*/
|
|
||||||
public ClientBootstrap newBootstrap(SocketAddress localAddress, SocketAddress remoteAddress) {
|
|
||||||
return newBootstrap(localAddress, remoteAddress, handler());
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -45,7 +45,7 @@ import java.util.Map.Entry;
|
||||||
* {@link Bootstrap} sub-class which allows easy bootstrap of {@link ServerChannel}
|
* {@link Bootstrap} sub-class which allows easy bootstrap of {@link ServerChannel}
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class ServerBootstrap extends Bootstrap<ServerBootstrap> {
|
public class ServerBootstrap extends AbstractBootstrap<ServerBootstrap> {
|
||||||
|
|
||||||
private static final InternalLogger logger = InternalLoggerFactory.getInstance(ServerBootstrap.class);
|
private static final InternalLogger logger = InternalLoggerFactory.getInstance(ServerBootstrap.class);
|
||||||
private static final InetSocketAddress DEFAULT_LOCAL_ADDR = new InetSocketAddress(NetworkConstants.LOCALHOST, 0);
|
private static final InetSocketAddress DEFAULT_LOCAL_ADDR = new InetSocketAddress(NetworkConstants.LOCALHOST, 0);
|
||||||
|
|
|
@ -129,7 +129,7 @@ import java.util.concurrent.TimeUnit;
|
||||||
* connect timeout should be configured via a transport-specific option:
|
* connect timeout should be configured via a transport-specific option:
|
||||||
* <pre>
|
* <pre>
|
||||||
* // BAD - NEVER DO THIS
|
* // BAD - NEVER DO THIS
|
||||||
* {@link ClientBootstrap} b = ...;
|
* {@link Bootstrap} b = ...;
|
||||||
* {@link ChannelFuture} f = b.connect(...);
|
* {@link ChannelFuture} f = b.connect(...);
|
||||||
* f.awaitUninterruptibly(10, TimeUnit.SECONDS);
|
* f.awaitUninterruptibly(10, TimeUnit.SECONDS);
|
||||||
* if (f.isCancelled()) {
|
* if (f.isCancelled()) {
|
||||||
|
@ -143,7 +143,7 @@ import java.util.concurrent.TimeUnit;
|
||||||
* }
|
* }
|
||||||
*
|
*
|
||||||
* // GOOD
|
* // GOOD
|
||||||
* {@link ClientBootstrap} b = ...;
|
* {@link Bootstrap} b = ...;
|
||||||
* // Configure the connect timeout option.
|
* // Configure the connect timeout option.
|
||||||
* <b>b.setOption("connectTimeoutMillis", 10000);</b>
|
* <b>b.setOption("connectTimeoutMillis", 10000);</b>
|
||||||
* {@link ChannelFuture} f = b.connect(...);
|
* {@link ChannelFuture} f = b.connect(...);
|
||||||
|
|
|
@ -15,7 +15,6 @@
|
||||||
*/
|
*/
|
||||||
package io.netty.channel;
|
package io.netty.channel;
|
||||||
|
|
||||||
import io.netty.bootstrap.ClientBootstrap;
|
|
||||||
import io.netty.channel.group.ChannelGroup;
|
import io.netty.channel.group.ChannelGroup;
|
||||||
|
|
||||||
import java.lang.annotation.Documented;
|
import java.lang.annotation.Documented;
|
||||||
|
|
|
@ -15,7 +15,7 @@
|
||||||
*/
|
*/
|
||||||
package io.netty.channel.local;
|
package io.netty.channel.local;
|
||||||
|
|
||||||
import io.netty.bootstrap.ClientBootstrap;
|
import io.netty.bootstrap.Bootstrap;
|
||||||
import io.netty.bootstrap.ServerBootstrap;
|
import io.netty.bootstrap.ServerBootstrap;
|
||||||
import io.netty.channel.Channel;
|
import io.netty.channel.Channel;
|
||||||
import io.netty.channel.ChannelHandlerContext;
|
import io.netty.channel.ChannelHandlerContext;
|
||||||
|
@ -39,7 +39,7 @@ public class LocalChannelRegistryTest {
|
||||||
|
|
||||||
for (int i = 0; i < 2; i ++) {
|
for (int i = 0; i < 2; i ++) {
|
||||||
LocalAddress addr = new LocalAddress(LOCAL_ADDR_ID);
|
LocalAddress addr = new LocalAddress(LOCAL_ADDR_ID);
|
||||||
ClientBootstrap cb = new ClientBootstrap();
|
Bootstrap cb = new Bootstrap();
|
||||||
ServerBootstrap sb = new ServerBootstrap();
|
ServerBootstrap sb = new ServerBootstrap();
|
||||||
|
|
||||||
cb.group(new LocalEventLoopGroup())
|
cb.group(new LocalEventLoopGroup())
|
||||||
|
|
Loading…
Reference in New Issue
Block a user