1 package org.opendaylight.controller.sal.streams.websockets;
3 import io.netty.bootstrap.ServerBootstrap;
4 import io.netty.channel.Channel;
5 import io.netty.channel.EventLoopGroup;
6 import io.netty.channel.nio.NioEventLoopGroup;
7 import io.netty.channel.socket.nio.NioServerSocketChannel;
9 import org.opendaylight.controller.sal.streams.listeners.Notificator;
10 import org.slf4j.Logger;
11 import org.slf4j.LoggerFactory;
14 * {@link WebSocketServer} is responsible to start and stop web socket server at
17 public class WebSocketServer implements Runnable {
19 private static final Logger logger = LoggerFactory
20 .getLogger(WebSocketServer.class);
22 public static final int PORT = 8181;
23 private EventLoopGroup bossGroup;
24 private EventLoopGroup workerGroup;
28 bossGroup = new NioEventLoopGroup();
29 workerGroup = new NioEventLoopGroup();
31 ServerBootstrap b = new ServerBootstrap();
32 b.group(bossGroup, workerGroup)
33 .channel(NioServerSocketChannel.class)
34 .childHandler(new WebSocketServerInitializer());
36 Channel ch = b.bind(PORT).sync().channel();
37 logger.info("Web socket server started at port {}.", PORT);
39 ch.closeFuture().sync();
40 } catch (InterruptedException e) {
48 * Stops the web socket server and removes all listeners.
51 Notificator.removeAllListeners();
52 if (bossGroup != null) {
53 bossGroup.shutdownGracefully();
55 if (workerGroup != null) {
56 workerGroup.shutdownGracefully();