本文整理汇总了Java中io.netty.channel.EventLoopGroup.shutdownGracefully方法的典型用法代码示例。如果您正苦于以下问题:Java EventLoopGroup.shutdownGracefully方法的具体用法?Java EventLoopGroup.shutdownGracefully怎么用?Java EventLoopGroup.shutdownGracefully使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类io.netty.channel.EventLoopGroup
的用法示例。
在下文中一共展示了EventLoopGroup.shutdownGracefully方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: start
import io.netty.channel.EventLoopGroup; //导入方法依赖的package包/类
@Override
public void start(Config config) throws Exception {
EventLoopGroup bossGroup = new NioEventLoopGroup(1);
EventLoopGroup workerGroup = new NioEventLoopGroup();
int port = config.getPort();
try {
ServerBootstrap b = new ServerBootstrap();
b.group(bossGroup, workerGroup)
.channel(NioServerSocketChannel.class)
.option(ChannelOption.SO_BACKLOG, 1024)
.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, 1000)
.childHandler(new SocksServerInitializer(config));
log.info("Socks5 server bind port: {}", port);
b.bind(port).sync().channel().closeFuture().sync();
} finally {
bossGroup.shutdownGracefully();
workerGroup.shutdownGracefully();
}
}
示例2: run
import io.netty.channel.EventLoopGroup; //导入方法依赖的package包/类
public void run() {
try {
// Configure the server.
EventLoopGroup group = new NioEventLoopGroup();
try {
ServerBootstrap b = new ServerBootstrap();
b.option(ChannelOption.SO_BACKLOG, 1024);
b.group(group)
.channel(NioServerSocketChannel.class)
.handler(new LoggingHandler(LogLevel.INFO))
.childHandler(new Http2ServerInitializer(mSslCtx));
sServerChannel = b.bind(PORT).sync().channel();
Log.i(TAG, "Netty HTTP/2 server started on " + getServerUrl());
sBlock.open();
sServerChannel.closeFuture().sync();
} finally {
group.shutdownGracefully();
}
Log.i(TAG, "Stopped Http2TestServerRunnable!");
} catch (Exception e) {
Log.e(TAG, e.toString());
}
}
示例3: start
import io.netty.channel.EventLoopGroup; //导入方法依赖的package包/类
public void start() throws InterruptedException {
EventLoopGroup acceptors = new NioEventLoopGroup(socksProperties.getAcceptors());
EventLoopGroup workers = new NioEventLoopGroup();
EventLoopGroup forwarders = new NioEventLoopGroup();
try {
ServerBootstrap bootstrap = new ServerBootstrap();
bootstrap.group(acceptors, workers)
.channel(NioServerSocketChannel.class)
.option(ChannelOption.SO_BACKLOG, socksProperties.getBacklog())
.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, socksProperties.getConnectTimeoutMillis())
.childHandler(new Socks5WorkerChannelInitializer(socksProperties, forwarders));
Address address = socksProperties.getListen();
ChannelFuture future = bootstrap.bind(address.getHost(), address.getPort()).sync();
future.channel().closeFuture().sync();
} finally {
forwarders.shutdownGracefully();
workers.shutdownGracefully();
acceptors.shutdownGracefully();
}
}
示例4: run
import io.netty.channel.EventLoopGroup; //导入方法依赖的package包/类
/**
* Start the server
*
* @param port The port on which the server listen to
*/
public void run(final int port) {
final EventLoopGroup bossGroup = new NioEventLoopGroup();
final EventLoopGroup workerGroup = new NioEventLoopGroup();
try {
final ServerBootstrap bootstrap = new ServerBootstrap()
.group(bossGroup, workerGroup)
.channel(NioServerSocketChannel.class)
.childHandler(new ServerInitializer())
.childOption(ChannelOption.SO_KEEPALIVE, true)
.childOption(ChannelOption.TCP_NODELAY, true);
final ChannelFuture f = bootstrap.bind(port).sync();
LOGGER.info("NettyServer: running on port {}", port);
f.channel().closeFuture().sync();
} catch (final InterruptedException e) {
LOGGER.error("NettyServer: an error occurred while running: {}", e.getMessage());
} finally {
bossGroup.shutdownGracefully();
workerGroup.shutdownGracefully();
}
}
示例5: bind
import io.netty.channel.EventLoopGroup; //导入方法依赖的package包/类
/**
*@description 监听指定端口
*@time 创建时间:2017年7月21日下午3:50:26
*@param port
*@throws InterruptedException
*@author dzn
*/
public void bind(int port) throws InterruptedException{
EventLoopGroup bossGroup = new NioEventLoopGroup();
EventLoopGroup workGroup = new NioEventLoopGroup();
try{
ServerBootstrap server = new ServerBootstrap();
server.group(bossGroup, workGroup)
.channel(NioServerSocketChannel.class)
.option(ChannelOption.SO_BACKLOG, 1024)
.childHandler(new ChildChannelHandler());
ChannelFuture cf = server.bind(port).sync();
System.out.println("服务器已启动, 监控端口号为 : " + port);
cf.channel().closeFuture().sync();
}finally{
bossGroup.shutdownGracefully();
workGroup.shutdownGracefully();
}
}
示例6: bind
import io.netty.channel.EventLoopGroup; //导入方法依赖的package包/类
/**
*@description 监听指定端口
*@time 创建时间:2017年7月21日下午3:50:26
*@param port
*@throws InterruptedException
*@author dzn
*/
public void bind(int port) throws InterruptedException{
//分配任务线程池
EventLoopGroup bossGroup = new NioEventLoopGroup();
//执行任务线程池
EventLoopGroup workGroup = new NioEventLoopGroup();
try{
//netty Server端
ServerBootstrap server = new ServerBootstrap();
server.group(bossGroup, workGroup)
.channel(NioServerSocketChannel.class)
.option(ChannelOption.SO_BACKLOG, 1024)
.childHandler(new ChildChannelHandler());
//启动netty服务器
ChannelFuture cf = server.bind(port).sync();
System.out.println("服务器已启动, 监控端口号为 : " + port);
//等待服务器端关闭
cf.channel().closeFuture().sync();
}finally{
bossGroup.shutdownGracefully();
workGroup.shutdownGracefully();
}
}
示例7: testTryWithResourcesShouldCloseAllClustersButNotEventLoopIfProvided
import io.netty.channel.EventLoopGroup; //导入方法依赖的package包/类
@Test
public void testTryWithResourcesShouldCloseAllClustersButNotEventLoopIfProvided()
throws Exception {
EventLoopGroup eventLoop = new DefaultEventLoopGroup();
BoundCluster cluster;
MockClient client;
try (Server server =
Server.builder()
.withAddressResolver(localAddressResolver)
.withEventLoopGroup(eventLoop, LocalServerChannel.class)
.build()) {
cluster = server.register(ClusterSpec.builder().withNodes(5));
BoundNode node = cluster.node(0);
SocketAddress address = node.getAddress();
client = new MockClient(eventLoop);
client.connect(address);
}
// event loop should not have been closed.
assertThat(eventLoop.isShutdown()).isFalse();
// timer should have since a custom one was not provided.
try {
cluster
.getServer()
.timer
.newTimeout(
timeout -> {
// noop
},
1,
TimeUnit.SECONDS);
fail("Expected IllegalStateException");
} catch (IllegalStateException ise) {
// expected
}
eventLoop.shutdownGracefully(0, 0, TimeUnit.SECONDS);
}
示例8: main
import io.netty.channel.EventLoopGroup; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
// Configure the server.
EventLoopGroup group = new NioEventLoopGroup();
try {
UkcpServerBootstrap b = new UkcpServerBootstrap();
b.group(group)
.channel(UkcpServerChannel.class)
.childHandler(new ChannelInitializer<UkcpChannel>() {
@Override
public void initChannel(UkcpChannel ch) throws Exception {
ChannelPipeline p = ch.pipeline();
p.addLast(new KcpRttServerHandler());
}
});
ChannelOptionHelper.nodelay(b, true, 20, 2, true)
.childOption(UkcpChannelOption.UKCP_MTU, 512);
// Start the server.
ChannelFuture f = b.bind(PORT).sync();
// Wait until the server socket is closed.
f.channel().closeFuture().sync();
} finally {
// Shut down all event loops to terminate all threads.
group.shutdownGracefully();
}
}
示例9: main
import io.netty.channel.EventLoopGroup; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
// Configure the server.
EventLoopGroup group = new NioEventLoopGroup();
try {
UkcpServerBootstrap b = new UkcpServerBootstrap();
b.group(group)
.channel(UkcpServerChannel.class)
.childHandler(new ChannelInitializer<UkcpChannel>() {
@Override
public void initChannel(UkcpChannel ch) throws Exception {
ChannelPipeline p = ch.pipeline();
p.addLast(new EchoServerHandler());
}
});
ChannelOptionHelper.nodelay(b, true, 20, 2, true)
.childOption(UkcpChannelOption.UKCP_MTU, 512);
// Start the server.
ChannelFuture f = b.bind(PORT).sync();
// Wait until the server socket is closed.
f.channel().closeFuture().sync();
} finally {
// Shut down all event loops to terminate all threads.
group.shutdownGracefully();
}
}
示例10: start
import io.netty.channel.EventLoopGroup; //导入方法依赖的package包/类
public void start() throws Exception {
// Configure SSL.
final SslContext sslCtx;
if (SSL) {
SelfSignedCertificate ssc = new SelfSignedCertificate();
sslCtx = SslContextBuilder.forServer(ssc.certificate(), ssc.privateKey()).build();
} else {
sslCtx = null;
}
// Configure the server.
EventLoopGroup bossGroup = new NioEventLoopGroup(1);
EventLoopGroup workerGroup = new NioEventLoopGroup();
try {
ServerBootstrap b = new ServerBootstrap();
b.group(bossGroup, workerGroup).channel(NioServerSocketChannel.class).option(ChannelOption.SO_BACKLOG, 100)
.handler(new LoggingHandler(LogLevel.INFO)).childHandler(new FileServerHandlerInitializer());
// Start the server.
ChannelFuture f = b.bind(getHostAddress(), PORT).sync();
// System.out.println("server is started "+f.isSuccess());
setStarted(true);
// Wait until the server socket is closed.
f.channel().closeFuture().sync();
} finally {
// Shut down all event loops to terminate all threads.
bossGroup.shutdownGracefully();
workerGroup.shutdownGracefully();
}
}
示例11: start
import io.netty.channel.EventLoopGroup; //导入方法依赖的package包/类
public void start() {
Configuration config = Configuration.INSTANCE;
InternalLoggerFactory.setDefaultFactory(Slf4JLoggerFactory.INSTANCE);
EventLoopGroup bossGroup = new NioEventLoopGroup(1);
EventLoopGroup workerGroup = new NioEventLoopGroup();
try {
ServerBootstrap bootstrap = new ServerBootstrap();
bootstrap.group(bossGroup, workerGroup)
.channel(NioServerSocketChannel.class)
.childHandler(new ChannelInitializer<SocketChannel>() {
protected void initChannel(SocketChannel socketChannel) throws Exception {
socketChannel.pipeline()
.addLast("logging", new LoggingHandler(LogLevel.DEBUG))
.addLast(new XConnectHandler());
if (config.getReadLimit() != 0 || config.getWriteLimit() != 0) {
socketChannel.pipeline().addLast(
new GlobalTrafficShapingHandler(Executors.newScheduledThreadPool(1), config.getWriteLimit(), config.getReadLimit())
);
}
}
});
log.info("\tStartup {}-{}-server [{}]", Constants.APP_NAME, Constants.APP_VERSION, config.getProtocol());
new Thread(() -> new UdpServer().start()).start();
ChannelFuture future = bootstrap.bind(config.getHost(), config.getPort()).sync();
future.addListener(future1 -> log.info("\tTCP listening at {}:{}...", config.getHost(), config.getPort()));
future.channel().closeFuture().sync();
} catch (Exception e) {
log.error("\tSocket bind failure ({})", e.getMessage());
} finally {
log.info("\tShutting down and recycling...");
bossGroup.shutdownGracefully();
workerGroup.shutdownGracefully();
Configuration.shutdownRelays();
}
System.exit(0);
}
示例12: main
import io.netty.channel.EventLoopGroup; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
// Configure SSL.git
final SslContext sslCtx;
if (SSL) {
sslCtx = SslContextBuilder.forClient()
.trustManager(InsecureTrustManagerFactory.INSTANCE).build();
} else {
sslCtx = null;
}
// Configure the client.
EventLoopGroup group = new NioEventLoopGroup();
try {
Bootstrap b = new Bootstrap();
b.group(group)
.channel(NioSocketChannel.class)
.option(ChannelOption.TCP_NODELAY, true)
.handler(new ChannelInitializer<SocketChannel>() {
@Override
public void initChannel(SocketChannel ch) throws Exception {
ChannelPipeline p = ch.pipeline();
if (sslCtx != null) {
p.addLast(sslCtx.newHandler(ch.alloc(), HOST, PORT));
}
// p.addLast(new LoggingHandler(LogLevel.INFO));
p.addLast(new EchoClientHandler());
}
});
// Start the client.
ChannelFuture f = b.connect(HOST, PORT).sync();
// Wait until the connection is closed.
f.channel().closeFuture().sync();
} finally {
// Shut down the event loop to terminate all threads.
group.shutdownGracefully();
}
}
示例13: main
import io.netty.channel.EventLoopGroup; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
// Configure SSL.
//final SslContext sslCtx;
ConfigurationManager.getConfigInstance().setProperty("app.localLog.path","E:\\Tools\\apache-tomcat-7.0.68\\logs");
// Configure the server.
EventLoopGroup bossGroup = new NioEventLoopGroup(1);
EventLoopGroup workerGroup = new NioEventLoopGroup();
try {
ServerBootstrap b = new ServerBootstrap();
b.option(ChannelOption.SO_BACKLOG, 1024);
b.group(bossGroup, workerGroup)
.channel(NioServerSocketChannel.class)
.handler(new LoggingHandler(LogLevel.INFO))
.childHandler(new HttpHelloWorldServerInitializer());
Channel ch = b.bind(PORT).sync().channel();
System.err.println("Open your web browser and navigate to " +
(SSL? "https" : "http") + "://127.0.0.1:" + PORT + '/');
ch.closeFuture().sync();
} finally {
bossGroup.shutdownGracefully();
workerGroup.shutdownGracefully();
}
}
示例14: main
import io.netty.channel.EventLoopGroup; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
// Configure SSL.
final SslContext sslCtx;
if (SSL) {
SelfSignedCertificate ssc = new SelfSignedCertificate();
sslCtx = SslContextBuilder.forServer(ssc.certificate(), ssc.privateKey()).build();
} else {
sslCtx = null;
}
// Configure the server.
EventLoopGroup bossGroup = new NioEventLoopGroup(1);
EventLoopGroup workerGroup = new NioEventLoopGroup();
try {
ServerBootstrap b = new ServerBootstrap();
b.option(ChannelOption.SO_BACKLOG, 1024);
b.group(bossGroup, workerGroup)
.channel(NioServerSocketChannel.class)
.handler(new LoggingHandler(LogLevel.INFO))
.childHandler(new HttpHelloWorldServerInitializer(sslCtx));
Channel ch = b.bind(PORT).sync().channel();
System.err.println("Open your web browser and navigate to " +
(SSL? "https" : "http") + "://127.0.0.1:" + PORT + '/');
ch.closeFuture().sync();
} finally {
bossGroup.shutdownGracefully();
workerGroup.shutdownGracefully();
}
}
示例15: main
import io.netty.channel.EventLoopGroup; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
// Configure the client.
EventLoopGroup group = new NioEventLoopGroup();
try {
Bootstrap b = new Bootstrap();
b.group(group)
.channel(UkcpClientChannel.class)
.handler(new ChannelInitializer<UkcpChannel>() {
@Override
public void initChannel(UkcpChannel ch) throws Exception {
ChannelPipeline p = ch.pipeline();
p.addLast(new KcpRttClientHandler(COUNT));
}
});
ChannelOptionHelper.nodelay(b, true, 20, 2, true)
.option(UkcpChannelOption.UKCP_MTU, 512);
// Start the client.
ChannelFuture f = b.connect(HOST, PORT).sync();
// Wait until the connection is closed.
f.channel().closeFuture().sync();
} finally {
// Shut down the event loop to terminate all threads.
group.shutdownGracefully();
}
}