Apply style rules on whole sal-rest-connector
[controller.git] / opendaylight / md-sal / sal-rest-connector / src / main / java / org / opendaylight / controller / sal / rest / impl / RestconfProvider.java
index 09cf01091ed0deaa3c3ea5f86d35134d5ae89a84..1f1d0eb83147533d1171a4e81a36a73d7f72acd0 100644 (file)
@@ -1,8 +1,14 @@
+/*
+ * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
 package org.opendaylight.controller.sal.rest.impl;
 
 import java.util.Collection;
 import java.util.Collections;
-
 import org.opendaylight.controller.sal.core.api.Broker;
 import org.opendaylight.controller.sal.core.api.Broker.ProviderSession;
 import org.opendaylight.controller.sal.core.api.Provider;
@@ -11,6 +17,7 @@ import org.opendaylight.controller.sal.core.api.model.SchemaService;
 import org.opendaylight.controller.sal.core.api.mount.MountService;
 import org.opendaylight.controller.sal.restconf.impl.BrokerFacade;
 import org.opendaylight.controller.sal.restconf.impl.ControllerContext;
+import org.opendaylight.controller.sal.streams.websockets.WebSocketServer;
 import org.opendaylight.yangtools.concepts.ListenerRegistration;
 import org.opendaylight.yangtools.yang.model.api.SchemaServiceListener;
 import org.osgi.framework.BundleActivator;
@@ -26,7 +33,7 @@ public class RestconfProvider implements BundleActivator, Provider, ServiceTrack
     private ListenerRegistration<SchemaServiceListener> listenerRegistration;
     private ServiceTracker<Broker, Broker> brokerServiceTrancker;
     private BundleContext bundleContext;
-    private ProviderSession session;
+    private Thread webSocketServerThread;
 
     @Override
     public void onSessionInitiated(ProviderSession session) {
@@ -43,7 +50,13 @@ public class RestconfProvider implements BundleActivator, Provider, ServiceTrack
 
     @Override
     public void start(BundleContext context) throws Exception {
+        String websocketPortStr = context.getProperty(WebSocketServer.WEBSOCKET_SERVER_CONFIG_PROPERTY);
+        int websocketPort = (websocketPortStr != null && !"".equals(websocketPortStr)) ? Integer
+                .parseInt(websocketPortStr) : WebSocketServer.DEFAULT_PORT;
         bundleContext = context;
+        webSocketServerThread = new Thread(WebSocketServer.createInstance(websocketPort));
+        webSocketServerThread.setName("Web socket server");
+        webSocketServerThread.start();
         brokerServiceTrancker = new ServiceTracker<>(context, Broker.class, this);
         brokerServiceTrancker.open();
     }
@@ -57,7 +70,7 @@ public class RestconfProvider implements BundleActivator, Provider, ServiceTrack
                 e.printStackTrace();
             }
         }
-        session.close();
+        webSocketServerThread.interrupt();
         brokerServiceTrancker.close();
     }