2 * ============LICENSE_START========================================================================
3 * ONAP : ccsdk feature sdnr wt
4 * =================================================================================================
5 * Copyright (C) 2019 highstreet technologies GmbH Intellectual Property. All rights reserved.
6 * =================================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
8 * in compliance with the License. You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software distributed under the License
13 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
14 * or implied. See the License for the specific language governing permissions and limitations under
16 * ============LICENSE_END==========================================================================
18 package org.onap.ccsdk.features.sdnr.wt.websocketmanager;
20 import java.time.Instant;
21 import javax.servlet.ServletException;
22 import org.onap.ccsdk.features.sdnr.wt.websocketmanager.model.WebsocketManagerService;
23 import org.onap.ccsdk.features.sdnr.wt.websocketmanager.model.data.NotificationOutput;
24 import org.onap.ccsdk.features.sdnr.wt.yang.mapper.YangToolsMapperHelper;
25 import org.opendaylight.mdsal.dom.api.DOMNotification;
26 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.DateAndTime;
27 import org.opendaylight.yangtools.yang.binding.Notification;
28 import org.opendaylight.yangtools.yang.common.QName;
29 import org.osgi.service.http.HttpService;
30 import org.osgi.service.http.NamespaceException;
31 import org.slf4j.Logger;
32 import org.slf4j.LoggerFactory;
34 public class WebSocketManagerProvider implements WebsocketManagerService, AutoCloseable {
36 private static final Logger LOG = LoggerFactory.getLogger(WebSocketManagerProvider.class);
37 private static final String APPLICATION_NAME = WebSocketManagerProvider.class.getName();
38 private static final String ALIAS = "/websocket";
40 private WebSocketManager wsServlet = null;
42 public WebSocketManagerProvider() {
43 LOG.info("Creating provider for {}", APPLICATION_NAME);
48 LOG.info("Init provider for {}", APPLICATION_NAME);
52 public void close() throws Exception {
53 LOG.info("Close provider for {}", APPLICATION_NAME);
56 public void onUnbindService(HttpService httpService) {
57 httpService.unregister(ALIAS);
61 public void onBindService(HttpService httpService) throws ServletException, NamespaceException {
62 if (httpService == null) {
63 LOG.warn("Unable to inject HttpService into DluxLoader. dlux modules won't work without httpService");
66 if (wsServlet == null) {
67 wsServlet = new WebSocketManager();
68 httpService.registerServlet(ALIAS, wsServlet, null, null);
69 LOG.info("websocket servlet registered.");
77 public WebSocketManager getWsServlet() {
81 public void setWsServlet(WebSocketManager wsServlet) {
82 this.wsServlet = wsServlet;
87 public void sendNotification(Notification notification, String nodeId, QName eventType) {
88 this.sendNotification(notification, nodeId, eventType, YangToolsMapperHelper.getTime(notification,Instant.now()));
92 public void sendNotification(Notification notification, String nodeId, QName eventType, DateAndTime eventTime) {
93 WebSocketManagerSocket.broadCast(new NotificationOutput(notification, nodeId, eventType, eventTime));
98 public void sendNotification(DOMNotification notification, String nodeId, QName eventType) {
99 LOG.warn("not yet implemented");
104 public void sendNotification(DOMNotification notification, String nodeId, QName eventType, DateAndTime eventTime) {
105 LOG.warn("not yet implemented");