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 edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
13 import org.opendaylight.controller.md.sal.dom.api.DOMDataBroker;
14 import org.opendaylight.controller.md.sal.dom.api.DOMMountPointService;
15 import org.opendaylight.controller.md.sal.dom.api.DOMNotificationService;
16 import org.opendaylight.controller.md.sal.dom.api.DOMRpcService;
17 import org.opendaylight.mdsal.dom.api.DOMSchemaService;
18 import org.opendaylight.restconf.nb.rfc8040.handlers.DOMDataBrokerHandler;
19 import org.opendaylight.restconf.nb.rfc8040.handlers.DOMMountPointServiceHandler;
20 import org.opendaylight.restconf.nb.rfc8040.handlers.NotificationServiceHandler;
21 import org.opendaylight.restconf.nb.rfc8040.handlers.RpcServiceHandler;
22 import org.opendaylight.restconf.nb.rfc8040.handlers.SchemaContextHandler;
23 import org.opendaylight.restconf.nb.rfc8040.handlers.TransactionChainHandler;
24 import org.opendaylight.restconf.nb.rfc8040.services.wrapper.ServiceWrapper;
25 import org.slf4j.Logger;
26 import org.slf4j.LoggerFactory;
29 * Provider for restconf draft18.
32 public class RestConnectorProvider<T extends ServiceWrapper> implements RestconfConnector, AutoCloseable {
34 private static final Logger LOG = LoggerFactory.getLogger(RestConnectorProvider.class);
36 @SuppressFBWarnings("ST_WRITE_TO_STATIC_FROM_INSTANCE_METHOD")
37 private static volatile DOMMountPointServiceHandler mountPointServiceHandler;
39 private final DOMRpcService rpcService;
40 private final DOMNotificationService notificationService;
41 private final DOMMountPointService mountPointService;
42 private final DOMSchemaService domSchemaService;
43 private final TransactionChainHandler transactionChainHandler;
44 private final DOMDataBroker dataBroker;
45 private final SchemaContextHandler schemaCtxHandler;
46 private final T wrapperServices;
48 public RestConnectorProvider(final DOMDataBroker domDataBroker, final DOMSchemaService domSchemaService,
49 final DOMRpcService rpcService, final DOMNotificationService notificationService,
50 final DOMMountPointService mountPointService, final TransactionChainHandler transactionChainHandler,
51 final SchemaContextHandler schemaCtxHandler, final T wrapperServices) {
52 this.wrapperServices = wrapperServices;
53 this.domSchemaService = Preconditions.checkNotNull(domSchemaService);
54 this.rpcService = Preconditions.checkNotNull(rpcService);
55 this.notificationService = Preconditions.checkNotNull(notificationService);
56 this.mountPointService = Preconditions.checkNotNull(mountPointService);
57 this.transactionChainHandler = Preconditions.checkNotNull(transactionChainHandler);
58 this.dataBroker = Preconditions.checkNotNull(domDataBroker);
59 this.schemaCtxHandler = Preconditions.checkNotNull(schemaCtxHandler);
62 public synchronized void start() {
63 mountPointServiceHandler = new DOMMountPointServiceHandler(mountPointService);
65 final DOMDataBrokerHandler brokerHandler = new DOMDataBrokerHandler(dataBroker);
67 final RpcServiceHandler rpcServiceHandler = new RpcServiceHandler(rpcService);
69 final NotificationServiceHandler notificationServiceHandler =
70 new NotificationServiceHandler(notificationService);
72 if (wrapperServices != null) {
73 wrapperServices.setHandlers(this.schemaCtxHandler, RestConnectorProvider.mountPointServiceHandler,
74 transactionChainHandler, brokerHandler, rpcServiceHandler,
75 notificationServiceHandler, domSchemaService);
79 public DOMMountPointServiceHandler getMountPointServiceHandler() {
80 return mountPointServiceHandler;
84 * Get current {@link DOMMountPointService} from {@link DOMMountPointServiceHandler}.
85 * @return {@link DOMMountPointService}
87 public static DOMMountPointService getMountPointService() {
88 return mountPointServiceHandler.get();
93 mountPointServiceHandler = null;