Thomas Vachuska | 0fa2aa1 | 2015-08-18 12:53:04 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2015-present Open Networking Foundation |
Thomas Vachuska | 0fa2aa1 | 2015-08-18 12:53:04 -0700 | [diff] [blame] | 3 | * |
| 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 | */ |
| 16 | package org.onosproject.rest.impl; |
| 17 | |
| 18 | import com.google.common.collect.ImmutableSet; |
| 19 | import com.google.common.collect.Maps; |
Thomas Vachuska | 0fa2aa1 | 2015-08-18 12:53:04 -0700 | [diff] [blame] | 20 | import org.onosproject.rest.ApiDocProvider; |
| 21 | import org.onosproject.rest.ApiDocService; |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 22 | import org.osgi.service.component.annotations.Activate; |
| 23 | import org.osgi.service.component.annotations.Component; |
| 24 | import org.osgi.service.component.annotations.Deactivate; |
Thomas Vachuska | 0fa2aa1 | 2015-08-18 12:53:04 -0700 | [diff] [blame] | 25 | import org.slf4j.Logger; |
| 26 | import org.slf4j.LoggerFactory; |
| 27 | |
| 28 | import java.util.Map; |
| 29 | import java.util.Set; |
| 30 | |
| 31 | /** |
| 32 | * Implementation of the REST API documentation tracker. |
| 33 | */ |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 34 | @Component(immediate = true, service = ApiDocService.class) |
Thomas Vachuska | 0fa2aa1 | 2015-08-18 12:53:04 -0700 | [diff] [blame] | 35 | public 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 HIGUCHI | 2035e72 | 2016-12-21 17:52:21 -0800 | [diff] [blame] | 55 | log.info("{} registered at {}", provider.name(), provider.key()); |
Thomas Vachuska | 0fa2aa1 | 2015-08-18 12:53:04 -0700 | [diff] [blame] | 56 | } |
| 57 | |
| 58 | @Override |
| 59 | public void unregister(ApiDocProvider provider) { |
| 60 | providers.remove(provider.name()); |
Yuta HIGUCHI | 2035e72 | 2016-12-21 17:52:21 -0800 | [diff] [blame] | 61 | log.info("{} unregistered", provider.name()); |
Thomas Vachuska | 0fa2aa1 | 2015-08-18 12:53:04 -0700 | [diff] [blame] | 62 | } |
| 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 | } |