1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.jboss.netty.example.factorial;
17
18 import org.jboss.netty.bootstrap.ServerBootstrap;
19 import org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory;
20 import org.jboss.netty.handler.ssl.SslContext;
21 import org.jboss.netty.handler.ssl.util.SelfSignedCertificate;
22
23 import java.net.InetSocketAddress;
24 import java.util.concurrent.Executors;
25
26
27
28
29
30 public final class FactorialServer {
31
32 static final boolean SSL = System.getProperty("ssl") != null;
33 static final int PORT = Integer.parseInt(System.getProperty("port", "8322"));
34
35 public static void main(String[] args) throws Exception {
36
37 final SslContext sslCtx;
38 if (SSL) {
39 SelfSignedCertificate ssc = new SelfSignedCertificate();
40 sslCtx = SslContext.newServerContext(ssc.certificate(), ssc.privateKey());
41 } else {
42 sslCtx = null;
43 }
44
45
46 ServerBootstrap bootstrap = new ServerBootstrap(
47 new NioServerSocketChannelFactory(
48 Executors.newCachedThreadPool(),
49 Executors.newCachedThreadPool()));
50
51
52 bootstrap.setPipelineFactory(new FactorialServerPipelineFactory(sslCtx));
53
54
55 bootstrap.bind(new InetSocketAddress(PORT));
56 }
57 }