Remove FlowGroupCacheManager crud
[openflowplugin.git] / openflowplugin-impl / src / main / java / org / opendaylight / openflowplugin / impl / device / history / FlowGroupInfoHistoryImpl.java
diff --git a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/device/history/FlowGroupInfoHistoryImpl.java b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/device/history/FlowGroupInfoHistoryImpl.java
new file mode 100644 (file)
index 0000000..6ee631a
--- /dev/null
@@ -0,0 +1,41 @@
+/*
+ * Copyright (c) 2020 PANTHEON.tech, s.r.o. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.openflowplugin.impl.device.history;
+
+import com.google.common.collect.EvictingQueue;
+import com.google.common.collect.ImmutableList;
+import java.util.Collection;
+import org.checkerframework.checker.lock.qual.GuardedBy;
+import org.eclipse.jdt.annotation.NonNullByDefault;
+import org.opendaylight.openflowplugin.api.openflow.FlowGroupInfo;
+import org.opendaylight.openflowplugin.api.openflow.FlowGroupInfoHistory;
+
+@NonNullByDefault
+public final class FlowGroupInfoHistoryImpl implements FlowGroupInfoHistory, FlowGroupInfoHistoryAppender {
+    // FIXME: most of the time all we access it from the same(-ish) context. We should be able to do better. To do do
+    //        that we need an Executor which will run exclusively with the associated device
+    //        (i.e. in its Netty context) ...
+    @GuardedBy("this")
+    private final EvictingQueue<FlowGroupInfo> entries;
+
+    public FlowGroupInfoHistoryImpl(final int size) {
+        entries = EvictingQueue.create(size);
+    }
+
+    // FIXME: ... in which case this method will not be synchronized ...
+    @Override
+    public synchronized void appendFlowGroupInfo(final FlowGroupInfo info) {
+        entries.add(info);
+    }
+
+    // FIXME: ... and this method will submit a request on that executor, producing a copy of the history
+    @Override
+    public synchronized Collection<FlowGroupInfo> readEntries() {
+        return ImmutableList.copyOf(entries);
+    }
+}