1 /*******************************************************************************
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==========================================================================
17 ******************************************************************************/
18 package org.onap.ccsdk.features.sdnr.wt.websocketmanager2;
20 import javax.servlet.ServletException;
21 import org.opendaylight.mdsal.binding.api.RpcProviderService;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.websocketmanager.rev150105.WebsocketmanagerService;
23 import org.opendaylight.yangtools.concepts.ObjectRegistration;
24 import org.osgi.service.http.HttpService;
25 import org.osgi.service.http.NamespaceException;
26 import org.slf4j.Logger;
27 import org.slf4j.LoggerFactory;
29 public class WebSocketManagerProvider extends Blueprint {
31 private static final Logger LOG = LoggerFactory.getLogger(WebSocketManagerProvider.class);
32 private static final String APPLICATION_NAME = WebSocketManagerProvider.class.getName();
33 private static final String ALIAS = "/websocket";
35 private WebSocketManager wsServlet = null;
36 private ObjectRegistration<WebSocketManager> websocketService = null;
38 public WebSocketManagerProvider() {
39 LOG.info("Creating provider for {}", APPLICATION_NAME);
44 LOG.info("Init provider for {}", APPLICATION_NAME);
45 RpcProviderService rpcProviderRegistry = this.getRpcProviderRegistry();
46 if (rpcProviderRegistry != null) {
47 if (wsServlet != null) {
48 this.websocketService =
49 rpcProviderRegistry.registerRpcImplementation(WebsocketmanagerService.class, wsServlet);
50 LOG.info("websocketservice initialized");
52 LOG.debug("wsServlet not yet provided");
55 LOG.error("rpcProviderRegistry not provided");
60 public void close() throws Exception {
61 LOG.info("Close provider for {}", APPLICATION_NAME);
62 if (websocketService != null) {
63 websocketService.close();
67 public void onUnbindService(HttpService httpService) {
68 httpService.unregister(ALIAS);
72 public void onBindService(HttpService httpService) throws ServletException, NamespaceException {
73 if (httpService == null) {
74 LOG.warn("Unable to inject HttpService into DluxLoader. dlux modules won't work without httpService");
77 if (wsServlet == null) {
78 wsServlet = new WebSocketManager();
79 httpService.registerServlet(ALIAS, wsServlet, null, null);
80 LOG.info("websocket servlet registered.");
81 if (this.websocketService == null) {
84 LOG.info("websocketservice already initialized");
93 public WebSocketManager getWsServlet() {
97 public void setWsServlet(WebSocketManager wsServlet) {
98 this.wsServlet = wsServlet;