Use DOMMountPointServiceHandler non-statically
[netconf.git] / restconf / restconf-nb-rfc8040 / src / main / java / org / opendaylight / restconf / nb / rfc8040 / RestConnectorProvider.java
1 /*
2  * Copyright (c) 2016 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8
9 package org.opendaylight.restconf.nb.rfc8040;
10
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;
25
26 /**
27  * Provider for restconf draft18.
28  *
29  */
30 public class RestConnectorProvider<T extends ServiceWrapper> implements RestconfConnector, AutoCloseable {
31
32     private static final Logger LOG = LoggerFactory.getLogger(RestConnectorProvider.class);
33
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;
42
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);
56     }
57
58     public synchronized void start() {
59         final DOMDataBrokerHandler brokerHandler = new DOMDataBrokerHandler(dataBroker);
60
61         final RpcServiceHandler rpcServiceHandler = new RpcServiceHandler(rpcService);
62
63         final NotificationServiceHandler notificationServiceHandler =
64                 new NotificationServiceHandler(notificationService);
65
66         if (wrapperServices != null) {
67             wrapperServices.setHandlers(this.schemaCtxHandler, mountPointServiceHandler,
68                     transactionChainHandler, brokerHandler, rpcServiceHandler,
69                     notificationServiceHandler, domSchemaService);
70         }
71     }
72
73     @Override
74     public void close() {
75     }
76 }