class ControlWebsocketHandler {

	public void handle(ChannelHandlerContext ctx, HttpRequest req) {
		try {
			LoggingService.logDebug(MODULE_NAME, "Open the websocket for the real-time control signals");
			String uri = req.uri();
			uri = uri.substring(1);
			String[] tokens = uri.split("/");

			String id;

			if (tokens.length < 5) {
				LoggingService.logError(MODULE_NAME, " Missing ID or ID value in URL ",
						new AgentSystemException(" Missing ID or ID value in URL"));
				return;
			} else {
				id = tokens[4].trim();
			}

			// Handshake
			WebSocketServerHandshakerFactory wsFactory = new WebSocketServerHandshakerFactory(getWebSocketLocation(req),
					null, true, Integer.MAX_VALUE);
			WebSocketServerHandshaker handshaker = wsFactory.newHandshaker(req);
			if (handshaker == null) {
				WebSocketServerHandshakerFactory.sendUnsupportedVersionResponse(ctx.channel());
			} else {
				handshaker.handshake(ctx.channel(), req);
			}

			WebSocketMap.addWebsocket('C', id, ctx);
			StatusReporter.setLocalApiStatus().setOpenConfigSocketsCount(WebSocketMap.controlWebsocketMap.size());
			LoggingService.logDebug(MODULE_NAME, "Websocket for the real-time control signals is open");
		} catch (Exception e) {
			LoggingService.logError(MODULE_NAME, "Error in Handler to open the websocket for the real-time control signals",
					new AgentSystemException("Error in Handler to open the websocket for the real-time control signals"));
		}
	}

}