Simon Hunt

Renamed AbstractListenerRegistry to ListenerRegistry (since it is not abstract).

- added checkForNonRegistrant() predicate and augmented unit tests.

Change-Id: I7ecc618f01fdc4cead6f143a1e5e0ddd03268efc
Showing 21 changed files with 177 additions and 132 deletions
......@@ -28,15 +28,20 @@ import static org.slf4j.LoggerFactory.getLogger;
* Base implementation of an event sink and a registry capable of tracking
* listeners and dispatching events to them as part of event sink processing.
*/
public class AbstractListenerRegistry<E extends Event, L extends EventListener<E>>
public class ListenerRegistry<E extends Event, L extends EventListener<E>>
implements EventSink<E> {
private final Logger log = getLogger(getClass());
protected final Set<L> listeners = new CopyOnWriteArraySet<>();
private volatile boolean shutdown = false;
/**
* Set of listeners that have registered.
*/
protected final Set<L> listeners = new CopyOnWriteArraySet<>();
/**
* Adds the specified listener.
*
* @param listener listener to be added
......@@ -53,7 +58,9 @@ public class AbstractListenerRegistry<E extends Event, L extends EventListener<E
*/
public void removeListener(L listener) {
checkNotNull(listener, "Listener cannot be null");
checkArgument(listeners.remove(listener), "Listener not registered");
if (checkForNonRegistrant()) {
checkArgument(listeners.remove(listener), "Listener not registered");
}
}
@Override
......@@ -68,6 +75,19 @@ public class AbstractListenerRegistry<E extends Event, L extends EventListener<E
}
/**
* Predicate indicating whether we should throw an exception if the
* argument to {@link #removeListener} is not in the current set of
* listeners.
* <p>
* This default implementation returns <code>true</code>.
*
* @return true if non-listed listeners should cause exception on remove
*/
protected boolean checkForNonRegistrant() {
return true;
}
/**
* Reports a problem encountered while processing an event.
*
* @param event event being processed
......@@ -92,5 +112,4 @@ public class AbstractListenerRegistry<E extends Event, L extends EventListener<E
public void deactivate() {
shutdown = true;
}
}
......
......@@ -15,50 +15,79 @@
*/
package org.onosproject.event;
import org.junit.Before;
import org.junit.Test;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
/**
* Tests of the base listener manager.
* Unit tests for {@link ListenerRegistry}.
*/
public class AbstractListenerRegistryTest {
public class ListenerRegistryTest {
private static class RelaxedRegistry extends TestListenerRegistry {
@Override
protected boolean checkForNonRegistrant() {
return false;
}
}
private static final TestEvent FOO_EVENT =
new TestEvent(TestEvent.Type.FOO, "foo");
private static final TestEvent BAR_EVENT =
new TestEvent(TestEvent.Type.BAR, "bar");
private TestListener listener;
private TestListener secondListener;
private TestListenerRegistry manager;
@Before
public void setUp() {
listener = new TestListener();
secondListener = new TestListener();
manager = new TestListenerRegistry();
}
@Test
public void basics() {
TestListener listener = new TestListener();
TestListener secondListener = new TestListener();
TestListenerRegistry manager = new TestListenerRegistry();
manager.addListener(listener);
manager.addListener(secondListener);
TestEvent event = new TestEvent(TestEvent.Type.BAR, "bar");
manager.process(event);
assertTrue("event not processed", listener.events.contains(event));
assertTrue("event not processed", secondListener.events.contains(event));
manager.process(BAR_EVENT);
assertTrue("BAR not processed", listener.events.contains(BAR_EVENT));
assertTrue("BAR not processed", secondListener.events.contains(BAR_EVENT));
manager.removeListener(listener);
TestEvent another = new TestEvent(TestEvent.Type.FOO, "foo");
manager.process(another);
assertFalse("event processed", listener.events.contains(another));
assertTrue("event not processed", secondListener.events.contains(event));
manager.process(FOO_EVENT);
assertFalse("FOO processed", listener.events.contains(FOO_EVENT));
assertTrue("FOO not processed", secondListener.events.contains(FOO_EVENT));
}
@Test
public void badListener() {
TestListener listener = new BrokenListener();
TestListener secondListener = new TestListener();
TestListenerRegistry manager = new TestListenerRegistry();
listener = new BrokenListener();
manager.addListener(listener);
manager.addListener(secondListener);
TestEvent event = new TestEvent(TestEvent.Type.BAR, "bar");
manager.process(event);
assertFalse("event processed", listener.events.contains(event));
manager.process(BAR_EVENT);
assertFalse("BAR processed", listener.events.contains(BAR_EVENT));
assertFalse("error not reported", manager.errors.isEmpty());
assertTrue("event not processed", secondListener.events.contains(event));
assertTrue("BAR not processed", secondListener.events.contains(BAR_EVENT));
}
@Test(expected = IllegalArgumentException.class)
public void removeNonListenerCausesException() {
manager.removeListener(listener);
}
@Test
public void removeNonListenerIgnored() {
manager = new RelaxedRegistry();
manager.removeListener(listener);
assertTrue("what?", manager.listeners.isEmpty());
}
}
......
......@@ -22,7 +22,7 @@ import java.util.List;
* Test event listener manager fixture.
*/
public class TestListenerRegistry
extends AbstractListenerRegistry<TestEvent, TestListener> {
extends ListenerRegistry<TestEvent, TestListener> {
public final List<Throwable> errors = new ArrayList<>();
......
......@@ -33,7 +33,7 @@ import org.onosproject.app.ApplicationStoreDelegate;
import org.onosproject.core.Application;
import org.onosproject.core.ApplicationId;
import org.onosproject.core.Permission;
import org.onosproject.event.AbstractListenerRegistry;
import org.onosproject.event.ListenerRegistry;
import org.onosproject.event.EventDeliveryService;
import org.slf4j.Logger;
......@@ -55,8 +55,8 @@ public class ApplicationManager implements ApplicationService, ApplicationAdminS
private static final String APP_ID_NULL = "Application ID cannot be null";
protected final AbstractListenerRegistry<ApplicationEvent, ApplicationListener>
listenerRegistry = new AbstractListenerRegistry<>();
protected final ListenerRegistry<ApplicationEvent, ApplicationListener>
listenerRegistry = new ListenerRegistry<>();
private final ApplicationStoreDelegate delegate = new InternalStoreDelegate();
......
......@@ -32,7 +32,7 @@ import org.onosproject.cluster.ClusterStore;
import org.onosproject.cluster.ClusterStoreDelegate;
import org.onosproject.cluster.ControllerNode;
import org.onosproject.cluster.NodeId;
import org.onosproject.event.AbstractListenerRegistry;
import org.onosproject.event.ListenerRegistry;
import org.onosproject.event.EventDeliveryService;
import org.slf4j.Logger;
......@@ -54,8 +54,8 @@ public class ClusterManager implements ClusterService, ClusterAdminService {
private ClusterStoreDelegate delegate = new InternalStoreDelegate();
protected final AbstractListenerRegistry<ClusterEvent, ClusterEventListener>
listenerRegistry = new AbstractListenerRegistry<>();
protected final ListenerRegistry<ClusterEvent, ClusterEventListener>
listenerRegistry = new ListenerRegistry<>();
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected ClusterStore store;
......
......@@ -30,7 +30,7 @@ import org.onosproject.cluster.ControllerNode;
import org.onosproject.cluster.NodeId;
import org.onosproject.cluster.RoleInfo;
import org.onosproject.core.MetricsHelper;
import org.onosproject.event.AbstractListenerRegistry;
import org.onosproject.event.ListenerRegistry;
import org.onosproject.event.EventDeliveryService;
import org.onosproject.mastership.MastershipAdminService;
import org.onosproject.mastership.MastershipEvent;
......@@ -73,8 +73,8 @@ public class MastershipManager
private final Logger log = getLogger(getClass());
protected final AbstractListenerRegistry<MastershipEvent, MastershipListener>
listenerRegistry = new AbstractListenerRegistry<>();
protected final ListenerRegistry<MastershipEvent, MastershipListener>
listenerRegistry = new ListenerRegistry<>();
private final MastershipStoreDelegate delegate = new InternalDelegate();
......
......@@ -24,7 +24,7 @@ import org.apache.felix.scr.annotations.ReferenceCardinality;
import org.apache.felix.scr.annotations.Service;
import org.onosproject.cluster.ClusterService;
import org.onosproject.cluster.NodeId;
import org.onosproject.event.AbstractListenerRegistry;
import org.onosproject.event.ListenerRegistry;
import org.onosproject.event.EventDeliveryService;
import org.onosproject.mastership.MastershipEvent;
import org.onosproject.mastership.MastershipListener;
......@@ -83,8 +83,8 @@ public class DeviceManager
private final Logger log = getLogger(getClass());
protected final AbstractListenerRegistry<DeviceEvent, DeviceListener> listenerRegistry =
new AbstractListenerRegistry<>();
protected final ListenerRegistry<DeviceEvent, DeviceListener> listenerRegistry =
new ListenerRegistry<>();
private final DeviceStoreDelegate delegate = new InternalStoreDelegate();
......
......@@ -35,7 +35,7 @@ import org.onosproject.cfg.ComponentConfigService;
import org.onosproject.core.ApplicationId;
import org.onosproject.core.CoreService;
import org.onosproject.core.IdGenerator;
import org.onosproject.event.AbstractListenerRegistry;
import org.onosproject.event.ListenerRegistry;
import org.onosproject.event.EventDeliveryService;
import org.onosproject.net.Device;
import org.onosproject.net.DeviceId;
......@@ -97,8 +97,8 @@ public class FlowRuleManager
private final Logger log = getLogger(getClass());
private final AbstractListenerRegistry<FlowRuleEvent, FlowRuleListener>
listenerRegistry = new AbstractListenerRegistry<>();
private final ListenerRegistry<FlowRuleEvent, FlowRuleListener>
listenerRegistry = new ListenerRegistry<>();
private final FlowRuleStoreDelegate delegate = new InternalStoreDelegate();
......
......@@ -15,13 +15,7 @@
*/
package org.onosproject.net.group.impl;
import static org.slf4j.LoggerFactory.getLogger;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
import java.util.Set;
import com.google.common.collect.Sets;
import org.apache.felix.scr.annotations.Activate;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Deactivate;
......@@ -29,8 +23,8 @@ import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.ReferenceCardinality;
import org.apache.felix.scr.annotations.Service;
import org.onosproject.core.ApplicationId;
import org.onosproject.event.AbstractListenerRegistry;
import org.onosproject.event.EventDeliveryService;
import org.onosproject.event.ListenerRegistry;
import org.onosproject.net.DeviceId;
import org.onosproject.net.device.DeviceEvent;
import org.onosproject.net.device.DeviceListener;
......@@ -54,7 +48,12 @@ import org.onosproject.net.provider.AbstractProviderRegistry;
import org.onosproject.net.provider.AbstractProviderService;
import org.slf4j.Logger;
import com.google.common.collect.Sets;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
import java.util.Set;
import static org.slf4j.LoggerFactory.getLogger;
/**
* Provides implementation of the group service APIs.
......@@ -67,8 +66,8 @@ public class GroupManager
private final Logger log = getLogger(getClass());
private final AbstractListenerRegistry<GroupEvent, GroupListener>
listenerRegistry = new AbstractListenerRegistry<>();
private final ListenerRegistry<GroupEvent, GroupListener>
listenerRegistry = new ListenerRegistry<>();
private final GroupStoreDelegate delegate = new InternalGroupStoreDelegate();
private final DeviceListener deviceListener = new InternalDeviceListener();
......
......@@ -15,19 +15,17 @@
*/
package org.onosproject.net.host.impl;
import static com.google.common.base.Preconditions.checkNotNull;
import static org.slf4j.LoggerFactory.getLogger;
import java.util.Set;
import org.apache.felix.scr.annotations.Activate;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Deactivate;
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.AbstractListenerRegistry;
import org.onlab.packet.IpAddress;
import org.onlab.packet.MacAddress;
import org.onlab.packet.VlanId;
import org.onosproject.event.EventDeliveryService;
import org.onosproject.event.ListenerRegistry;
import org.onosproject.net.ConnectPoint;
import org.onosproject.net.DeviceId;
import org.onosproject.net.Host;
......@@ -47,11 +45,13 @@ import org.onosproject.net.host.PortAddresses;
import org.onosproject.net.packet.PacketService;
import org.onosproject.net.provider.AbstractProviderRegistry;
import org.onosproject.net.provider.AbstractProviderService;
import org.onlab.packet.IpAddress;
import org.onlab.packet.MacAddress;
import org.onlab.packet.VlanId;
import org.slf4j.Logger;
import java.util.Set;
import static com.google.common.base.Preconditions.checkNotNull;
import static org.slf4j.LoggerFactory.getLogger;
/**
* Provides basic implementation of the host SB &amp; NB APIs.
*/
......@@ -64,8 +64,8 @@ public class HostManager
public static final String HOST_ID_NULL = "Host ID cannot be null";
private final Logger log = getLogger(getClass());
private final AbstractListenerRegistry<HostEvent, HostListener>
listenerRegistry = new AbstractListenerRegistry<>();
private final ListenerRegistry<HostEvent, HostListener>
listenerRegistry = new ListenerRegistry<>();
private HostStoreDelegate delegate = new InternalStoreDelegate();
......
......@@ -24,7 +24,7 @@ import org.apache.felix.scr.annotations.ReferenceCardinality;
import org.apache.felix.scr.annotations.Service;
import org.onosproject.core.CoreService;
import org.onosproject.core.IdGenerator;
import org.onosproject.event.AbstractListenerRegistry;
import org.onosproject.event.ListenerRegistry;
import org.onosproject.event.EventDeliveryService;
import org.onosproject.net.flow.FlowRule;
import org.onosproject.net.flow.FlowRuleOperations;
......@@ -83,8 +83,8 @@ public class IntentManager
private static final EnumSet<IntentState> RECOMPILE
= EnumSet.of(INSTALL_REQ, FAILED, WITHDRAW_REQ);
private final AbstractListenerRegistry<IntentEvent, IntentListener>
listenerRegistry = new AbstractListenerRegistry<>();
private final ListenerRegistry<IntentEvent, IntentListener>
listenerRegistry = new ListenerRegistry<>();
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected CoreService coreService;
......
......@@ -15,16 +15,17 @@
*/
package org.onosproject.net.link.impl;
import java.util.Set;
import com.google.common.base.Predicate;
import com.google.common.collect.FluentIterable;
import com.google.common.collect.Sets;
import org.apache.felix.scr.annotations.Activate;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Deactivate;
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.AbstractListenerRegistry;
import org.onosproject.event.EventDeliveryService;
import org.onosproject.event.ListenerRegistry;
import org.onosproject.net.ConnectPoint;
import org.onosproject.net.DeviceId;
import org.onosproject.net.Link;
......@@ -47,9 +48,7 @@ import org.onosproject.net.provider.AbstractProviderRegistry;
import org.onosproject.net.provider.AbstractProviderService;
import org.slf4j.Logger;
import com.google.common.base.Predicate;
import com.google.common.collect.FluentIterable;
import com.google.common.collect.Sets;
import java.util.Set;
import static com.google.common.base.Preconditions.checkNotNull;
import static org.slf4j.LoggerFactory.getLogger;
......@@ -69,8 +68,8 @@ public class LinkManager
private final Logger log = getLogger(getClass());
protected final AbstractListenerRegistry<LinkEvent, LinkListener>
listenerRegistry = new AbstractListenerRegistry<>();
protected final ListenerRegistry<LinkEvent, LinkListener>
listenerRegistry = new ListenerRegistry<>();
private final LinkStoreDelegate delegate = new InternalStoreDelegate();
......
......@@ -21,7 +21,7 @@ import org.apache.felix.scr.annotations.Deactivate;
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.AbstractListenerRegistry;
import org.onosproject.event.ListenerRegistry;
import org.onosproject.event.EventDeliveryService;
import org.onosproject.net.Link;
import org.onosproject.net.intent.IntentId;
......@@ -66,8 +66,8 @@ public class LinkResourceManager implements LinkResourceService {
private final Logger log = getLogger(getClass());
protected final AbstractListenerRegistry<LinkResourceEvent, LinkResourceListener>
listenerRegistry = new AbstractListenerRegistry<>();
protected final ListenerRegistry<LinkResourceEvent, LinkResourceListener>
listenerRegistry = new ListenerRegistry<>();
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
private LinkResourceStore store;
......
......@@ -21,7 +21,7 @@ import org.apache.felix.scr.annotations.Deactivate;
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.AbstractListenerRegistry;
import org.onosproject.event.ListenerRegistry;
import org.onosproject.event.Event;
import org.onosproject.event.EventDeliveryService;
import org.onosproject.net.ConnectPoint;
......@@ -69,8 +69,8 @@ public class TopologyManager
private final Logger log = getLogger(getClass());
private final AbstractListenerRegistry<TopologyEvent, TopologyListener>
listenerRegistry = new AbstractListenerRegistry<>();
private final ListenerRegistry<TopologyEvent, TopologyListener>
listenerRegistry = new ListenerRegistry<>();
private TopologyStoreDelegate delegate = new InternalStoreDelegate();
......
......@@ -15,12 +15,6 @@
*/
package org.onosproject.net.tunnel.impl;
import static org.slf4j.LoggerFactory.getLogger;
import java.util.Collection;
import java.util.Set;
import java.util.concurrent.ExecutorService;
import org.apache.felix.scr.annotations.Activate;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Deactivate;
......@@ -28,8 +22,8 @@ import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.ReferenceCardinality;
import org.apache.felix.scr.annotations.Service;
import org.onosproject.core.CoreService;
import org.onosproject.event.AbstractListenerRegistry;
import org.onosproject.event.EventDeliveryService;
import org.onosproject.event.ListenerRegistry;
import org.onosproject.net.ConnectPoint;
import org.onosproject.net.DeviceId;
import org.onosproject.net.Path;
......@@ -41,6 +35,7 @@ import org.onosproject.net.provider.ProviderId;
import org.onosproject.net.resource.BandwidthResource;
import org.onosproject.net.tunnel.Label;
import org.onosproject.net.tunnel.Tunnel;
import org.onosproject.net.tunnel.Tunnel.Type;
import org.onosproject.net.tunnel.TunnelAdminService;
import org.onosproject.net.tunnel.TunnelDescription;
import org.onosproject.net.tunnel.TunnelEvent;
......@@ -52,9 +47,14 @@ import org.onosproject.net.tunnel.TunnelProviderService;
import org.onosproject.net.tunnel.TunnelService;
import org.onosproject.net.tunnel.TunnelStore;
import org.onosproject.net.tunnel.TunnelStoreDelegate;
import org.onosproject.net.tunnel.Tunnel.Type;
import org.slf4j.Logger;
import java.util.Collection;
import java.util.Set;
import java.util.concurrent.ExecutorService;
import static org.slf4j.LoggerFactory.getLogger;
/**
* Provides implementation of the tunnel NB/SB APIs.
*/
......@@ -67,8 +67,8 @@ public class TunnelManager extends AbstractProviderRegistry<TunnelProvider, Tunn
private final Logger log = getLogger(getClass());
protected final AbstractListenerRegistry<TunnelEvent, TunnelListener>
listenerRegistry = new AbstractListenerRegistry<>();
protected final ListenerRegistry<TunnelEvent, TunnelListener>
listenerRegistry = new ListenerRegistry<>();
private final TunnelStoreDelegate delegate = new InternalStoreDelegate();
private final InternalTunnelListener tunnelListener = new InternalTunnelListener();
......
......@@ -33,7 +33,7 @@ import org.onosproject.cluster.LeadershipEvent;
import org.onosproject.cluster.LeadershipEventListener;
import org.onosproject.cluster.LeadershipService;
import org.onosproject.cluster.NodeId;
import org.onosproject.event.AbstractListenerRegistry;
import org.onosproject.event.ListenerRegistry;
import org.onosproject.event.EventDeliveryService;
import org.onosproject.store.cluster.messaging.ClusterCommunicationService;
import org.onosproject.store.cluster.messaging.ClusterMessage;
......@@ -109,7 +109,7 @@ public class HazelcastLeadershipService implements LeadershipService {
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected EventDeliveryService eventDispatcher;
private AbstractListenerRegistry<LeadershipEvent, LeadershipEventListener>
private ListenerRegistry<LeadershipEvent, LeadershipEventListener>
listenerRegistry;
private final Map<String, Topic> topics = Maps.newConcurrentMap();
private NodeId localNodeId;
......@@ -122,7 +122,7 @@ public class HazelcastLeadershipService implements LeadershipService {
@Activate
protected void activate() {
localNodeId = clusterService.getLocalNode().id();
listenerRegistry = new AbstractListenerRegistry<>();
listenerRegistry = new ListenerRegistry<>();
eventDispatcher.addSink(LeadershipEvent.class, listenerRegistry);
TopicConfig topicConfig = new TopicConfig();
......
......@@ -19,7 +19,7 @@ import org.onosproject.cluster.LeadershipEvent;
import org.onosproject.cluster.LeadershipEventListener;
import org.onosproject.cluster.LeadershipService;
import org.onosproject.cluster.NodeId;
import org.onosproject.event.AbstractListenerRegistry;
import org.onosproject.event.ListenerRegistry;
import org.onosproject.event.EventDeliveryService;
import org.onosproject.store.cluster.messaging.ClusterCommunicationService;
import org.onosproject.store.cluster.messaging.MessageSubject;
......@@ -85,7 +85,7 @@ public class DistributedLeadershipManager implements LeadershipService {
private ConsistentMap<String, NodeId> leaderMap;
private ConsistentMap<String, List<NodeId>> candidateMap;
private AbstractListenerRegistry<LeadershipEvent, LeadershipEventListener>
private ListenerRegistry<LeadershipEvent, LeadershipEventListener>
listenerRegistry;
private final Map<String, Leadership> leaderBoard = Maps.newConcurrentMap();
private final Map<String, Leadership> candidateBoard = Maps.newConcurrentMap();
......@@ -135,7 +135,7 @@ public class DistributedLeadershipManager implements LeadershipService {
leadershipStatusBroadcaster.scheduleWithFixedDelay(
this::sendLeadershipStatus, 0, LEADERSHIP_STATUS_UPDATE_INTERVAL_SEC, TimeUnit.SECONDS);
listenerRegistry = new AbstractListenerRegistry<>();
listenerRegistry = new ListenerRegistry<>();
eventDispatcher.addSink(LeadershipEvent.class, listenerRegistry);
log.info("Started");
......
......@@ -15,15 +15,9 @@
*/
package org.onosproject.store.flow.impl;
import static com.google.common.base.Preconditions.checkNotNull;
import static org.slf4j.LoggerFactory.getLogger;
import static org.onosproject.store.flow.ReplicaInfoEvent.Type.MASTER_CHANGED;
import static org.onosproject.store.flow.ReplicaInfoEvent.Type.BACKUPS_CHANGED;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import com.google.common.base.Objects;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Maps;
import org.apache.felix.scr.annotations.Activate;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Deactivate;
......@@ -32,8 +26,8 @@ import org.apache.felix.scr.annotations.ReferenceCardinality;
import org.apache.felix.scr.annotations.Service;
import org.onosproject.cluster.NodeId;
import org.onosproject.cluster.RoleInfo;
import org.onosproject.event.AbstractListenerRegistry;
import org.onosproject.event.EventDeliveryService;
import org.onosproject.event.ListenerRegistry;
import org.onosproject.mastership.MastershipEvent;
import org.onosproject.mastership.MastershipListener;
import org.onosproject.mastership.MastershipService;
......@@ -44,9 +38,14 @@ import org.onosproject.store.flow.ReplicaInfoEventListener;
import org.onosproject.store.flow.ReplicaInfoService;
import org.slf4j.Logger;
import com.google.common.base.Objects;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Maps;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import static com.google.common.base.Preconditions.checkNotNull;
import static org.onosproject.store.flow.ReplicaInfoEvent.Type.BACKUPS_CHANGED;
import static org.onosproject.store.flow.ReplicaInfoEvent.Type.MASTER_CHANGED;
import static org.slf4j.LoggerFactory.getLogger;
/**
* Manages replica placement information.
......@@ -65,8 +64,8 @@ public class ReplicaInfoManager implements ReplicaInfoService {
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected MastershipService mastershipService;
protected final AbstractListenerRegistry<ReplicaInfoEvent, ReplicaInfoEventListener>
listenerRegistry = new AbstractListenerRegistry<>();
protected final ListenerRegistry<ReplicaInfoEvent, ReplicaInfoEventListener>
listenerRegistry = new ListenerRegistry<>();
private final Map<DeviceId, ReplicaInfo> deviceReplicaInfoMap = Maps.newConcurrentMap();
......
......@@ -15,25 +15,18 @@
*/
package org.onosproject.store.flow.impl;
import static com.google.common.base.Preconditions.checkState;
import static org.junit.Assert.*;
import java.util.Collections;
import java.util.Map;
import java.util.LinkedList;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import com.google.common.base.Optional;
import com.google.common.collect.Maps;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.onosproject.cluster.NodeId;
import org.onosproject.cluster.RoleInfo;
import org.onosproject.event.AbstractListenerRegistry;
import org.onosproject.event.DefaultEventSinkRegistry;
import org.onosproject.event.Event;
import org.onosproject.event.EventDeliveryService;
import org.onosproject.event.EventSink;
import org.onosproject.event.ListenerRegistry;
import org.onosproject.mastership.MastershipEvent;
import org.onosproject.mastership.MastershipEvent.Type;
import org.onosproject.mastership.MastershipListener;
......@@ -45,8 +38,15 @@ import org.onosproject.store.flow.ReplicaInfoEvent;
import org.onosproject.store.flow.ReplicaInfoEventListener;
import org.onosproject.store.flow.ReplicaInfoService;
import com.google.common.base.Optional;
import com.google.common.collect.Maps;
import java.util.Collections;
import java.util.LinkedList;
import java.util.Map;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import static com.google.common.base.Preconditions.checkState;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
public class ReplicaInfoManagerTest {
......@@ -58,14 +58,14 @@ public class ReplicaInfoManagerTest {
private ReplicaInfoManager mgr;
private ReplicaInfoService service;
private AbstractListenerRegistry<MastershipEvent, MastershipListener>
private ListenerRegistry<MastershipEvent, MastershipListener>
mastershipListenerRegistry;
private TestEventDispatcher eventDispatcher;
@Before
public void setUp() throws Exception {
mastershipListenerRegistry = new AbstractListenerRegistry<>();
mastershipListenerRegistry = new ListenerRegistry<>();
mgr = new ReplicaInfoManager();
service = mgr;
......
......@@ -17,7 +17,7 @@
package org.onosproject.ui.impl.topo;
import org.onosproject.event.AbstractListenerRegistry;
import org.onosproject.event.ListenerRegistry;
import org.slf4j.Logger;
import java.util.HashSet;
......@@ -31,7 +31,7 @@ import static org.slf4j.LoggerFactory.getLogger;
*/
// package private
class ModelListenerRegistry
extends AbstractListenerRegistry<TopoUiEvent, TopoUiListener> {
extends ListenerRegistry<TopoUiEvent, TopoUiListener> {
private final Logger log = getLogger(getClass());
......@@ -58,4 +58,9 @@ class ModelListenerRegistry
removeListener(z);
}
}
@Override
protected boolean checkForNonRegistrant() {
return false;
}
}
......
......@@ -143,12 +143,7 @@ public class TopoUiModelManager implements TopoUiModelService {
@Override
public void removeListener(TopoUiListener listener) {
// we don't really care if the listener is not listed...
try {
listenerRegistry.removeListener(listener);
} catch (IllegalArgumentException e) {
log.debug("Oops, listener not registered: {}", listener);
}
listenerRegistry.removeListener(listener);
}
@Override
......