1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.jboss.netty.example.http.tunnel;
17
18 import org.jboss.netty.bootstrap.ServerBootstrap;
19 import org.jboss.netty.channel.Channel;
20 import org.jboss.netty.channel.ChannelFactory;
21 import org.jboss.netty.channel.local.DefaultLocalServerChannelFactory;
22 import org.jboss.netty.channel.local.LocalAddress;
23 import org.jboss.netty.example.echo.EchoServerHandler;
24
25
26
27
28
29
30
31
32
33 public class LocalEchoServerRegistration {
34
35 private final ChannelFactory factory = new DefaultLocalServerChannelFactory();
36 private volatile Channel serverChannel;
37
38 public void start() {
39 ServerBootstrap serverBootstrap = new ServerBootstrap(factory);
40 EchoServerHandler handler = new EchoServerHandler();
41 serverBootstrap.getPipeline().addLast("handler", handler);
42
43
44 serverChannel = serverBootstrap.bind(new LocalAddress("myLocalServer"));
45 }
46
47 public void stop() {
48 serverChannel.close();
49 }
50 }