c2cfda5b69ef62a55c2d022f86322a9bf73f3b59
[openflowplugin.git] / openflowplugin-impl / src / main / java / org / opendaylight / openflowplugin / impl / device / ItemLifeCycleRegistryImpl.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.device;
10
11 import java.util.Collections;
12 import java.util.Set;
13 import java.util.concurrent.ConcurrentHashMap;
14 import org.opendaylight.openflowplugin.api.openflow.registry.ItemLifeCycleRegistry;
15 import org.opendaylight.openflowplugin.api.openflow.rpc.ItemLifeCycleSource;
16 import org.opendaylight.yangtools.concepts.Registration;
17
18 /**
19  * Default implementation.
20  */
21 public class ItemLifeCycleRegistryImpl implements ItemLifeCycleRegistry {
22
23     private final Set<ItemLifeCycleSource> registry;
24
25     public ItemLifeCycleRegistryImpl() {
26         registry = Collections.newSetFromMap(new ConcurrentHashMap<ItemLifeCycleSource, Boolean>());
27     }
28
29
30     @Override
31
32     public Registration registerLifeCycleSource(final ItemLifeCycleSource lifeCycleSource) {
33         registry.add(lifeCycleSource);
34         return new Registration() {
35             @Override
36             public void close() throws Exception {
37                 registry.remove(lifeCycleSource);
38             }
39         };
40     }
41
42     @Override
43     public void clear() {
44         registry.clear();
45     }
46
47     @Override
48     public Iterable<ItemLifeCycleSource> getLifeCycleSources() {
49         return Collections.unmodifiableCollection(registry);
50     }
51 }