2 * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
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
9 package org.opendaylight.openflowplugin.impl.statistics.services.direct;
11 import java.util.HashMap;
13 import java.util.Optional;
16 * The Opendaylight direct statistics service provider.
18 public class OpendaylightDirectStatisticsServiceProvider {
19 private Map<Class<? extends AbstractDirectStatisticsService>, AbstractDirectStatisticsService> services = new HashMap<>();
22 * Register direct statistics service.
24 * @param type the service type
25 * @param service the service instance
27 public void register(Class<? extends AbstractDirectStatisticsService> type, AbstractDirectStatisticsService service) {
28 if (services.containsKey(type)) return;
30 services.put(type, service);
34 * Lookup direct statistics service.
36 * @param <T> the type parameter
37 * @param type the service type
38 * @return the service instance
40 public <T extends AbstractDirectStatisticsService> Optional<T> lookup(Class<T> type) {
41 if (!services.containsKey(type)) return Optional.empty();
43 return Optional.of(type.cast(services.get(type)));