Thomas Vachuska | 24c849c | 2014-10-27 09:53:05 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | 5ab426f | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2015-present Open Networking Laboratory |
Thomas Vachuska | 24c849c | 2014-10-27 09:53:05 -0700 | [diff] [blame] | 3 | * |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 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 |
Thomas Vachuska | 24c849c | 2014-10-27 09:53:05 -0700 | [diff] [blame] | 7 | * |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 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. |
Thomas Vachuska | 24c849c | 2014-10-27 09:53:05 -0700 | [diff] [blame] | 15 | */ |
tom | 0eb04ca | 2014-08-25 14:34:51 -0700 | [diff] [blame] | 16 | package org.onlab.osgi; |
| 17 | |
| 18 | import com.google.common.collect.ClassToInstanceMap; |
| 19 | import com.google.common.collect.MutableClassToInstanceMap; |
| 20 | |
| 21 | /** |
| 22 | * Service directory implementation suitable for testing. |
| 23 | */ |
Ray Milkey | 5154ec3 | 2014-10-22 10:51:18 -0700 | [diff] [blame] | 24 | @SuppressWarnings("unchecked") |
tom | 0eb04ca | 2014-08-25 14:34:51 -0700 | [diff] [blame] | 25 | public class TestServiceDirectory implements ServiceDirectory { |
| 26 | |
| 27 | private ClassToInstanceMap<Object> services = MutableClassToInstanceMap.create(); |
| 28 | |
| 29 | @Override |
| 30 | public <T> T get(Class<T> serviceClass) { |
| 31 | return services.getInstance(serviceClass); |
| 32 | } |
| 33 | |
| 34 | /** |
| 35 | * Adds a new service to the directory. |
| 36 | * |
| 37 | * @param serviceClass service class |
| 38 | * @param service service instance |
| 39 | * @return self |
| 40 | */ |
| 41 | public TestServiceDirectory add(Class serviceClass, Object service) { |
| 42 | services.putInstance(serviceClass, service); |
| 43 | return this; |
| 44 | } |
| 45 | |
| 46 | } |