2 * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
9 package org.opendaylight.restconf.nb.rfc8040;
11 import com.google.common.base.Preconditions;
12 import org.opendaylight.controller.md.sal.dom.api.DOMDataBroker;
13 import org.opendaylight.controller.md.sal.dom.api.DOMNotificationService;
14 import org.opendaylight.controller.md.sal.dom.api.DOMRpcService;
15 import org.opendaylight.mdsal.dom.api.DOMSchemaService;
16 import org.opendaylight.restconf.nb.rfc8040.handlers.DOMDataBrokerHandler;
17 import org.opendaylight.restconf.nb.rfc8040.handlers.DOMMountPointServiceHandler;
18 import org.opendaylight.restconf.nb.rfc8040.handlers.NotificationServiceHandler;
19 import org.opendaylight.restconf.nb.rfc8040.handlers.RpcServiceHandler;
20 import org.opendaylight.restconf.nb.rfc8040.handlers.SchemaContextHandler;
21 import org.opendaylight.restconf.nb.rfc8040.handlers.TransactionChainHandler;
22 import org.opendaylight.restconf.nb.rfc8040.services.wrapper.ServiceWrapper;
23 import org.slf4j.Logger;
24 import org.slf4j.LoggerFactory;
27 * Provider for restconf draft18.
30 public class RestConnectorProvider<T extends ServiceWrapper> implements RestconfConnector, AutoCloseable {
32 private static final Logger LOG = LoggerFactory.getLogger(RestConnectorProvider.class);
34 private final DOMRpcService rpcService;
35 private final DOMNotificationService notificationService;
36 private final DOMSchemaService domSchemaService;
37 private final TransactionChainHandler transactionChainHandler;
38 private final DOMDataBroker dataBroker;
39 private final SchemaContextHandler schemaCtxHandler;
40 private final DOMMountPointServiceHandler mountPointServiceHandler;
41 private final T wrapperServices;
43 public RestConnectorProvider(final DOMDataBroker domDataBroker, final DOMSchemaService domSchemaService,
44 final DOMRpcService rpcService, final DOMNotificationService notificationService,
45 final TransactionChainHandler transactionChainHandler,
46 final SchemaContextHandler schemaCtxHandler, final DOMMountPointServiceHandler mountPointServiceHandler,
47 final T wrapperServices) {
48 this.wrapperServices = wrapperServices;
49 this.domSchemaService = Preconditions.checkNotNull(domSchemaService);
50 this.rpcService = Preconditions.checkNotNull(rpcService);
51 this.notificationService = Preconditions.checkNotNull(notificationService);
52 this.transactionChainHandler = Preconditions.checkNotNull(transactionChainHandler);
53 this.dataBroker = Preconditions.checkNotNull(domDataBroker);
54 this.schemaCtxHandler = Preconditions.checkNotNull(schemaCtxHandler);
55 this.mountPointServiceHandler = Preconditions.checkNotNull(mountPointServiceHandler);
58 public synchronized void start() {
59 final DOMDataBrokerHandler brokerHandler = new DOMDataBrokerHandler(dataBroker);
61 final RpcServiceHandler rpcServiceHandler = new RpcServiceHandler(rpcService);
63 final NotificationServiceHandler notificationServiceHandler =
64 new NotificationServiceHandler(notificationService);
66 if (wrapperServices != null) {
67 wrapperServices.setHandlers(this.schemaCtxHandler, mountPointServiceHandler,
68 transactionChainHandler, brokerHandler, rpcServiceHandler,
69 notificationServiceHandler, domSchemaService);