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.ChannelPipeline;
10 import io.netty.channel.EventLoopGroup;
11 import io.netty.channel.nio.NioEventLoopGroup;
12 import io.netty.channel.socket.nio.NioServerSocketChannel;
15 * {@link WebSocketServer} is responsible to start and stop web socket server at
18 public class WebSocketServer implements Runnable {
20 private static final Logger logger = LoggerFactory
21 .getLogger(WebSocketServer.class);
23 public static final int PORT = 8181;
24 private EventLoopGroup bossGroup;
25 private EventLoopGroup workerGroup;
29 bossGroup = new NioEventLoopGroup();
30 workerGroup = new NioEventLoopGroup();
32 ServerBootstrap b = new ServerBootstrap();
33 b.group(bossGroup, workerGroup)
34 .channel(NioServerSocketChannel.class)
35 .childHandler(new WebSocketServerInitializer());
37 Channel ch = b.bind(PORT).sync().channel();
38 logger.info("Web socket server started at port {}.", PORT);
40 ch.closeFuture().sync();
41 } catch (InterruptedException e) {
49 * Stops the web socket server and removes all listeners.
52 Notificator.removeAllListeners();
53 if (bossGroup != null) {
54 bossGroup.shutdownGracefully();
56 if (workerGroup != null) {
57 workerGroup.shutdownGracefully();