4 package org.opendaylight.mwtn.devicemanager.impl.xml;
6 import java.util.concurrent.Future;
8 import org.opendaylight.mwtn.devicemanager.impl.listener.ODLEventListener;
9 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.websocketmanager.rev150105.WebsocketEventInputBuilder;
10 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.websocketmanager.rev150105.WebsocketEventOutput;
11 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.websocketmanager.rev150105.WebsocketmanagerService;
12 import org.opendaylight.yangtools.yang.common.RpcResult;
13 import org.slf4j.Logger;
14 import org.slf4j.LoggerFactory;
17 * Wrapper for forwarding websocket notifications to the websocket service, that is running as container.
20 public class WebSocketServiceClient {
22 private static final Logger LOG = LoggerFactory.getLogger(ODLEventListener.class);
24 private final WebsocketmanagerService websocketmanagerService;
25 private final XmlMapper xmlMapper;
28 * @param websocketmanagerService object
29 * @param xmlMapper object
31 public WebSocketServiceClient(WebsocketmanagerService websocketmanagerService,
32 XmlMapper xmlMapper) {
34 this.websocketmanagerService = websocketmanagerService;
35 this.xmlMapper = xmlMapper;
38 public <T extends MwtNotificationBase & GetEventType> void sendViaWebsockets(String nodeName, T notificationXml) {
39 LOG.info("Send websocket event {} for mountpoint {}", notificationXml.getClass().getSimpleName(), nodeName);
42 WebsocketEventInputBuilder wsBuilder = new WebsocketEventInputBuilder();
43 wsBuilder.setNodeName(nodeName);
44 wsBuilder.setEventType(notificationXml.getEventType());
45 wsBuilder.setXmlEvent(xmlMapper.getXmlString(notificationXml));
46 Future<RpcResult<WebsocketEventOutput>> result = websocketmanagerService.websocketEvent(wsBuilder.build());
47 LOG.info("Send websocket result: {}", result.get().getResult().getResponse());
48 } catch (Exception e) {
49 LOG.warn("Can not send websocket event {} for mountpoint {} {}",
50 notificationXml.getClass().getSimpleName(), nodeName, e.toString());