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