ab84e302e1db3a9b8300c8e6d680e7648bd79c70
[netconf.git] / restconf / sal-rest-docgen / src / main / java / org / opendaylight / netconf / sal / rest / doc / DocProvider.java
1 /*
2  * Copyright (c) 2014, 2017 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 package org.opendaylight.netconf.sal.rest.doc;
9
10 import java.util.LinkedList;
11 import java.util.List;
12 import org.opendaylight.controller.md.sal.dom.api.DOMMountPointService;
13 import org.opendaylight.controller.sal.core.api.model.SchemaService;
14 import org.opendaylight.controller.sal.core.api.mount.MountProvisionListener;
15 import org.opendaylight.netconf.sal.rest.doc.impl.ApiDocGenerator;
16 import org.opendaylight.netconf.sal.rest.doc.mountpoints.MountPointSwagger;
17 import org.opendaylight.yangtools.concepts.ListenerRegistration;
18 import org.slf4j.Logger;
19 import org.slf4j.LoggerFactory;
20
21 public class DocProvider {
22
23     private static final Logger LOG = LoggerFactory.getLogger(DocProvider.class);
24
25     private final List<AutoCloseable> toClose = new LinkedList<>();
26
27     public DocProvider(final SchemaService schemaService, final DOMMountPointService mountService) {
28
29         ApiDocGenerator.getInstance().setSchemaService(schemaService);
30
31         final ListenerRegistration<MountProvisionListener> registration = mountService
32                 .registerProvisionListener(MountPointSwagger.getInstance());
33         MountPointSwagger.getInstance().setGlobalSchema(schemaService);
34         synchronized (toClose) {
35             toClose.add(registration);
36         }
37         MountPointSwagger.getInstance().setMountService(mountService);
38
39         LOG.debug("Restconf API Explorer started");
40     }
41
42     public void close() throws Exception {
43         synchronized (toClose) {
44             for (final AutoCloseable close : toClose) {
45                 close.close();
46             }
47         }
48     }
49 }