1 package org.opendaylight.controller.sal.streams.websockets;
3 import org.opendaylight.controller.sal.streams.listeners.Notificator;
4 import org.slf4j.Logger;
5 import org.slf4j.LoggerFactory;
7 import io.netty.bootstrap.ServerBootstrap;
8 import io.netty.channel.Channel;
9 import io.netty.channel.EventLoopGroup;
10 import io.netty.channel.nio.NioEventLoopGroup;
11 import io.netty.channel.socket.nio.NioServerSocketChannel;
13 public class WebSocketServer implements Runnable {
15 private static final Logger logger = LoggerFactory.getLogger(WebSocketServer.class);
17 public static final int PORT = 8181;
18 private EventLoopGroup bossGroup;
19 private EventLoopGroup workerGroup;
23 bossGroup = new NioEventLoopGroup();
24 workerGroup = new NioEventLoopGroup();
26 ServerBootstrap b = new ServerBootstrap();
27 b.group(bossGroup, workerGroup)
28 .channel(NioServerSocketChannel.class)
29 .childHandler(new WebSocketServerInitializer());
31 Channel ch = b.bind(PORT).sync().channel();
32 logger.info("Web socket server started at port {}.", PORT);
34 ch.closeFuture().sync();
35 } catch (InterruptedException e) {
43 Notificator.removeAllListeners();
44 if (bossGroup != null) {
45 bossGroup.shutdownGracefully();
47 if (workerGroup != null) {
48 workerGroup.shutdownGracefully();