Rename classes as result of descussion on #594

This commit is contained in:
norman 2012-09-12 14:04:41 +02:00
parent d22480c0f4
commit df72356d7d
36 changed files with 492 additions and 493 deletions

View File

@ -15,7 +15,7 @@
*/
package io.netty.example.discard;
import io.netty.bootstrap.ClientBootstrap;
import io.netty.bootstrap.Bootstrap;
import io.netty.channel.ChannelFuture;
import io.netty.channel.socket.nio.NioEventLoopGroup;
import io.netty.channel.socket.nio.NioSocketChannel;
@ -36,7 +36,7 @@ public class DiscardClient {
}
public void run() throws Exception {
ClientBootstrap b = new ClientBootstrap();
Bootstrap b = new Bootstrap();
try {
b.group(new NioEventLoopGroup())
.channel(NioSocketChannel.class)

View File

@ -15,7 +15,7 @@
*/
package io.netty.example.echo;
import io.netty.bootstrap.ClientBootstrap;
import io.netty.bootstrap.Bootstrap;
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelOption;
@ -47,7 +47,7 @@ public class EchoClient {
public void run() throws Exception {
// Configure the client.
ClientBootstrap b = new ClientBootstrap();
Bootstrap b = new Bootstrap();
try {
b.group(new NioEventLoopGroup())
.channel(NioSocketChannel.class)

View File

@ -15,7 +15,7 @@
*/
package io.netty.example.factorial;
import io.netty.bootstrap.ClientBootstrap;
import io.netty.bootstrap.Bootstrap;
import io.netty.channel.ChannelFuture;
import io.netty.channel.socket.nio.NioEventLoopGroup;
import io.netty.channel.socket.nio.NioSocketChannel;
@ -37,7 +37,7 @@ public class FactorialClient {
}
public void run() throws Exception {
ClientBootstrap b = new ClientBootstrap();
Bootstrap b = new Bootstrap();
try {
b.group(new NioEventLoopGroup())
.channel(NioSocketChannel.class)

View File

@ -15,7 +15,7 @@
*/
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.socket.nio.NioEventLoopGroup;
import io.netty.channel.socket.nio.NioSocketChannel;
@ -62,7 +62,7 @@ public class HttpSnoopClient {
boolean ssl = scheme.equalsIgnoreCase("https");
// Configure the client.
ClientBootstrap b = new ClientBootstrap();
Bootstrap b = new Bootstrap();
try {
b.group(new NioEventLoopGroup())
.channel(NioSocketChannel.class)

View File

@ -36,7 +36,7 @@
//THE SOFTWARE.
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.channel.Channel;
import io.netty.channel.ChannelInitializer;
@ -65,7 +65,7 @@ public class WebSocketClient {
}
public void run() throws Exception {
ClientBootstrap b = new ClientBootstrap();
Bootstrap b = new Bootstrap();
try {
String protocol = uri.getScheme();

View File

@ -15,7 +15,7 @@
*/
package io.netty.example.localecho;
import io.netty.bootstrap.ClientBootstrap;
import io.netty.bootstrap.Bootstrap;
import io.netty.bootstrap.ServerBootstrap;
import io.netty.channel.Channel;
import io.netty.channel.ChannelFuture;
@ -43,7 +43,7 @@ public class LocalEcho {
// Address to bind on / connect to.
final LocalAddress addr = new LocalAddress(port);
ClientBootstrap cb = new ClientBootstrap();
Bootstrap cb = new Bootstrap();
ServerBootstrap sb = new ServerBootstrap();
try {
// Note that we can use any event loop to ensure certain local channels

View File

@ -15,7 +15,7 @@
*/
package io.netty.example.localtime;
import io.netty.bootstrap.ClientBootstrap;
import io.netty.bootstrap.Bootstrap;
import io.netty.channel.Channel;
import io.netty.channel.socket.nio.NioEventLoopGroup;
import io.netty.channel.socket.nio.NioSocketChannel;
@ -43,7 +43,7 @@ public class LocalTimeClient {
}
public void run() throws Exception {
ClientBootstrap b = new ClientBootstrap();
Bootstrap b = new Bootstrap();
try {
b.group(new NioEventLoopGroup())
.channel(NioSocketChannel.class)

View File

@ -15,7 +15,7 @@
*/
package io.netty.example.objectecho;
import io.netty.bootstrap.ClientBootstrap;
import io.netty.bootstrap.Bootstrap;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.socket.SocketChannel;
import io.netty.channel.socket.nio.NioEventLoopGroup;
@ -41,7 +41,7 @@ public class ObjectEchoClient {
}
public void run() throws Exception {
ClientBootstrap b = new ClientBootstrap();
Bootstrap b = new Bootstrap();
try {
b.group(new NioEventLoopGroup())
.channel(NioSocketChannel.class)

View File

@ -15,7 +15,7 @@
*/
package io.netty.example.proxy;
import io.netty.bootstrap.ClientBootstrap;
import io.netty.bootstrap.Bootstrap;
import io.netty.buffer.ByteBuf;
import io.netty.channel.Channel;
import io.netty.channel.ChannelFuture;
@ -43,7 +43,7 @@ public class HexDumpProxyFrontendHandler extends ChannelInboundByteHandlerAdapte
final Channel inboundChannel = ctx.channel();
// Start the connection attempt.
ClientBootstrap b = new ClientBootstrap();
Bootstrap b = new Bootstrap();
b.group(inboundChannel.eventLoop())
.channel(NioSocketChannel.class)
.remoteAddress(remoteHost, remotePort)

View File

@ -15,7 +15,7 @@
*/
package io.netty.example.qotm;
import io.netty.bootstrap.ClientBootstrap;
import io.netty.bootstrap.Bootstrap;
import io.netty.buffer.Unpooled;
import io.netty.channel.Channel;
import io.netty.channel.ChannelOption;
@ -41,7 +41,7 @@ public class QuoteOfTheMomentClient {
}
public void run() throws Exception {
ClientBootstrap b = new ClientBootstrap();
Bootstrap b = new Bootstrap();
try {
b.group(new NioEventLoopGroup())
.channel(NioDatagramChannel.class)

View File

@ -15,7 +15,7 @@
*/
package io.netty.example.qotm;
import io.netty.bootstrap.ClientBootstrap;
import io.netty.bootstrap.Bootstrap;
import io.netty.channel.ChannelOption;
import io.netty.channel.socket.nio.NioDatagramChannel;
import io.netty.channel.socket.nio.NioEventLoopGroup;
@ -37,7 +37,7 @@ public class QuoteOfTheMomentServer {
}
public void run() throws Exception {
ClientBootstrap b = new ClientBootstrap();
Bootstrap b = new Bootstrap();
try {
b.group(new NioEventLoopGroup())
.channel(NioDatagramChannel.class)

View File

@ -15,8 +15,8 @@
*/
package io.netty.example.sctp;
import io.netty.bootstrap.AbstractBootstrap;
import io.netty.bootstrap.Bootstrap;
import io.netty.bootstrap.ClientBootstrap;
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelOption;
@ -52,7 +52,7 @@ public class SctpEchoClient {
public void run() throws Exception {
// Configure the client.
ClientBootstrap b = new ClientBootstrap();
Bootstrap b = new Bootstrap();
try {
b.group(new NioEventLoopGroup())
.channel(NioSctpChannel.class)

View File

@ -15,7 +15,7 @@
*/
package io.netty.example.securechat;
import io.netty.bootstrap.ClientBootstrap;
import io.netty.bootstrap.Bootstrap;
import io.netty.channel.Channel;
import io.netty.channel.ChannelFuture;
import io.netty.channel.socket.nio.NioEventLoopGroup;
@ -39,7 +39,7 @@ public class SecureChatClient {
}
public void run() throws Exception {
ClientBootstrap b = new ClientBootstrap();
Bootstrap b = new Bootstrap();
try {
b.group(new NioEventLoopGroup())
.channel(NioSocketChannel.class)

View File

@ -15,7 +15,7 @@
*/
package io.netty.example.telnet;
import io.netty.bootstrap.ClientBootstrap;
import io.netty.bootstrap.Bootstrap;
import io.netty.channel.Channel;
import io.netty.channel.ChannelFuture;
import io.netty.channel.socket.nio.NioEventLoopGroup;
@ -38,7 +38,7 @@ public class TelnetClient {
}
public void run() throws Exception {
ClientBootstrap b = new ClientBootstrap();
Bootstrap b = new Bootstrap();
try {
b.group(new NioEventLoopGroup())
.channel(NioSocketChannel.class)

View File

@ -15,7 +15,7 @@
*/
package io.netty.example.uptime;
import io.netty.bootstrap.ClientBootstrap;
import io.netty.bootstrap.Bootstrap;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.socket.SocketChannel;
@ -50,14 +50,14 @@ public class UptimeClient {
}
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());
}
ClientBootstrap configureBootstrap(ClientBootstrap b, EventLoopGroup g) {
Bootstrap configureBootstrap(Bootstrap b, EventLoopGroup g) {
b.group(g)
.channel(NioSocketChannel.class)
.remoteAddress(host, port)

View File

@ -15,7 +15,7 @@
*/
package io.netty.example.uptime;
import io.netty.bootstrap.ClientBootstrap;
import io.netty.bootstrap.Bootstrap;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandler.Sharable;
import io.netty.channel.ChannelHandlerContext;
@ -84,7 +84,7 @@ public class UptimeClientHandler extends ChannelInboundByteHandlerAdapter {
@Override
public void run() {
println("Reconnecting to: " + ctx.channel().remoteAddress());
client.configureBootstrap(new ClientBootstrap(), loop).connect();
client.configureBootstrap(new Bootstrap(), loop).connect();
}
}, UptimeClient.RECONNECT_DELAY, TimeUnit.SECONDS);
}

View File

@ -15,7 +15,7 @@
*/
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.InternalLoggerFactory;
import io.netty.testsuite.transport.socket.SocketTestPermutation.Factory;
@ -32,19 +32,19 @@ import org.junit.rules.TestName;
public abstract class AbstractClientSocketTest {
private static final List<Factory<ClientBootstrap>> COMBO = SocketTestPermutation.clientSocket();
private static final List<Factory<Bootstrap>> COMBO = SocketTestPermutation.clientSocket();
@Rule
public final TestName testName = new TestName();
protected final InternalLogger logger = InternalLoggerFactory.getInstance(getClass());
protected volatile ClientBootstrap cb;
protected volatile Bootstrap cb;
protected volatile InetSocketAddress addr;
protected void run() throws Throwable {
int i = 0;
for (Factory<ClientBootstrap> e: COMBO) {
for (Factory<Bootstrap> e: COMBO) {
cb = e.newInstance();
addr = new InetSocketAddress(
NetworkConstants.LOCALHOST, TestUtils.getFreePort());
@ -54,7 +54,7 @@ public abstract class AbstractClientSocketTest {
"Running: %s %d of %d", testName.getMethodName(), ++ i, COMBO.size()));
try {
Method m = getClass().getDeclaredMethod(
testName.getMethodName(), ClientBootstrap.class);
testName.getMethodName(), Bootstrap.class);
m.invoke(this, cb);
} catch (InvocationTargetException ex) {
throw ex.getCause();

View File

@ -15,8 +15,8 @@
*/
package io.netty.testsuite.transport.socket;
import io.netty.bootstrap.AbstractBootstrap;
import io.netty.bootstrap.Bootstrap;
import io.netty.bootstrap.ClientBootstrap;
import io.netty.logging.InternalLogger;
import io.netty.logging.InternalLoggerFactory;
import io.netty.testsuite.transport.socket.SocketTestPermutation.Factory;
@ -34,7 +34,7 @@ import org.junit.rules.TestName;
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();
@Rule
@ -42,13 +42,13 @@ public abstract class AbstractDatagramTest {
protected final InternalLogger logger = InternalLoggerFactory.getInstance(getClass());
protected volatile ClientBootstrap sb;
protected volatile ClientBootstrap cb;
protected volatile Bootstrap sb;
protected volatile Bootstrap cb;
protected volatile InetSocketAddress addr;
protected void run() throws Throwable {
int i = 0;
for (Entry<Factory<ClientBootstrap>, Factory<ClientBootstrap>> e: COMBO) {
for (Entry<Factory<Bootstrap>, Factory<Bootstrap>> e: COMBO) {
sb = e.getKey().newInstance();
cb = e.getValue().newInstance();
addr = new InetSocketAddress(
@ -60,7 +60,7 @@ public abstract class AbstractDatagramTest {
"Running: %s %d of %d", testName.getMethodName(), ++ i, COMBO.size()));
try {
Method m = getClass().getDeclaredMethod(
testName.getMethodName(), Bootstrap.class, Bootstrap.class);
testName.getMethodName(), AbstractBootstrap.class, AbstractBootstrap.class);
m.invoke(this, sb, cb);
} catch (InvocationTargetException ex) {
throw ex.getCause();

View File

@ -15,7 +15,7 @@
*/
package io.netty.testsuite.transport.socket;
import io.netty.bootstrap.ClientBootstrap;
import io.netty.bootstrap.Bootstrap;
import io.netty.bootstrap.ServerBootstrap;
import io.netty.logging.InternalLogger;
import io.netty.logging.InternalLoggerFactory;
@ -34,7 +34,7 @@ import org.junit.rules.TestName;
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();
@Rule
@ -43,13 +43,13 @@ public abstract class AbstractSocketTest {
protected final InternalLogger logger = InternalLoggerFactory.getInstance(getClass());
protected volatile ServerBootstrap sb;
protected volatile ClientBootstrap cb;
protected volatile Bootstrap cb;
protected volatile InetSocketAddress addr;
protected volatile Factory<ClientBootstrap> currentBootstrap;
protected volatile Factory<Bootstrap> currentBootstrap;
protected void run() throws Throwable {
int i = 0;
for (Entry<Factory<ServerBootstrap>, Factory<ClientBootstrap>> e: COMBO) {
for (Entry<Factory<ServerBootstrap>, Factory<Bootstrap>> e: COMBO) {
currentBootstrap = e.getValue();
sb = e.getKey().newInstance();
cb = e.getValue().newInstance();
@ -62,7 +62,7 @@ public abstract class AbstractSocketTest {
"Running: %s %d of %d", testName.getMethodName(), ++ i, COMBO.size()));
try {
Method m = getClass().getDeclaredMethod(
testName.getMethodName(), ServerBootstrap.class, ClientBootstrap.class);
testName.getMethodName(), ServerBootstrap.class, Bootstrap.class);
m.invoke(this, sb, cb);
} catch (InvocationTargetException ex) {
throw ex.getCause();

View File

@ -16,7 +16,7 @@
package io.netty.testsuite.transport.socket;
import static org.junit.Assert.*;
import io.netty.bootstrap.Bootstrap;
import io.netty.bootstrap.AbstractBootstrap;
import io.netty.buffer.Unpooled;
import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerContext;
@ -40,7 +40,7 @@ public class DatagramMulticastTest extends AbstractDatagramTest {
run();
}
public void testMulticast(Bootstrap sb, Bootstrap cb) throws Throwable {
public void testMulticast(AbstractBootstrap sb, AbstractBootstrap cb) throws Throwable {
MulticastTestHandler mhandler = new MulticastTestHandler();
sb.handler(new ChannelInboundMessageHandlerAdapter<DatagramPacket>() {

View File

@ -16,7 +16,7 @@
package io.netty.testsuite.transport.socket;
import static org.junit.Assert.*;
import io.netty.bootstrap.Bootstrap;
import io.netty.bootstrap.AbstractBootstrap;
import io.netty.buffer.Unpooled;
import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerContext;
@ -36,7 +36,7 @@ public class DatagramUnicastTest extends AbstractDatagramTest {
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);
sb.handler(new ChannelInboundMessageHandlerAdapter<DatagramPacket>() {

View File

@ -16,7 +16,7 @@
package io.netty.testsuite.transport.socket;
import static org.junit.Assert.*;
import io.netty.bootstrap.ClientBootstrap;
import io.netty.bootstrap.Bootstrap;
import io.netty.bootstrap.ServerBootstrap;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
@ -44,7 +44,7 @@ public class SocketEchoTest extends AbstractSocketTest {
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);
}
@ -53,11 +53,11 @@ public class SocketEchoTest extends AbstractSocketTest {
run();
}
public void testSimpleEchoWithBoundedBuffer(ServerBootstrap sb, ClientBootstrap cb) throws Throwable {
public void testSimpleEchoWithBoundedBuffer(ServerBootstrap sb, Bootstrap cb) throws Throwable {
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 ch = new EchoHandler(maxInboundBufferSize);

View File

@ -16,7 +16,7 @@
package io.netty.testsuite.transport.socket;
import static org.junit.Assert.*;
import io.netty.bootstrap.ClientBootstrap;
import io.netty.bootstrap.Bootstrap;
import io.netty.bootstrap.ServerBootstrap;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
@ -47,7 +47,7 @@ public class SocketFixedLengthEchoTest extends AbstractSocketTest {
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 ch = new EchoHandler();

View File

@ -16,7 +16,7 @@
package io.netty.testsuite.transport.socket;
import static org.junit.Assert.*;
import io.netty.bootstrap.ClientBootstrap;
import io.netty.bootstrap.Bootstrap;
import io.netty.bootstrap.ServerBootstrap;
import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerContext;
@ -55,7 +55,7 @@ public class SocketObjectEchoTest extends AbstractSocketTest {
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 ch = new EchoHandler();

View File

@ -16,7 +16,7 @@
package io.netty.testsuite.transport.socket;
import static org.junit.Assert.*;
import io.netty.bootstrap.ClientBootstrap;
import io.netty.bootstrap.Bootstrap;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelHandlerContext;
@ -37,7 +37,7 @@ public class SocketShutdownOutputBySelfTest extends AbstractClientSocketTest {
run();
}
public void testShutdownOutput(ClientBootstrap cb) throws Throwable {
public void testShutdownOutput(Bootstrap cb) throws Throwable {
TestHandler h = new TestHandler();
ServerSocket ss = new ServerSocket();
Socket s = null;

View File

@ -16,7 +16,7 @@
package io.netty.testsuite.transport.socket;
import static org.junit.Assert.*;
import io.netty.bootstrap.ClientBootstrap;
import io.netty.bootstrap.Bootstrap;
import io.netty.bootstrap.ServerBootstrap;
import io.netty.buffer.ByteBuf;
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);

View File

@ -16,7 +16,7 @@
package io.netty.testsuite.transport.socket;
import static org.junit.Assert.*;
import io.netty.bootstrap.ClientBootstrap;
import io.netty.bootstrap.Bootstrap;
import io.netty.bootstrap.ServerBootstrap;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
@ -67,7 +67,7 @@ public class SocketSslEchoTest extends AbstractSocketTest {
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 ch = new EchoHandler(false);

View File

@ -16,7 +16,7 @@
package io.netty.testsuite.transport.socket;
import static org.junit.Assert.*;
import io.netty.bootstrap.ClientBootstrap;
import io.netty.bootstrap.Bootstrap;
import io.netty.bootstrap.ServerBootstrap;
import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerContext;
@ -57,7 +57,7 @@ public class SocketStringEchoTest extends AbstractSocketTest {
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 ch = new StringEchoHandler();

View File

@ -15,8 +15,8 @@
*/
package io.netty.testsuite.transport.socket;
import io.netty.bootstrap.Bootstrap.ChannelFactory;
import io.netty.bootstrap.ClientBootstrap;
import io.netty.bootstrap.AbstractBootstrap.ChannelFactory;
import io.netty.bootstrap.Bootstrap;
import io.netty.bootstrap.ServerBootstrap;
import io.netty.channel.Channel;
import io.netty.channel.socket.InternetProtocolFamily;
@ -38,34 +38,34 @@ import java.util.Map.Entry;
final class SocketTestPermutation {
static List<Entry<Factory<ServerBootstrap>, Factory<ClientBootstrap>>> socket() {
List<Entry<Factory<ServerBootstrap>, Factory<ClientBootstrap>>> list =
new ArrayList<Entry<Factory<ServerBootstrap>, Factory<ClientBootstrap>>>();
static List<Entry<Factory<ServerBootstrap>, Factory<Bootstrap>>> socket() {
List<Entry<Factory<ServerBootstrap>, Factory<Bootstrap>>> list =
new ArrayList<Entry<Factory<ServerBootstrap>, Factory<Bootstrap>>>();
// Make the list of ServerBootstrap factories.
List<Factory<ServerBootstrap>> sbfs = serverSocket();
// Make the list of Bootstrap factories.
List<Factory<ClientBootstrap>> cbfs = clientSocket();
List<Factory<Bootstrap>> cbfs = clientSocket();
// Populate the combinations
for (Factory<ServerBootstrap> sbf: sbfs) {
for (Factory<ClientBootstrap> cbf: cbfs) {
for (Factory<Bootstrap> cbf: cbfs) {
final Factory<ServerBootstrap> sbf0 = sbf;
final Factory<ClientBootstrap> cbf0 = cbf;
list.add(new Entry<Factory<ServerBootstrap>, Factory<ClientBootstrap>>() {
final Factory<Bootstrap> cbf0 = cbf;
list.add(new Entry<Factory<ServerBootstrap>, Factory<Bootstrap>>() {
@Override
public Factory<ServerBootstrap> getKey() {
return sbf0;
}
@Override
public Factory<ClientBootstrap> getValue() {
public Factory<Bootstrap> getValue() {
return cbf0;
}
@Override
public Factory<ClientBootstrap> setValue(Factory<ClientBootstrap> value) {
public Factory<Bootstrap> setValue(Factory<Bootstrap> value) {
throw new UnsupportedOperationException();
}
});
@ -78,17 +78,17 @@ final class SocketTestPermutation {
return list;
}
static List<Entry<Factory<ClientBootstrap>, Factory<ClientBootstrap>>> datagram() {
List<Entry<Factory<ClientBootstrap>, Factory<ClientBootstrap>>> list =
new ArrayList<Entry<Factory<ClientBootstrap>, Factory<ClientBootstrap>>>();
static List<Entry<Factory<Bootstrap>, Factory<Bootstrap>>> datagram() {
List<Entry<Factory<Bootstrap>, Factory<Bootstrap>>> list =
new ArrayList<Entry<Factory<Bootstrap>, Factory<Bootstrap>>>();
// Make the list of Bootstrap factories.
List<Factory<ClientBootstrap>> bfs =
new ArrayList<Factory<ClientBootstrap>>();
bfs.add(new Factory<ClientBootstrap>() {
List<Factory<Bootstrap>> bfs =
new ArrayList<Factory<Bootstrap>>();
bfs.add(new Factory<Bootstrap>() {
@Override
public ClientBootstrap newInstance() {
return new ClientBootstrap().group(new NioEventLoopGroup()).channelFactory(new ChannelFactory() {
public Bootstrap newInstance() {
return new Bootstrap().group(new NioEventLoopGroup()).channelFactory(new ChannelFactory() {
@Override
public Channel newChannel() {
return new NioDatagramChannel(InternetProtocolFamily.IPv4);
@ -96,31 +96,31 @@ final class SocketTestPermutation {
});
}
});
bfs.add(new Factory<ClientBootstrap>() {
bfs.add(new Factory<Bootstrap>() {
@Override
public ClientBootstrap newInstance() {
return new ClientBootstrap().group(new OioEventLoopGroup()).channel(OioDatagramChannel.class);
public Bootstrap newInstance() {
return new Bootstrap().group(new OioEventLoopGroup()).channel(OioDatagramChannel.class);
}
});
// Populate the combinations
for (Factory<ClientBootstrap> sbf: bfs) {
for (Factory<ClientBootstrap> cbf: bfs) {
final Factory<ClientBootstrap> sbf0 = sbf;
final Factory<ClientBootstrap> cbf0 = cbf;
list.add(new Entry<Factory<ClientBootstrap>, Factory<ClientBootstrap>>() {
for (Factory<Bootstrap> sbf: bfs) {
for (Factory<Bootstrap> cbf: bfs) {
final Factory<Bootstrap> sbf0 = sbf;
final Factory<Bootstrap> cbf0 = cbf;
list.add(new Entry<Factory<Bootstrap>, Factory<Bootstrap>>() {
@Override
public Factory<ClientBootstrap> getKey() {
public Factory<Bootstrap> getKey() {
return sbf0;
}
@Override
public Factory<ClientBootstrap> getValue() {
public Factory<Bootstrap> getValue() {
return cbf0;
}
@Override
public Factory<ClientBootstrap> setValue(Factory<ClientBootstrap> value) {
public Factory<Bootstrap> setValue(Factory<Bootstrap> value) {
throw new UnsupportedOperationException();
}
});
@ -168,19 +168,19 @@ final class SocketTestPermutation {
return list;
}
static List<Factory<ClientBootstrap>> clientSocket() {
List<Factory<ClientBootstrap>> list = new ArrayList<Factory<ClientBootstrap>>();
list.add(new Factory<ClientBootstrap>() {
static List<Factory<Bootstrap>> clientSocket() {
List<Factory<Bootstrap>> list = new ArrayList<Factory<Bootstrap>>();
list.add(new Factory<Bootstrap>() {
@Override
public ClientBootstrap newInstance() {
return new ClientBootstrap().group(new NioEventLoopGroup()).channel(NioSocketChannel.class);
public Bootstrap newInstance() {
return new Bootstrap().group(new NioEventLoopGroup()).channel(NioSocketChannel.class);
}
});
list.add(new Factory<ClientBootstrap>() {
list.add(new Factory<Bootstrap>() {
@Override
public ClientBootstrap newInstance() {
public Bootstrap newInstance() {
final AioEventLoopGroup loop = new AioEventLoopGroup();
return new ClientBootstrap().group(loop).channelFactory(new ChannelFactory() {
return new Bootstrap().group(loop).channelFactory(new ChannelFactory() {
@Override
public Channel newChannel() {
return new AioSocketChannel(loop);
@ -188,10 +188,10 @@ final class SocketTestPermutation {
});
}
});
list.add(new Factory<ClientBootstrap>() {
list.add(new Factory<Bootstrap>() {
@Override
public ClientBootstrap newInstance() {
return new ClientBootstrap().group(new OioEventLoopGroup()).channel(OioSocketChannel.class);
public Bootstrap newInstance() {
return new Bootstrap().group(new OioEventLoopGroup()).channel(OioSocketChannel.class);
}
});
return list;

View File

@ -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();
}
}

View File

@ -13,244 +13,170 @@
* 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.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;
import java.nio.channels.ClosedChannelException;
import java.util.Map.Entry;
/**
* {@link Bootstrap} 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 Bootstrap}.
* A {@link Bootstrap} that makes it easy to bootstrap a {@link Channel} to use
* for clients.
*
*/
public abstract class Bootstrap<B extends Bootstrap<?>> {
private EventLoopGroup group;
private ChannelFactory factory;
private SocketAddress localAddress;
private final Map<ChannelOption<?>, Object> options = new LinkedHashMap<ChannelOption<?>, Object>();
private ChannelHandler handler;
public class Bootstrap extends AbstractBootstrap<Bootstrap> {
private static final InternalLogger logger = InternalLoggerFactory.getInstance(Bootstrap.class);
private SocketAddress remoteAddress;
/**
* The {@link EventLoopGroup} which is used to handle all the events for the to-be-creates
* {@link Channel}
* The {@link SocketAddress} to connect to once the {@link #connect()} method
* is called.
*/
@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;
public Bootstrap remoteAddress(SocketAddress remoteAddress) {
this.remoteAddress = remoteAddress;
return 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.
* See {@link #remoteAddress(SocketAddress)}
*/
public B channel(Class<? extends Channel> channelClass) {
if (channelClass == null) {
throw new NullPointerException("channelClass");
}
return channelFactory(new BootstrapChannelFactory(channelClass));
public Bootstrap remoteAddress(String host, int port) {
remoteAddress = new InetSocketAddress(host, port);
return this;
}
/**
* {@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.
* See {@link #remoteAddress(SocketAddress)}
*/
@SuppressWarnings("unchecked")
public B channelFactory(ChannelFactory factory) {
if (factory == null) {
throw new NullPointerException("factory");
}
if (this.factory != null) {
throw new IllegalStateException("factory set already");
public Bootstrap 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");
}
this.factory = factory;
return (B) this;
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);
}
/**
* The {@link SocketAddress} which is used to bind the local "end" to.
*
* Connect a {@link Channel} to the remote peer.
*/
@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 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() {
public ChannelFuture connect() {
validate();
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")
public B handler(ChannelHandler handler) {
if (handler == null) {
throw new NullPointerException("handler");
private void init(Channel channel) throws Exception {
if (channel.isActive()) {
throw new IllegalStateException("channel already active:: " + channel);
}
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;
if (channel.isRegistered()) {
throw new IllegalStateException("channel already registered: " + channel);
}
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;
if (!channel.isOpen()) {
throw new ClosedChannelException();
}
@Override
public Channel newChannel() {
ChannelPipeline p = channel.pipeline();
p.addLast(handler());
for (Entry<ChannelOption<?>, Object> e: options().entrySet()) {
try {
return clazz.newInstance();
if (!channel.config().setOption((ChannelOption<Object>) e.getKey(), e.getValue())) {
logger.warn("Unknown channel option: " + e);
}
} 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()}
* requests.
*
* 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 interface ChannelFactory {
/**
* {@link Channel} to use in the {@link Bootstrap}
*/
Channel newChannel();
public Bootstrap newBootstrap(SocketAddress localAddress, SocketAddress remoteAddress, ChannelHandler handler) {
validate();
Bootstrap cb = new Bootstrap().handler(handler).channelFactory(factory()).group(group())
.localAddress(localAddress).remoteAddress(remoteAddress);
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());
}
}

View File

@ -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());
}
}

View File

@ -45,7 +45,7 @@ import java.util.Map.Entry;
* {@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 InetSocketAddress DEFAULT_LOCAL_ADDR = new InetSocketAddress(NetworkConstants.LOCALHOST, 0);

View File

@ -129,7 +129,7 @@ import java.util.concurrent.TimeUnit;
* connect timeout should be configured via a transport-specific option:
* <pre>
* // BAD - NEVER DO THIS
* {@link ClientBootstrap} b = ...;
* {@link Bootstrap} b = ...;
* {@link ChannelFuture} f = b.connect(...);
* f.awaitUninterruptibly(10, TimeUnit.SECONDS);
* if (f.isCancelled()) {
@ -143,7 +143,7 @@ import java.util.concurrent.TimeUnit;
* }
*
* // GOOD
* {@link ClientBootstrap} b = ...;
* {@link Bootstrap} b = ...;
* // Configure the connect timeout option.
* <b>b.setOption("connectTimeoutMillis", 10000);</b>
* {@link ChannelFuture} f = b.connect(...);

View File

@ -15,7 +15,6 @@
*/
package io.netty.channel;
import io.netty.bootstrap.ClientBootstrap;
import io.netty.channel.group.ChannelGroup;
import java.lang.annotation.Documented;

View File

@ -15,7 +15,7 @@
*/
package io.netty.channel.local;
import io.netty.bootstrap.ClientBootstrap;
import io.netty.bootstrap.Bootstrap;
import io.netty.bootstrap.ServerBootstrap;
import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerContext;
@ -39,7 +39,7 @@ public class LocalChannelRegistryTest {
for (int i = 0; i < 2; i ++) {
LocalAddress addr = new LocalAddress(LOCAL_ADDR_ID);
ClientBootstrap cb = new ClientBootstrap();
Bootstrap cb = new Bootstrap();
ServerBootstrap sb = new ServerBootstrap();
cb.group(new LocalEventLoopGroup())