blob: 6500e6be04b63af6fef96907bbdb3373194a40ff [file] [log] [blame]
Thomas Vachuska0fa2aa12015-08-18 12:53:04 -07001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2015-present Open Networking Laboratory
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;
20import org.apache.felix.scr.annotations.Activate;
21import org.apache.felix.scr.annotations.Component;
22import org.apache.felix.scr.annotations.Deactivate;
23import org.apache.felix.scr.annotations.Service;
24import org.onosproject.rest.ApiDocProvider;
25import org.onosproject.rest.ApiDocService;
26import org.slf4j.Logger;
27import org.slf4j.LoggerFactory;
28
29import java.util.Map;
30import java.util.Set;
31
32/**
33 * Implementation of the REST API documentation tracker.
34 */
35@Component(immediate = true)
36@Service
37public class ApiDocManager implements ApiDocService {
38
39 private final Logger log = LoggerFactory.getLogger(getClass());
40
41 // Set of doc providers
42 private final Map<String, ApiDocProvider> providers = Maps.newConcurrentMap();
43
44 @Activate
45 public void activate() {
46 log.info("Started");
47 }
48
49 @Deactivate
50 public void deactivate() {
51 log.info("Stopped");
52 }
53
54 @Override
55 public void register(ApiDocProvider provider) {
56 providers.put(provider.key(), provider);
Yuta HIGUCHI2035e722016-12-21 17:52:21 -080057 log.info("{} registered at {}", provider.name(), provider.key());
Thomas Vachuska0fa2aa12015-08-18 12:53:04 -070058 }
59
60 @Override
61 public void unregister(ApiDocProvider provider) {
62 providers.remove(provider.name());
Yuta HIGUCHI2035e722016-12-21 17:52:21 -080063 log.info("{} unregistered", provider.name());
Thomas Vachuska0fa2aa12015-08-18 12:53:04 -070064 }
65
66 @Override
67 public Set<ApiDocProvider> getDocProviders() {
68 return ImmutableSet.copyOf(providers.values());
69 }
70
71 @Override
72 public ApiDocProvider getDocProvider(String key) {
73 return providers.get(key);
74 }
75}