--- /dev/null
+/*
+ * 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.ProviderSession;
+import org.opendaylight.controller.sal.core.api.Provider;
+import org.opendaylight.controller.sal.core.api.data.DataBrokerService;
+import org.opendaylight.controller.sal.core.api.model.SchemaService;
+import org.opendaylight.controller.sal.core.api.mount.MountService;
+import org.opendaylight.controller.sal.rest.api.RestConnector;
+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.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.PortNumber;
+import org.opendaylight.yangtools.concepts.ListenerRegistration;
+import org.opendaylight.yangtools.yang.model.api.SchemaServiceListener;
+
+public class RestconfProviderImpl implements Provider, AutoCloseable, RestConnector {
+
+ public final static String NOT_INITALIZED_MSG = "Restconf is not initialized yet. Please try again later";
+
+ private ListenerRegistration<SchemaServiceListener> listenerRegistration;
+ private PortNumber port;
+ public void setWebsocketPort(PortNumber port) {
+ this.port = port;
+ }
+
+ private Thread webSocketServerThread;
+
+ @Override
+ public void onSessionInitiated(ProviderSession session) {
+ DataBrokerService dataService = session.getService(DataBrokerService.class);
+
+ BrokerFacade.getInstance().setContext(session);
+ BrokerFacade.getInstance().setDataService(dataService);
+
+ SchemaService schemaService = session.getService(SchemaService.class);
+ listenerRegistration = schemaService.registerSchemaServiceListener(ControllerContext.getInstance());
+ ControllerContext.getInstance().setSchemas(schemaService.getGlobalContext());
+ ControllerContext.getInstance().setMountService(session.getService(MountService.class));
+
+ webSocketServerThread = new Thread(WebSocketServer.createInstance(port.getValue().intValue()));
+ webSocketServerThread.setName("Web socket server on port " + port);
+ webSocketServerThread.start();
+ }
+
+ @Override
+ public Collection<ProviderFunctionality> getProviderFunctionality() {
+ return Collections.emptySet();
+ }
+
+ @Override
+ public void close() {
+ if (listenerRegistration != null) {
+ listenerRegistration.close();
+ }
+ webSocketServerThread.interrupt();
+ }
+}