blob: f9dd678f0cff0288d290aee1968da4b43fd5660f [file] [log] [blame]
Thomas Vachuska0fa2aa12015-08-18 12:53:04 -07001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2015-present Open Networking Foundation
Thomas Vachuska0fa2aa12015-08-18 12:53:04 -07003 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16package org.onosproject.rest.impl;
17
18import com.google.common.collect.ImmutableSet;
19import com.google.common.collect.Maps;
Thomas Vachuska0fa2aa12015-08-18 12:53:04 -070020import org.onosproject.rest.ApiDocProvider;
21import org.onosproject.rest.ApiDocService;
Ray Milkeyd84f89b2018-08-17 14:54:17 -070022import org.osgi.service.component.annotations.Activate;
23import org.osgi.service.component.annotations.Component;
24import org.osgi.service.component.annotations.Deactivate;
Thomas Vachuska0fa2aa12015-08-18 12:53:04 -070025import org.slf4j.Logger;
26import org.slf4j.LoggerFactory;
27
28import java.util.Map;
29import java.util.Set;
30
31/**
32 * Implementation of the REST API documentation tracker.
33 */
Ray Milkeyd84f89b2018-08-17 14:54:17 -070034@Component(immediate = true, service = ApiDocService.class)
Thomas Vachuska0fa2aa12015-08-18 12:53:04 -070035public class ApiDocManager implements ApiDocService {
36
37 private final Logger log = LoggerFactory.getLogger(getClass());
38
39 // Set of doc providers
40 private final Map<String, ApiDocProvider> providers = Maps.newConcurrentMap();
41
42 @Activate
43 public void activate() {
44 log.info("Started");
45 }
46
47 @Deactivate
48 public void deactivate() {
49 log.info("Stopped");
50 }
51
52 @Override
53 public void register(ApiDocProvider provider) {
54 providers.put(provider.key(), provider);
Yuta HIGUCHI2035e722016-12-21 17:52:21 -080055 log.info("{} registered at {}", provider.name(), provider.key());
Thomas Vachuska0fa2aa12015-08-18 12:53:04 -070056 }
57
58 @Override
59 public void unregister(ApiDocProvider provider) {
60 providers.remove(provider.name());
Yuta HIGUCHI2035e722016-12-21 17:52:21 -080061 log.info("{} unregistered", provider.name());
Thomas Vachuska0fa2aa12015-08-18 12:53:04 -070062 }
63
64 @Override
65 public Set<ApiDocProvider> getDocProviders() {
66 return ImmutableSet.copyOf(providers.values());
67 }
68
69 @Override
70 public ApiDocProvider getDocProvider(String key) {
71 return providers.get(key);
72 }
73}