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;
22 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.RpcRegistration;
23 import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.websocketmanager.rev150105.WebsocketmanagerService;
25 import org.osgi.service.http.HttpService;
26 import org.osgi.service.http.NamespaceException;
27 import org.slf4j.Logger;
28 import org.slf4j.LoggerFactory;
30 public class WebSocketManagerProvider extends Blueprint {
32 private static final Logger LOG = LoggerFactory.getLogger(WebSocketManagerProvider.class);
33 private static final String APPLICATION_NAME = WebSocketManagerProvider.class.getName();
34 private static final String ALIAS = "/websocket";
36 private WebSocketManager wsServlet = null;
37 private RpcRegistration<WebsocketmanagerService> websocketService = null;
39 public WebSocketManagerProvider() {
40 LOG.info("Creating provider for {}", APPLICATION_NAME);
45 LOG.info("Init provider for {}", APPLICATION_NAME);
46 RpcProviderRegistry rpcProviderRegistry = this.getRpcProviderRegistry();
47 if (rpcProviderRegistry != null) {
48 if (wsServlet != null) {
49 this.websocketService = rpcProviderRegistry.addRpcImplementation(WebsocketmanagerService.class,
52 LOG.error("wsServlet not 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 wsServlet = new WebSocketManager();
78 httpService.registerServlet(ALIAS, wsServlet, null, null);
79 LOG.info("websocket servlet registered.");
80 if(this.websocketService==null)
83 LOG.info("websocketservice already initialized");
88 public WebSocketManager getWsServlet() {
92 public void setWsServlet(WebSocketManager wsServlet) {
93 this.wsServlet = wsServlet;