Merge changes from topic 'ofj-models-to-ofp-models'
[openflowplugin.git] / openflowplugin-impl / src / main / java / org / opendaylight / openflowplugin / impl / statistics / services / direct / OpendaylightDirectStatisticsServiceProvider.java
1 /*
2  * Copyright (c) 2015 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8
9 package org.opendaylight.openflowplugin.impl.statistics.services.direct;
10
11 import java.util.HashMap;
12 import java.util.Map;
13 import java.util.Optional;
14
15 /**
16  * The Opendaylight direct statistics service provider.
17  */
18 public class OpendaylightDirectStatisticsServiceProvider {
19     private Map<Class<? extends AbstractDirectStatisticsService>, AbstractDirectStatisticsService> services = new HashMap<>();
20
21     /**
22      * Register direct statistics service.
23      *
24      * @param type    the service type
25      * @param service the service instance
26      */
27     public void register(Class<? extends AbstractDirectStatisticsService> type, AbstractDirectStatisticsService service) {
28         services.put(type, service);
29     }
30
31     /**
32      * Lookup direct statistics service.
33      *
34      * @param type the service type
35      * @return the service instance
36      */
37     public Optional<? extends AbstractDirectStatisticsService> lookup(Class<? extends AbstractDirectStatisticsService> type) {
38         return Optional.ofNullable(services.get(type)).map(type::cast);
39     }
40 }