c5e2192a530ee2bbe7889788e76051596f6c2761
[openflowplugin.git] / openflowplugin-impl / src / main / java / org / opendaylight / openflowplugin / impl / registry / meter / DeviceMeterRegistryImpl.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.registry.meter;
10
11 import java.util.ArrayList;
12 import java.util.List;
13 import org.opendaylight.openflowplugin.api.openflow.registry.meter.DeviceMeterRegistry;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.MeterId;
15
16 /**
17  * Created by Martin Bobak <mbobak@cisco.com> on 15.4.2015.
18  */
19 public class DeviceMeterRegistryImpl implements DeviceMeterRegistry {
20
21     private final List<MeterId> meterIds = new ArrayList<>();
22     private final List<MeterId> marks = new ArrayList<>();
23
24     @Override
25     public void store(final MeterId meterId) {
26         meterIds.add(meterId);
27     }
28
29     @Override
30     public void markToBeremoved(final MeterId meterId) {
31         marks.add(meterId);
32     }
33
34     @Override
35     public void removeMarked() {
36         synchronized (meterIds) {
37             meterIds.removeAll(marks);
38         }
39         synchronized (marks) {
40             marks.clear();
41         }
42     }
43
44     @Override
45     public List<MeterId> getAllMeterIds() {
46         return meterIds;
47     }
48
49     @Override
50     public void close() {
51         synchronized (meterIds) {
52             meterIds.clear();
53         }
54         synchronized (marks) {
55             marks.clear();
56         }
57     }
58 }