Added more convenience methods to bootstraps
This commit is contained in:
parent
626c5ef9c9
commit
a2698e65fb
@ -3,6 +3,7 @@ package io.netty.channel;
|
|||||||
import io.netty.logging.InternalLogger;
|
import io.netty.logging.InternalLogger;
|
||||||
import io.netty.logging.InternalLoggerFactory;
|
import io.netty.logging.InternalLoggerFactory;
|
||||||
|
|
||||||
|
import java.net.InetSocketAddress;
|
||||||
import java.net.SocketAddress;
|
import java.net.SocketAddress;
|
||||||
import java.nio.channels.ClosedChannelException;
|
import java.nio.channels.ClosedChannelException;
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
@ -61,11 +62,26 @@ public class ChannelBootstrap {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ChannelBootstrap localAddress(int port) {
|
||||||
|
localAddress = new InetSocketAddress(port);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ChannelBootstrap localAddress(String host, int port) {
|
||||||
|
localAddress = new InetSocketAddress(host, port);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
public ChannelBootstrap remoteAddress(SocketAddress remoteAddress) {
|
public ChannelBootstrap remoteAddress(SocketAddress remoteAddress) {
|
||||||
this.remoteAddress = remoteAddress;
|
this.remoteAddress = remoteAddress;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ChannelBootstrap remoteAddress(String host, int port) {
|
||||||
|
remoteAddress = new InetSocketAddress(host, port);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
public ChannelFuture bind() {
|
public ChannelFuture bind() {
|
||||||
validate();
|
validate();
|
||||||
return bind(channel.newFuture());
|
return bind(channel.newFuture());
|
||||||
|
@ -17,7 +17,7 @@ public class ServerChannelBootstrap {
|
|||||||
private static final InternalLogger logger = InternalLoggerFactory.getInstance(ServerChannelBootstrap.class);
|
private static final InternalLogger logger = InternalLoggerFactory.getInstance(ServerChannelBootstrap.class);
|
||||||
private static final InetSocketAddress DEFAULT_LOCAL_ADDR = new InetSocketAddress(SocketAddresses.LOCALHOST, 0);
|
private static final InetSocketAddress DEFAULT_LOCAL_ADDR = new InetSocketAddress(SocketAddresses.LOCALHOST, 0);
|
||||||
|
|
||||||
private final ChannelHandler acceptor = new ChannelInitializer() {
|
private final ChannelHandler acceptor = new ChannelInitializer<Channel>() {
|
||||||
@Override
|
@Override
|
||||||
public void initChannel(Channel ch) throws Exception {
|
public void initChannel(Channel ch) throws Exception {
|
||||||
Acceptor acceptor = new Acceptor();
|
Acceptor acceptor = new Acceptor();
|
||||||
@ -96,6 +96,16 @@ public class ServerChannelBootstrap {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ServerChannelBootstrap localAddress(int port) {
|
||||||
|
localAddress = new InetSocketAddress(port);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ServerChannelBootstrap localAddress(String host, int port) {
|
||||||
|
localAddress = new InetSocketAddress(host, port);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
public ChannelFuture bind() {
|
public ChannelFuture bind() {
|
||||||
validate();
|
validate();
|
||||||
return bind(channel.newFuture());
|
return bind(channel.newFuture());
|
||||||
|
Loading…
Reference in New Issue
Block a user