1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.waarp.commandexec.server;
21
22 import io.netty.bootstrap.ServerBootstrap;
23 import io.netty.channel.ChannelFuture;
24 import io.netty.channel.EventLoopGroup;
25 import io.netty.channel.nio.NioEventLoopGroup;
26 import io.netty.util.concurrent.DefaultEventExecutorGroup;
27 import io.netty.util.concurrent.EventExecutorGroup;
28 import org.waarp.commandexec.utils.LocalExecDefaultResult;
29 import org.waarp.common.logging.WaarpLoggerFactory;
30 import org.waarp.common.logging.WaarpSlf4JLoggerFactory;
31 import org.waarp.common.utility.DetectionUtils;
32 import org.waarp.common.utility.WaarpNettyUtil;
33 import org.waarp.common.utility.WaarpThreadFactory;
34
35 import java.net.InetAddress;
36 import java.net.InetSocketAddress;
37
38
39
40
41 public class LocalExecServer {
42
43 static final EventLoopGroup workerGroup = new NioEventLoopGroup();
44 static final EventExecutorGroup executor =
45 new DefaultEventExecutorGroup(DetectionUtils.numberThreads(),
46 new WaarpThreadFactory("LocalExecServer"));
47
48
49
50
51
52
53
54
55
56
57
58
59 public static void main(final String[] args) throws Exception {
60 WaarpLoggerFactory.setDefaultFactoryIfNotSame(
61 new WaarpSlf4JLoggerFactory(null));
62 int port = 9999;
63 final InetAddress addr;
64 long delay = LocalExecDefaultResult.MAXWAITPROCESS;
65 if (args.length >= 2) {
66 addr = InetAddress.getByName(args[0]);
67 port = Integer.parseInt(args[1]);
68 if (args.length > 2) {
69 delay = Long.parseLong(args[2]);
70 }
71 } else {
72 final byte[] loop = { 127, 0, 0, 1 };
73 addr = InetAddress.getByAddress(loop);
74 }
75
76 try {
77 final ServerBootstrap bootstrap = new ServerBootstrap();
78 WaarpNettyUtil.setServerBootstrap(bootstrap, workerGroup, workerGroup,
79 30000);
80
81
82 bootstrap.childHandler(new LocalExecServerInitializer(delay, executor));
83
84
85 final ChannelFuture future =
86 bootstrap.bind(new InetSocketAddress(addr, port));
87
88
89 future.channel().closeFuture().sync();
90 } finally {
91
92 workerGroup.shutdownGracefully();
93
94
95 workerGroup.terminationFuture().sync();
96 }
97 }
98 }