Updated accumulator documentation and refactored names to remove the event heritage.
Change-Id: I2238ab1215281702e670a406fb901ba8a4ef85ce
diff --git a/core/api/src/main/java/org/onosproject/event/AbstractEventAccumulator.java b/core/api/src/main/java/org/onosproject/event/AbstractEventAccumulator.java
deleted file mode 100644
index f3fc65f..0000000
--- a/core/api/src/main/java/org/onosproject/event/AbstractEventAccumulator.java
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * Copyright 2014 Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.onosproject.event;
-
-import org.onlab.util.AbstractAccumulator;
-
-import java.util.Timer;
-
-/**
- * Base implementation of an event accumulator. It allows triggering based on
- * event inter-arrival time threshold, maximum batch life threshold and maximum
- * batch size.
- */
-public abstract class AbstractEventAccumulator
- extends AbstractAccumulator<Event>
- implements EventAccumulator {
-
- /**
- * Creates an event accumulator capable of triggering on the specified
- * thresholds.
- *
- * @param timer timer to use for scheduling check-points
- * @param maxEvents maximum number of events to accumulate before
- * processing is triggered
- * @param maxBatchMillis maximum number of millis allowed since the first
- * event before processing is triggered
- * @param maxIdleMillis maximum number millis between events before
- * processing is triggered
- */
- protected AbstractEventAccumulator(Timer timer, int maxEvents,
- int maxBatchMillis, int maxIdleMillis) {
- super(timer, maxEvents, maxBatchMillis, maxIdleMillis);
- }
-}
diff --git a/core/api/src/main/java/org/onosproject/event/EventAccumulator.java b/core/api/src/main/java/org/onosproject/event/EventAccumulator.java
deleted file mode 100644
index 78acfa0..0000000
--- a/core/api/src/main/java/org/onosproject/event/EventAccumulator.java
+++ /dev/null
@@ -1,25 +0,0 @@
-/*
- * Copyright 2014 Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.onosproject.event;
-
-import org.onlab.util.Accumulator;
-
-/**
- * Abstraction of an accumulator capable of collecting events and at some
- * point in time triggers processing of all previously accumulated events.
- */
-public interface EventAccumulator extends Accumulator<Event> {
-}
diff --git a/core/api/src/test/java/org/onosproject/event/AbstractEventAccumulatorTest.java b/core/api/src/test/java/org/onosproject/event/AbstractEventAccumulatorTest.java
deleted file mode 100644
index 67163dc5..0000000
--- a/core/api/src/test/java/org/onosproject/event/AbstractEventAccumulatorTest.java
+++ /dev/null
@@ -1,105 +0,0 @@
-/*
- * Copyright 2014 Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.onosproject.event;
-
-import org.junit.Ignore;
-import org.junit.Test;
-
-import java.util.List;
-import java.util.Timer;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-import static org.onlab.junit.TestTools.delay;
-import static org.onosproject.event.TestEvent.Type.FOO;
-
-/**
- * Tests the operation of the accumulator.
- */
-public class AbstractEventAccumulatorTest {
-
- private final Timer timer = new Timer();
-
- @Test
- public void basics() throws Exception {
- TestAccumulator accumulator = new TestAccumulator();
- assertEquals("incorrect timer", timer, accumulator.timer());
- assertEquals("incorrect max events", 5, accumulator.maxEvents());
- assertEquals("incorrect max ms", 100, accumulator.maxBatchMillis());
- assertEquals("incorrect idle ms", 50, accumulator.maxIdleMillis());
- }
-
- @Test
- public void eventTrigger() {
- TestAccumulator accumulator = new TestAccumulator();
- accumulator.add(new TestEvent(FOO, "a"));
- accumulator.add(new TestEvent(FOO, "b"));
- accumulator.add(new TestEvent(FOO, "c"));
- accumulator.add(new TestEvent(FOO, "d"));
- assertTrue("should not have fired yet", accumulator.batch.isEmpty());
- accumulator.add(new TestEvent(FOO, "e"));
- delay(20);
- assertFalse("should have fired", accumulator.batch.isEmpty());
- assertEquals("incorrect batch", "abcde", accumulator.batch);
- }
-
- @Ignore("FIXME: timing sensitive test failing randomly.")
- @Test
- public void timeTrigger() {
- TestAccumulator accumulator = new TestAccumulator();
- accumulator.add(new TestEvent(FOO, "a"));
- delay(30);
- assertTrue("should not have fired yet", accumulator.batch.isEmpty());
- accumulator.add(new TestEvent(FOO, "b"));
- delay(30);
- assertTrue("should not have fired yet", accumulator.batch.isEmpty());
- accumulator.add(new TestEvent(FOO, "c"));
- delay(30);
- assertTrue("should not have fired yet", accumulator.batch.isEmpty());
- accumulator.add(new TestEvent(FOO, "d"));
- delay(30);
- assertFalse("should have fired", accumulator.batch.isEmpty());
- assertEquals("incorrect batch", "abcd", accumulator.batch);
- }
-
- @Test
- public void idleTrigger() {
- TestAccumulator accumulator = new TestAccumulator();
- accumulator.add(new TestEvent(FOO, "a"));
- assertTrue("should not have fired yet", accumulator.batch.isEmpty());
- accumulator.add(new TestEvent(FOO, "b"));
- delay(80);
- assertFalse("should have fired", accumulator.batch.isEmpty());
- assertEquals("incorrect batch", "ab", accumulator.batch);
- }
-
- private class TestAccumulator extends AbstractEventAccumulator {
-
- String batch = "";
-
- protected TestAccumulator() {
- super(timer, 5, 100, 50);
- }
-
- @Override
- public void processEvents(List<Event> events) {
- for (Event event : events) {
- batch += event.subject();
- }
- }
- }
-}
diff --git a/core/net/src/main/java/org/onosproject/net/intent/impl/IntentAccumulator.java b/core/net/src/main/java/org/onosproject/net/intent/impl/IntentAccumulator.java
index 7eef748..09f5511 100644
--- a/core/net/src/main/java/org/onosproject/net/intent/impl/IntentAccumulator.java
+++ b/core/net/src/main/java/org/onosproject/net/intent/impl/IntentAccumulator.java
@@ -53,8 +53,8 @@
}
@Override
- public void processEvents(List<IntentData> ops) {
- delegate.execute(reduce(ops));
+ public void processItems(List<IntentData> items) {
+ delegate.execute(reduce(items));
// FIXME kick off the work
//for (IntentData data : opMap.values()) {}
}
diff --git a/core/net/src/main/java/org/onosproject/net/topology/impl/DefaultTopologyProvider.java b/core/net/src/main/java/org/onosproject/net/topology/impl/DefaultTopologyProvider.java
index 6137fa4..83e1f91 100644
--- a/core/net/src/main/java/org/onosproject/net/topology/impl/DefaultTopologyProvider.java
+++ b/core/net/src/main/java/org/onosproject/net/topology/impl/DefaultTopologyProvider.java
@@ -16,7 +16,6 @@
package org.onosproject.net.topology.impl;
import com.google.common.collect.ImmutableList;
-
import org.apache.felix.scr.annotations.Activate;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Deactivate;
@@ -25,9 +24,9 @@
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.ReferenceCardinality;
import org.apache.felix.scr.annotations.Service;
-import org.onosproject.event.AbstractEventAccumulator;
+import org.onlab.util.AbstractAccumulator;
+import org.onlab.util.Accumulator;
import org.onosproject.event.Event;
-import org.onosproject.event.EventAccumulator;
import org.onosproject.net.device.DeviceEvent;
import org.onosproject.net.device.DeviceListener;
import org.onosproject.net.device.DeviceService;
@@ -51,9 +50,9 @@
import static com.google.common.base.Strings.isNullOrEmpty;
import static java.util.concurrent.Executors.newFixedThreadPool;
+import static org.onlab.util.Tools.namedThreads;
import static org.onosproject.core.CoreService.CORE_PROVIDER_ID;
import static org.onosproject.net.device.DeviceEvent.Type.*;
-import static org.onlab.util.Tools.namedThreads;
import static org.slf4j.LoggerFactory.getLogger;
/**
@@ -104,7 +103,7 @@
private DeviceListener deviceListener = new InternalDeviceListener();
private LinkListener linkListener = new InternalLinkListener();
- private EventAccumulator accumulator;
+ private Accumulator<Event> accumulator;
private ExecutorService executor;
/**
@@ -245,18 +244,15 @@
}
// Event accumulator for paced triggering of topology assembly.
- private class TopologyChangeAccumulator
- extends AbstractEventAccumulator implements EventAccumulator {
-
+ private class TopologyChangeAccumulator extends AbstractAccumulator<Event> {
TopologyChangeAccumulator() {
super(TIMER, maxEvents, maxBatchMs, maxIdleMs);
}
@Override
- public void processEvents(List<Event> events) {
- triggerTopologyBuild(events);
+ public void processItems(List<Event> items) {
+ triggerTopologyBuild(items);
}
-
}
// Task for building topology data in a separate thread.