Thomas Vachuska
Committed by Gerrit Code Review

Adding some base-classes to eliminate event and listener boiler-plate code throu…

…ghout a number of subsystems.

Refactored all core components to take advantage of this; apps remain to be done.

Change-Id: Ib0935ba07ff81b0fa032534004ec9ac6187cbf22
Showing 55 changed files with 418 additions and 822 deletions
......@@ -18,13 +18,15 @@ package org.onosproject.app;
import org.onosproject.core.Application;
import org.onosproject.core.ApplicationId;
import org.onosproject.core.Permission;
import org.onosproject.event.ListenerService;
import java.util.Set;
/**
* Service for inspecting inventory of network control applications.
*/
public interface ApplicationService {
public interface ApplicationService
extends ListenerService<ApplicationEvent, ApplicationListener> {
/**
* Returns the set of all installed applications.
......@@ -65,18 +67,4 @@ public interface ApplicationService {
*/
Set<Permission> getPermissions(ApplicationId appId);
/**
* Adds the given listener for application lifecycle events.
*
* @param listener listener to be added
*/
void addListener(ApplicationListener listener);
/**
* Removes the specified listener for application lifecycle events.
*
* @param listener listener to be removed
*/
void removeListener(ApplicationListener listener);
}
......
......@@ -18,12 +18,14 @@ package org.onosproject.cluster;
import java.util.Set;
import org.joda.time.DateTime;
import org.onosproject.event.ListenerService;
/**
* Service for obtaining information about the individual nodes within
* the controller cluster.
*/
public interface ClusterService {
public interface ClusterService
extends ListenerService<ClusterEvent, ClusterEventListener> {
/**
* Returns the local controller node.
......@@ -63,18 +65,4 @@ public interface ClusterService {
*/
DateTime getLastUpdated(NodeId nodeId);
/**
* Adds the specified cluster event listener.
*
* @param listener the cluster listener
*/
void addListener(ClusterEventListener listener);
/**
* Removes the specified cluster event listener.
*
* @param listener the cluster listener
*/
void removeListener(ClusterEventListener listener);
}
......
......@@ -15,6 +15,8 @@
*/
package org.onosproject.cluster;
import org.onosproject.event.ListenerService;
import java.util.List;
import java.util.Map;
import java.util.Set;
......@@ -27,7 +29,8 @@ import java.util.concurrent.CompletableFuture;
* Listeners can be added to receive notifications asynchronously for various
* leadership contests.
*/
public interface LeadershipService {
public interface LeadershipService
extends ListenerService<LeadershipEvent, LeadershipEventListener> {
/**
* Returns the current leader for the topic.
......@@ -118,17 +121,4 @@ public interface LeadershipService {
*/
List<NodeId> getCandidates(String path);
/**
* Registers a event listener to be notified of leadership events.
*
* @param listener listener that will asynchronously notified of leadership events.
*/
void addListener(LeadershipEventListener listener);
/**
* Unregisters a event listener for leadership events.
*
* @param listener listener to be removed.
*/
void removeListener(LeadershipEventListener listener);
}
......
/*
* Copyright 2015 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.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.ReferenceCardinality;
/**
* Basis for components which need to export listener mechanism.
*/
@Component(componentAbstract = true)
public abstract class AbstractListenerManager<E extends Event, L extends EventListener<E>>
implements ListenerService<E, L> {
protected final ListenerRegistry<E, L> listenerRegistry = new ListenerRegistry<>();
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected EventDeliveryService eventDispatcher;
@Override
public void addListener(L listener) {
listenerRegistry.addListener(listener);
}
@Override
public void removeListener(L listener) {
listenerRegistry.removeListener(listener);
}
/**
* Safely posts the specified event to the local event dispatcher.
* If there is no event dispatcher or if the event is null, this method
* is a noop.
*
* @param event event to be posted; may be null
*/
protected void post(E event) {
if (event != null && eventDispatcher != null) {
eventDispatcher.post(event);
}
}
}
......@@ -28,7 +28,7 @@ import static org.slf4j.LoggerFactory.getLogger;
* listeners and dispatching events to them as part of event sink processing.
*/
public class ListenerRegistry<E extends Event, L extends EventListener<E>>
implements EventSink<E> {
implements ListenerService<E, L>, EventSink<E> {
private static final long LIMIT = 1_800; // ms
......@@ -42,22 +42,13 @@ public class ListenerRegistry<E extends Event, L extends EventListener<E>>
*/
protected final Set<L> listeners = new CopyOnWriteArraySet<>();
/**
* Adds the specified listener.
*
* @param listener listener to be added
*/
@Override
public void addListener(L listener) {
checkNotNull(listener, "Listener cannot be null");
listeners.add(listener);
}
/**
* Removes the specified listener.
*
* @param listener listener to be removed
*/
@Override
public void removeListener(L listener) {
checkNotNull(listener, "Listener cannot be null");
if (!listeners.remove(listener)) {
......
/*
* Copyright 2015 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;
/**
* Abstraction of a service capable of asynchronously notifying listeners.
*/
public interface ListenerService<E extends Event, L extends EventListener<E>> {
/**
* Adds the specified listener.
*
* @param listener listener to be added
*/
void addListener(L listener);
/**
* Removes the specified listener.
*
* @param listener listener to be removed
*/
void removeListener(L listener);
}
......@@ -20,6 +20,7 @@ import java.util.concurrent.CompletableFuture;
import org.onosproject.cluster.NodeId;
import org.onosproject.cluster.RoleInfo;
import org.onosproject.event.ListenerService;
import org.onosproject.net.DeviceId;
import org.onosproject.net.MastershipRole;
......@@ -29,7 +30,8 @@ import org.onosproject.net.MastershipRole;
* determining mastership, but is not responsible for actually applying it
* to the devices; this falls on the device service.
*/
public interface MastershipService {
public interface MastershipService
extends ListenerService<MastershipEvent, MastershipListener> {
/**
* Returns the role of the local node for the specified device, without
......@@ -84,18 +86,4 @@ public interface MastershipService {
*/
Set<DeviceId> getDevicesOf(NodeId nodeId);
/**
* Adds the specified mastership change listener.
*
* @param listener the mastership listener
*/
void addListener(MastershipListener listener);
/**
* Removes the specified mastership change listener.
*
* @param listener the mastership listener
*/
void removeListener(MastershipListener listener);
}
......
......@@ -15,6 +15,7 @@
*/
package org.onosproject.net.device;
import org.onosproject.event.ListenerService;
import org.onosproject.net.Device;
import org.onosproject.net.DeviceId;
import org.onosproject.net.MastershipRole;
......@@ -26,7 +27,8 @@ import java.util.List;
/**
* Service for interacting with the inventory of infrastructure devices.
*/
public interface DeviceService {
public interface DeviceService
extends ListenerService<DeviceEvent, DeviceListener> {
/**
* Returns the number of infrastructure devices known to the system.
......@@ -119,18 +121,4 @@ public interface DeviceService {
*/
boolean isAvailable(DeviceId deviceId);
/**
* Adds the specified device listener.
*
* @param listener device listener
*/
void addListener(DeviceListener listener);
/**
* Removes the specified device listener.
*
* @param listener device listener
*/
void removeListener(DeviceListener listener);
}
......
......@@ -15,6 +15,7 @@
*/
package org.onosproject.net.edge;
import org.onosproject.event.ListenerService;
import org.onosproject.net.ConnectPoint;
import org.onosproject.net.DeviceId;
import org.onosproject.net.flow.TrafficTreatment;
......@@ -27,7 +28,8 @@ import java.util.Optional;
* is considered an edge port if it is an active port and does not have an
* infrastructure link associated with it.
*/
public interface EdgePortService {
public interface EdgePortService
extends ListenerService<EdgePortEvent, EdgePortListener> {
/**
* Indicates whether or not the specified connection point is an edge point.
......@@ -70,18 +72,4 @@ public interface EdgePortService {
void emitPacket(DeviceId deviceId, ByteBuffer data,
Optional<TrafficTreatment> treatment);
/**
* Adds a listener for edge port events.
*
* @param listener listener to be added
*/
void addListener(EdgePortListener listener);
/**
* Removes the listener for edge port events.
*
* @param listener listener to be removed
*/
void removeListener(EdgePortListener listener);
}
......
......@@ -16,6 +16,7 @@
package org.onosproject.net.flow;
import org.onosproject.core.ApplicationId;
import org.onosproject.event.ListenerService;
import org.onosproject.net.DeviceId;
/**
......@@ -25,7 +26,8 @@ import org.onosproject.net.DeviceId;
* of the flow rules lies with the controller and the devices hold only the
* 'cached' copy.
*/
public interface FlowRuleService {
public interface FlowRuleService
extends ListenerService<FlowRuleEvent, FlowRuleListener> {
/**
* The topic used for obtaining globally unique ids.
......@@ -102,17 +104,4 @@ public interface FlowRuleService {
*/
void apply(FlowRuleOperations ops);
/**
* Adds the specified flow rule listener.
*
* @param listener flow rule listener
*/
void addListener(FlowRuleListener listener);
/**
* Removes the specified flow rule listener.
*
* @param listener flow rule listener
*/
void removeListener(FlowRuleListener listener);
}
......
......@@ -16,6 +16,7 @@
package org.onosproject.net.group;
import org.onosproject.core.ApplicationId;
import org.onosproject.event.ListenerService;
import org.onosproject.net.DeviceId;
/**
......@@ -32,7 +33,8 @@ import org.onosproject.net.DeviceId;
* where the master copy of the groups lies with the controller and
* the devices hold only the 'cached' copy.
*/
public interface GroupService {
public interface GroupService
extends ListenerService<GroupEvent, GroupListener> {
/**
* Creates a group in the specified device with the provided buckets.
......@@ -134,17 +136,4 @@ public interface GroupService {
*/
Iterable<Group> getGroups(DeviceId deviceId);
/**
* Adds the specified group listener.
*
* @param listener group listener
*/
void addListener(GroupListener listener);
/**
* Removes the specified group listener.
*
* @param listener group listener
*/
void removeListener(GroupListener listener);
}
......
......@@ -17,6 +17,7 @@ package org.onosproject.net.host;
import java.util.Set;
import org.onosproject.event.ListenerService;
import org.onosproject.net.ConnectPoint;
import org.onosproject.net.DeviceId;
import org.onosproject.net.Host;
......@@ -28,7 +29,8 @@ import org.onlab.packet.VlanId;
/**
* Service for interacting with the inventory of end-station hosts.
*/
public interface HostService {
public interface HostService
extends ListenerService<HostEvent, HostListener> {
/**
* Returns the number of end-station hosts known to the system.
......@@ -137,18 +139,4 @@ public interface HostService {
*/
Set<PortAddresses> getAddressBindingsForPort(ConnectPoint connectPoint);
/**
* Adds the specified host listener.
*
* @param listener host listener
*/
void addListener(HostListener listener);
/**
* Removes the specified host listener.
*
* @param listener host listener
*/
void removeListener(HostListener listener);
}
......
......@@ -17,6 +17,7 @@ package org.onosproject.net.intent;
import com.google.common.annotations.Beta;
import org.onosproject.event.ListenerService;
import java.util.List;
......@@ -24,7 +25,9 @@ import java.util.List;
* Service for application submitting or withdrawing their intents.
*/
@Beta
public interface IntentService {
public interface IntentService
extends ListenerService<IntentEvent, IntentListener> {
/**
* Submits an intent into the system.
* <p>
......@@ -117,17 +120,4 @@ public interface IntentService {
*/
Iterable<Intent> getPending();
/**
* Adds the specified listener for intent events.
*
* @param listener listener to be added
*/
void addListener(IntentListener listener);
/**
* Removes the specified listener for intent events.
*
* @param listener listener to be removed
*/
void removeListener(IntentListener listener);
}
......
......@@ -17,12 +17,14 @@ package org.onosproject.net.intent;
import com.google.common.annotations.Beta;
import org.onosproject.cluster.NodeId;
import org.onosproject.event.ListenerService;
/**
* Service for interacting with the partition-to-instance assignments.
*/
@Beta
public interface PartitionService {
public interface PartitionService
extends ListenerService<PartitionEvent, PartitionEventListener> {
/**
* Returns whether the given intent key is in a partition owned by this
......@@ -43,17 +45,4 @@ public interface PartitionService {
// TODO add API for rebalancing partitions
/**
* Registers a event listener to be notified of partition events.
*
* @param listener listener that will asynchronously notified of partition events.
*/
void addListener(PartitionEventListener listener);
/**
* Unregisters a event listener for partition events.
*
* @param listener listener to be removed.
*/
void removeListener(PartitionEventListener listener);
}
......
......@@ -17,6 +17,7 @@ package org.onosproject.net.link;
import java.util.Set;
import org.onosproject.event.ListenerService;
import org.onosproject.net.ConnectPoint;
import org.onosproject.net.DeviceId;
import org.onosproject.net.Link;
......@@ -24,7 +25,8 @@ import org.onosproject.net.Link;
/**
* Service for interacting with the inventory of infrastructure links.
*/
public interface LinkService {
public interface LinkService
extends ListenerService<LinkEvent, LinkListener> {
/**
* Returns the count of all known infrastructure links.
......@@ -111,18 +113,4 @@ public interface LinkService {
*/
Link getLink(ConnectPoint src, ConnectPoint dst);
/**
* Adds the specified link listener.
*
* @param listener link listener
*/
void addListener(LinkListener listener);
/**
* Removes the specified link listener.
*
* @param listener link listener
*/
void removeListener(LinkListener listener);
}
......
/*
* Copyright 2015 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.net.provider;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.ReferenceCardinality;
import org.onosproject.event.Event;
import org.onosproject.event.EventDeliveryService;
import org.onosproject.event.EventListener;
import org.onosproject.event.ListenerRegistry;
import org.onosproject.event.ListenerService;
/**
* Basis for components which need to export listener mechanism.
*/
@Component(componentAbstract = true)
public abstract class AbstractListenerProviderRegistry<E extends Event, L extends EventListener<E>,
P extends Provider, S extends ProviderService<P>>
extends AbstractProviderRegistry<P, S> implements ListenerService<E, L> {
// If only Java supported mixins...
protected final ListenerRegistry<E, L> listenerRegistry = new ListenerRegistry<>();
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected EventDeliveryService eventDispatcher;
@Override
public void addListener(L listener) {
listenerRegistry.addListener(listener);
}
@Override
public void removeListener(L listener) {
listenerRegistry.removeListener(listener);
}
/**
* Safely posts the specified event to the local event dispatcher.
* If there is no event dispatcher or if the event is null, this method
* is a noop.
*
* @param event event to be posted; may be null
*/
protected void post(E event) {
if (event != null && eventDispatcher != null) {
eventDispatcher.post(event);
}
}
}
......@@ -15,6 +15,7 @@
*/
package org.onosproject.net.resource.link;
import org.onosproject.event.ListenerService;
import org.onosproject.net.Link;
import org.onosproject.net.intent.IntentId;
import org.onosproject.net.resource.ResourceRequest;
......@@ -22,7 +23,8 @@ import org.onosproject.net.resource.ResourceRequest;
/**
* Service for providing link resource allocation.
*/
public interface LinkResourceService {
public interface LinkResourceService
extends ListenerService<LinkResourceEvent, LinkResourceListener> {
/**
* Requests resources.
......@@ -88,20 +90,6 @@ public interface LinkResourceService {
* @return available resources for the target link
*/
Iterable<ResourceRequest> getAvailableResources(Link link,
LinkResourceAllocations allocations);
/**
* Adds a listener for resource related events.
*
* @param listener listener to add
*/
void addListener(LinkResourceListener listener);
/**
* Removes a listener for resource related events.
*
* @param listener listener to remove.
*/
void removeListener(LinkResourceListener listener);
LinkResourceAllocations allocations);
}
......
......@@ -15,6 +15,7 @@
*/
package org.onosproject.net.topology;
import org.onosproject.event.ListenerService;
import org.onosproject.net.ConnectPoint;
import org.onosproject.net.DeviceId;
import org.onosproject.net.Link;
......@@ -25,7 +26,8 @@ import java.util.Set;
/**
* Service for providing network topology information.
*/
public interface TopologyService {
public interface TopologyService
extends ListenerService<TopologyEvent, TopologyListener> {
/**
* Returns the current topology descriptor.
......@@ -130,18 +132,4 @@ public interface TopologyService {
*/
boolean isBroadcastPoint(Topology topology, ConnectPoint connectPoint);
/**
* Adds the specified topology listener.
*
* @param listener topology listener
*/
void addListener(TopologyListener listener);
/**
* Removes the specified topology listener.
*
* @param listener topology listener
*/
void removeListener(TopologyListener listener);
}
......
......@@ -15,22 +15,24 @@
*/
package org.onosproject.net;
import org.onlab.packet.ChassisId;
import org.onlab.packet.IpAddress;
import org.onosproject.TestApplicationId;
import org.onosproject.core.ApplicationId;
import org.onosproject.event.EventDeliveryService;
import org.onosproject.net.provider.ProviderId;
import org.onlab.packet.ChassisId;
import org.onlab.packet.IpAddress;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import static org.junit.Assert.assertEquals;
import static org.onlab.packet.MacAddress.valueOf;
import static org.onlab.packet.VlanId.vlanId;
import static org.onosproject.net.DeviceId.deviceId;
import static org.onosproject.net.HostId.hostId;
import static org.onosproject.net.PortNumber.portNumber;
import static org.onlab.packet.MacAddress.valueOf;
import static org.onlab.packet.VlanId.vlanId;
/**
* Miscellaneous tools for testing core related to the network model.
......@@ -98,8 +100,8 @@ public final class NetTestTools {
* Verifies that Annotations created by merging {@code annotations} is
* equal to actual Annotations.
*
* @param actual Annotations to check
* @param annotations
* @param actual annotations to check
* @param annotations expected annotations
*/
public static void assertAnnotationsEquals(Annotations actual, SparseAnnotations... annotations) {
DefaultAnnotations expected = DefaultAnnotations.builder().build();
......@@ -112,4 +114,25 @@ public final class NetTestTools {
}
}
/**
* Injects the given event delivery service into the specified manager
* component.
*
* @param manager manager component
* @param svc service reference to be injected
*/
public static void injectEventDispatcher(Object manager, EventDeliveryService svc) {
Class mc = manager.getClass();
for (Field f : mc.getSuperclass().getDeclaredFields()) {
if (f.getType().equals(EventDeliveryService.class)) {
try {
f.setAccessible(true);
f.set(manager, svc);
} catch (IllegalAccessException e) {
throw new IllegalArgumentException("Unable to inject reference", e);
}
}
}
}
}
......
......@@ -49,25 +49,6 @@
<artifactId>easymock</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.compendium</artifactId>
</dependency>
<dependency>
<groupId>org.apache.felix</groupId>
<artifactId>org.apache.felix.scr.annotations</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-scr-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
......
/*
* Copyright 2015 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.
*/
/**
* Miscellaneous common facilities used for construction of various core and
* app subsystems.
*/
package org.onosproject.common;
\ No newline at end of file
......@@ -78,11 +78,6 @@
</dependency>
<dependency>
<groupId>org.apache.felix</groupId>
<artifactId>org.apache.felix.scr.annotations</artifactId>
</dependency>
<dependency>
<groupId>org.apache.karaf.features</groupId>
<artifactId>org.apache.karaf.features.core</artifactId>
</dependency>
......@@ -93,13 +88,4 @@
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-scr-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
......
......@@ -30,11 +30,10 @@ import org.onosproject.app.ApplicationService;
import org.onosproject.app.ApplicationState;
import org.onosproject.app.ApplicationStore;
import org.onosproject.app.ApplicationStoreDelegate;
import org.onosproject.event.AbstractListenerManager;
import org.onosproject.core.Application;
import org.onosproject.core.ApplicationId;
import org.onosproject.core.Permission;
import org.onosproject.event.ListenerRegistry;
import org.onosproject.event.EventDeliveryService;
import org.slf4j.Logger;
import java.io.InputStream;
......@@ -50,15 +49,14 @@ import static org.slf4j.LoggerFactory.getLogger;
*/
@Component(immediate = true)
@Service
public class ApplicationManager implements ApplicationService, ApplicationAdminService {
public class ApplicationManager
extends AbstractListenerManager<ApplicationEvent, ApplicationListener>
implements ApplicationService, ApplicationAdminService {
private final Logger log = getLogger(getClass());
private static final String APP_ID_NULL = "Application ID cannot be null";
protected final ListenerRegistry<ApplicationEvent, ApplicationListener>
listenerRegistry = new ListenerRegistry<>();
private final ApplicationStoreDelegate delegate = new InternalStoreDelegate();
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
......@@ -67,9 +65,6 @@ public class ApplicationManager implements ApplicationService, ApplicationAdminS
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected FeaturesService featuresService;
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected EventDeliveryService eventDispatcher;
private boolean initializing;
@Activate
......@@ -99,7 +94,6 @@ public class ApplicationManager implements ApplicationService, ApplicationAdminS
@Override
public ApplicationId getId(String name) {
checkPermission(Permission.APP_READ);
checkNotNull(name, "Name cannot be null");
return store.getId(name);
}
......@@ -160,18 +154,6 @@ public class ApplicationManager implements ApplicationService, ApplicationAdminS
store.setPermissions(appId, permissions);
}
@Override
public void addListener(ApplicationListener listener) {
checkPermission(Permission.APP_EVENT);
listenerRegistry.addListener(listener);
}
@Override
public void removeListener(ApplicationListener listener) {
checkPermission(Permission.APP_EVENT);
listenerRegistry.removeListener(listener);
}
private class InternalStoreDelegate implements ApplicationStoreDelegate {
@Override
public void notify(ApplicationEvent event) {
......@@ -199,7 +181,7 @@ public class ApplicationManager implements ApplicationService, ApplicationAdminS
}
}
eventDispatcher.post(event);
post(event);
} catch (Exception e) {
log.warn("Unable to perform operation on application " + app.id().name(), e);
......
......@@ -33,17 +33,16 @@ import org.onosproject.cluster.ClusterStore;
import org.onosproject.cluster.ClusterStoreDelegate;
import org.onosproject.cluster.ControllerNode;
import org.onosproject.cluster.NodeId;
import org.onosproject.event.AbstractListenerManager;
import org.onosproject.core.Permission;
import org.onosproject.event.ListenerRegistry;
import org.onosproject.event.EventDeliveryService;
import org.slf4j.Logger;
import java.util.Set;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
import static org.slf4j.LoggerFactory.getLogger;
import static org.onosproject.security.AppGuard.checkPermission;
import static org.slf4j.LoggerFactory.getLogger;
/**
......@@ -51,16 +50,15 @@ import static org.onosproject.security.AppGuard.checkPermission;
*/
@Component(immediate = true)
@Service
public class ClusterManager implements ClusterService, ClusterAdminService {
public class ClusterManager
extends AbstractListenerManager<ClusterEvent, ClusterEventListener>
implements ClusterService, ClusterAdminService {
public static final String INSTANCE_ID_NULL = "Instance ID cannot be null";
private final Logger log = getLogger(getClass());
private ClusterStoreDelegate delegate = new InternalStoreDelegate();
protected final ListenerRegistry<ClusterEvent, ClusterEventListener>
listenerRegistry = new ListenerRegistry<>();
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected ClusterDefinitionService clusterDefinitionService;
......@@ -68,9 +66,6 @@ public class ClusterManager implements ClusterService, ClusterAdminService {
protected ClusterStore store;
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected EventDeliveryService eventDispatcher;
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected SystemService systemService;
@Activate
......@@ -150,24 +145,11 @@ public class ClusterManager implements ClusterService, ClusterAdminService {
store.removeNode(nodeId);
}
@Override
public void addListener(ClusterEventListener listener) {
checkPermission(Permission.CLUSTER_EVENT);
listenerRegistry.addListener(listener);
}
@Override
public void removeListener(ClusterEventListener listener) {
checkPermission(Permission.CLUSTER_EVENT);
listenerRegistry.removeListener(listener);
}
// Store delegate to re-post events emitted from the store.
private class InternalStoreDelegate implements ClusterStoreDelegate {
@Override
public void notify(ClusterEvent event) {
checkNotNull(event, "Event cannot be null");
eventDispatcher.post(event);
post(event);
}
}
}
......
......@@ -19,7 +19,6 @@ import com.codahale.metrics.Timer;
import com.codahale.metrics.Timer.Context;
import com.google.common.collect.Lists;
import com.google.common.util.concurrent.Futures;
import org.apache.felix.scr.annotations.Activate;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Deactivate;
......@@ -31,10 +30,9 @@ import org.onosproject.cluster.ClusterService;
import org.onosproject.cluster.ControllerNode;
import org.onosproject.cluster.NodeId;
import org.onosproject.cluster.RoleInfo;
import org.onosproject.event.AbstractListenerManager;
import org.onosproject.core.MetricsHelper;
import org.onosproject.core.Permission;
import org.onosproject.event.ListenerRegistry;
import org.onosproject.event.EventDeliveryService;
import org.onosproject.mastership.MastershipAdminService;
import org.onosproject.mastership.MastershipEvent;
import org.onosproject.mastership.MastershipListener;
......@@ -62,13 +60,14 @@ import static org.onlab.metrics.MetricsUtil.startTimer;
import static org.onlab.metrics.MetricsUtil.stopTimer;
import static org.onosproject.cluster.ControllerNode.State.ACTIVE;
import static org.onosproject.net.MastershipRole.MASTER;
import static org.slf4j.LoggerFactory.getLogger;
import static org.onosproject.security.AppGuard.checkPermission;
import static org.slf4j.LoggerFactory.getLogger;
@Component(immediate = true)
@Service
public class MastershipManager
extends AbstractListenerManager<MastershipEvent, MastershipListener>
implements MastershipService, MastershipAdminService, MastershipTermService,
MetricsHelper {
......@@ -78,18 +77,12 @@ public class MastershipManager
private final Logger log = getLogger(getClass());
protected final ListenerRegistry<MastershipEvent, MastershipListener>
listenerRegistry = new ListenerRegistry<>();
private final MastershipStoreDelegate delegate = new InternalDelegate();
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected MastershipStore store;
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected EventDeliveryService eventDispatcher;
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected ClusterService clusterService;
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
......@@ -197,22 +190,6 @@ public class MastershipManager
}
@Override
public void addListener(MastershipListener listener) {
checkPermission(Permission.CLUSTER_EVENT);
checkNotNull(listener);
listenerRegistry.addListener(listener);
}
@Override
public void removeListener(MastershipListener listener) {
checkPermission(Permission.CLUSTER_EVENT);
checkNotNull(listener);
listenerRegistry.removeListener(listener);
}
@Override
public MetricsService metricsService() {
return metricsService;
}
......@@ -294,21 +271,11 @@ public class MastershipManager
}
// Posts the specified event to the local event dispatcher.
private void post(MastershipEvent event) {
if (event != null && eventDispatcher != null) {
eventDispatcher.post(event);
}
}
public class InternalDelegate implements MastershipStoreDelegate {
@Override
public void notify(MastershipEvent event) {
log.trace("dispatching mastership event {}", event);
eventDispatcher.post(event);
post(event);
}
}
}
......
......@@ -26,9 +26,8 @@ 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.AbstractListenerManager;
import org.onosproject.event.Event;
import org.onosproject.event.EventDeliveryService;
import org.onosproject.event.ListenerRegistry;
import org.onosproject.net.ConnectPoint;
import org.onosproject.net.DeviceId;
import org.onosproject.net.device.DeviceEvent;
......@@ -64,7 +63,9 @@ import static org.slf4j.LoggerFactory.getLogger;
*/
@Component(immediate = true)
@Service
public class EdgeManager implements EdgePortService {
public class EdgeManager
extends AbstractListenerManager<EdgePortEvent, EdgePortListener>
implements EdgePortService {
private final Logger log = getLogger(getClass());
......@@ -72,15 +73,9 @@ public class EdgeManager implements EdgePortService {
private final Map<DeviceId, Set<ConnectPoint>> connectionPoints = Maps.newConcurrentMap();
private final ListenerRegistry<EdgePortEvent, EdgePortListener>
listenerRegistry = new ListenerRegistry<>();
private final TopologyListener topologyListener = new InnerTopologyListener();
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected EventDeliveryService eventDispatcher;
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected PacketService packetService;
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
......@@ -147,17 +142,6 @@ public class EdgeManager implements EdgePortService {
return new DefaultOutboundPacket(point.deviceId(), builder.build(), data);
}
@Override
public void addListener(EdgePortListener listener) {
listenerRegistry.addListener(listener);
}
@Override
public void removeListener(EdgePortListener listener) {
listenerRegistry.removeListener(listener);
}
// Internal listener for topo events used to keep our edge-port cache
// up to date.
private class InnerTopologyListener implements TopologyListener {
......@@ -234,7 +218,7 @@ public class EdgeManager implements EdgePortService {
connectionPoints.put(point.deviceId(), set);
}
if (set.add(point)) {
eventDispatcher.post(new EdgePortEvent(EDGE_PORT_ADDED, point));
post(new EdgePortEvent(EDGE_PORT_ADDED, point));
}
}
}
......@@ -247,7 +231,7 @@ public class EdgeManager implements EdgePortService {
return;
}
if (set.remove(point)) {
eventDispatcher.post(new EdgePortEvent(EDGE_PORT_REMOVED, point));
post(new EdgePortEvent(EDGE_PORT_REMOVED, point));
}
if (set.isEmpty()) {
connectionPoints.remove(point.deviceId());
......
......@@ -32,12 +32,11 @@ import org.apache.felix.scr.annotations.ReferenceCardinality;
import org.apache.felix.scr.annotations.Service;
import org.onlab.util.Tools;
import org.onosproject.cfg.ComponentConfigService;
import org.onosproject.net.provider.AbstractListenerProviderRegistry;
import org.onosproject.core.ApplicationId;
import org.onosproject.core.CoreService;
import org.onosproject.core.IdGenerator;
import org.onosproject.core.Permission;
import org.onosproject.event.ListenerRegistry;
import org.onosproject.event.EventDeliveryService;
import org.onosproject.net.Device;
import org.onosproject.net.DeviceId;
import org.onosproject.net.device.DeviceService;
......@@ -60,7 +59,6 @@ import org.onosproject.net.flow.FlowRuleProviderService;
import org.onosproject.net.flow.FlowRuleService;
import org.onosproject.net.flow.FlowRuleStore;
import org.onosproject.net.flow.FlowRuleStoreDelegate;
import org.onosproject.net.provider.AbstractProviderRegistry;
import org.onosproject.net.provider.AbstractProviderService;
import org.osgi.service.component.ComponentContext;
import org.slf4j.Logger;
......@@ -77,8 +75,10 @@ import java.util.concurrent.atomic.AtomicBoolean;
import static com.google.common.base.Preconditions.checkNotNull;
import static org.onlab.util.Tools.groupedThreads;
import static org.slf4j.LoggerFactory.getLogger;
import static org.onosproject.net.flow.FlowRuleEvent.Type.RULE_ADD_REQUESTED;
import static org.onosproject.net.flow.FlowRuleEvent.Type.RULE_REMOVE_REQUESTED;
import static org.onosproject.security.AppGuard.checkPermission;
import static org.slf4j.LoggerFactory.getLogger;
/**
......@@ -87,7 +87,8 @@ import static org.onosproject.security.AppGuard.checkPermission;
@Component(immediate = true, enabled = true)
@Service
public class FlowRuleManager
extends AbstractProviderRegistry<FlowRuleProvider, FlowRuleProviderService>
extends AbstractListenerProviderRegistry<FlowRuleEvent, FlowRuleListener,
FlowRuleProvider, FlowRuleProviderService>
implements FlowRuleService, FlowRuleProviderRegistry {
public static final String FLOW_RULE_NULL = "FlowRule cannot be null";
......@@ -99,9 +100,6 @@ public class FlowRuleManager
private final Logger log = getLogger(getClass());
private final ListenerRegistry<FlowRuleEvent, FlowRuleListener>
listenerRegistry = new ListenerRegistry<>();
private final FlowRuleStoreDelegate delegate = new InternalStoreDelegate();
protected ExecutorService deviceInstallers =
......@@ -119,9 +117,6 @@ public class FlowRuleManager
protected FlowRuleStore store;
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected EventDeliveryService eventDispatcher;
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected DeviceService deviceService;
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
......@@ -171,14 +166,12 @@ public class FlowRuleManager
@Override
public int getFlowRuleCount() {
checkPermission(Permission.FLOWRULE_READ);
return store.getFlowRuleCount();
}
@Override
public Iterable<FlowEntry> getFlowEntries(DeviceId deviceId) {
checkPermission(Permission.FLOWRULE_READ);
return store.getFlowEntries(deviceId);
}
......@@ -207,7 +200,6 @@ public class FlowRuleManager
@Override
public void removeFlowRulesById(ApplicationId id) {
checkPermission(Permission.FLOWRULE_WRITE);
removeFlowRules(Iterables.toArray(getFlowRulesById(id), FlowRule.class));
}
......@@ -245,25 +237,10 @@ public class FlowRuleManager
@Override
public void apply(FlowRuleOperations ops) {
checkPermission(Permission.FLOWRULE_WRITE);
operationsService.submit(new FlowOperationsProcessor(ops));
}
@Override
public void addListener(FlowRuleListener listener) {
checkPermission(Permission.FLOWRULE_EVENT);
listenerRegistry.addListener(listener);
}
@Override
public void removeListener(FlowRuleListener listener) {
checkPermission(Permission.FLOWRULE_EVENT);
listenerRegistry.removeListener(listener);
}
@Override
protected FlowRuleProviderService createProviderService(
FlowRuleProvider provider) {
return new InternalFlowRuleProviderService(provider);
......@@ -408,13 +385,6 @@ public class FlowRuleManager
return false;
}
// Posts the specified event to the local event dispatcher.
private void post(FlowRuleEvent event) {
if (event != null) {
eventDispatcher.post(event);
}
}
@Override
public void pushFlowMetrics(DeviceId deviceId, Iterable<FlowEntry> flowEntries) {
Set<FlowEntry> storedRules = Sets.newHashSet(store.getFlowEntries(deviceId));
......@@ -473,16 +443,12 @@ public class FlowRuleManager
switch (op.operator()) {
case ADD:
eventDispatcher.post(
new FlowRuleEvent(
FlowRuleEvent.Type.RULE_ADD_REQUESTED,
op.target()));
post(new FlowRuleEvent(RULE_ADD_REQUESTED,
op.target()));
break;
case REMOVE:
eventDispatcher.post(
new FlowRuleEvent(
FlowRuleEvent.Type.RULE_REMOVE_REQUESTED,
op.target()));
post(new FlowRuleEvent(RULE_REMOVE_REQUESTED,
op.target()));
break;
case MODIFY:
//TODO: do something here when the time comes.
......
......@@ -24,9 +24,8 @@ import org.apache.felix.scr.annotations.Service;
import org.onlab.packet.IpAddress;
import org.onlab.packet.MacAddress;
import org.onlab.packet.VlanId;
import org.onosproject.net.provider.AbstractListenerProviderRegistry;
import org.onosproject.core.Permission;
import org.onosproject.event.EventDeliveryService;
import org.onosproject.event.ListenerRegistry;
import org.onosproject.incubator.net.config.NetworkConfigEvent;
import org.onosproject.incubator.net.config.NetworkConfigListener;
import org.onosproject.incubator.net.config.NetworkConfigService;
......@@ -51,7 +50,6 @@ import org.onosproject.net.host.HostStore;
import org.onosproject.net.host.HostStoreDelegate;
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.slf4j.Logger;
......@@ -59,9 +57,8 @@ import java.util.Set;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Preconditions.checkState;
import static org.slf4j.LoggerFactory.getLogger;
import static org.onosproject.security.AppGuard.checkPermission;
import static org.slf4j.LoggerFactory.getLogger;
/**
* Provides basic implementation of the host SB &amp; NB APIs.
......@@ -69,14 +66,12 @@ import static org.onosproject.security.AppGuard.checkPermission;
@Component(immediate = true)
@Service
public class HostManager
extends AbstractProviderRegistry<HostProvider, HostProviderService>
extends AbstractListenerProviderRegistry<HostEvent, HostListener, HostProvider, HostProviderService>
implements HostService, HostAdminService, HostProviderRegistry {
public static final String HOST_ID_NULL = "Host ID cannot be null";
private final Logger log = getLogger(getClass());
private final ListenerRegistry<HostEvent, HostListener>
listenerRegistry = new ListenerRegistry<>();
public static final String HOST_ID_NULL = "Host ID cannot be null";
private final NetworkConfigListener networkConfigListener = new InternalNetworkConfigListener();
......@@ -86,9 +81,6 @@ public class HostManager
protected HostStore store;
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected EventDeliveryService eventDispatcher;
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected DeviceService deviceService;
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
......@@ -101,12 +93,12 @@ public class HostManager
@Activate
public void activate() {
log.info("Started");
store.setDelegate(delegate);
eventDispatcher.addSink(HostEvent.class, listenerRegistry);
networkConfigService.addListener(networkConfigListener);
monitor = new HostMonitor(deviceService, packetService, this);
monitor = new HostMonitor(deviceService, packetService, this);
monitor.start();
log.info("Started");
}
@Deactivate
......@@ -120,28 +112,24 @@ public class HostManager
@Override
protected HostProviderService createProviderService(HostProvider provider) {
monitor.registerHostProvider(provider);
return new InternalHostProviderService(provider);
}
@Override
public int getHostCount() {
checkPermission(Permission.HOST_READ);
return store.getHostCount();
}
@Override
public Iterable<Host> getHosts() {
checkPermission(Permission.HOST_READ);
return store.getHosts();
}
@Override
public Host getHost(HostId hostId) {
checkPermission(Permission.HOST_READ);
checkNotNull(hostId, HOST_ID_NULL);
return store.getHost(hostId);
}
......@@ -149,14 +137,12 @@ public class HostManager
@Override
public Set<Host> getHostsByVlan(VlanId vlanId) {
checkPermission(Permission.HOST_READ);
return store.getHosts(vlanId);
}
@Override
public Set<Host> getHostsByMac(MacAddress mac) {
checkPermission(Permission.HOST_READ);
checkNotNull(mac, "MAC address cannot be null");
return store.getHosts(mac);
}
......@@ -164,7 +150,6 @@ public class HostManager
@Override
public Set<Host> getHostsByIp(IpAddress ip) {
checkPermission(Permission.HOST_READ);
checkNotNull(ip, "IP address cannot be null");
return store.getHosts(ip);
}
......@@ -172,7 +157,6 @@ public class HostManager
@Override
public Set<Host> getConnectedHosts(ConnectPoint connectPoint) {
checkPermission(Permission.HOST_READ);
checkNotNull(connectPoint, "Connection point cannot be null");
return store.getConnectedHosts(connectPoint);
}
......@@ -180,7 +164,6 @@ public class HostManager
@Override
public Set<Host> getConnectedHosts(DeviceId deviceId) {
checkPermission(Permission.HOST_READ);
checkNotNull(deviceId, "Device ID cannot be null");
return store.getConnectedHosts(deviceId);
}
......@@ -188,34 +171,18 @@ public class HostManager
@Override
public void startMonitoringIp(IpAddress ip) {
checkPermission(Permission.HOST_EVENT);
monitor.addMonitoringFor(ip);
}
@Override
public void stopMonitoringIp(IpAddress ip) {
checkPermission(Permission.HOST_EVENT);
monitor.stopMonitoring(ip);
}
@Override
public void requestMac(IpAddress ip) {
// TODO Auto-generated method stub
}
@Override
public void addListener(HostListener listener) {
checkPermission(Permission.HOST_EVENT);
listenerRegistry.addListener(listener);
}
@Override
public void removeListener(HostListener listener) {
checkPermission(Permission.HOST_EVENT);
listenerRegistry.removeListener(listener);
// FIXME!!!! Auto-generated method stub
}
@Override
......@@ -245,14 +212,12 @@ public class HostManager
@Override
public Set<PortAddresses> getAddressBindings() {
checkPermission(Permission.HOST_READ);
return store.getAddressBindings();
}
@Override
public Set<PortAddresses> getAddressBindingsForPort(ConnectPoint connectPoint) {
checkPermission(Permission.HOST_READ);
return store.getAddressBindingsForPort(connectPoint);
}
......@@ -326,13 +291,6 @@ public class HostManager
return DefaultAnnotations.union(originalAnnotations, newAnnotations);
}
// Posts the specified event to the local event dispatcher.
private void post(HostEvent event) {
if (event != null) {
eventDispatcher.post(event);
}
}
// Store delegate to re-post events emitted from the store.
private class InternalStoreDelegate implements HostStoreDelegate {
@Override
......
......@@ -22,11 +22,10 @@ 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.AbstractListenerManager;
import org.onosproject.core.CoreService;
import org.onosproject.core.IdGenerator;
import org.onosproject.core.Permission;
import org.onosproject.event.ListenerRegistry;
import org.onosproject.event.EventDeliveryService;
import org.onosproject.net.flow.FlowRule;
import org.onosproject.net.flow.FlowRuleOperations;
import org.onosproject.net.flow.FlowRuleOperationsContext;
......@@ -65,9 +64,8 @@ import static java.util.concurrent.Executors.newSingleThreadExecutor;
import static org.onlab.util.Tools.groupedThreads;
import static org.onosproject.net.intent.IntentState.*;
import static org.onosproject.net.intent.impl.phase.IntentProcessPhase.newInitialPhase;
import static org.slf4j.LoggerFactory.getLogger;
import static org.onosproject.security.AppGuard.checkPermission;
import static org.slf4j.LoggerFactory.getLogger;
/**
* An implementation of intent service.
......@@ -75,7 +73,9 @@ import static org.onosproject.security.AppGuard.checkPermission;
@Component(immediate = true)
@Service
public class IntentManager
extends AbstractListenerManager<IntentEvent, IntentListener>
implements IntentService, IntentExtensionService {
private static final Logger log = getLogger(IntentManager.class);
public static final String INTENT_NULL = "Intent cannot be null";
......@@ -86,9 +86,6 @@ public class IntentManager
private static final EnumSet<IntentState> RECOMPILE
= EnumSet.of(INSTALL_REQ, FAILED, WITHDRAW_REQ);
private final ListenerRegistry<IntentEvent, IntentListener>
listenerRegistry = new ListenerRegistry<>();
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected CoreService coreService;
......@@ -99,12 +96,8 @@ public class IntentManager
protected ObjectiveTrackerService trackerService;
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected EventDeliveryService eventDispatcher;
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected FlowRuleService flowRuleService;
private ExecutorService batchExecutor;
private ExecutorService workerExecutor;
......@@ -143,7 +136,6 @@ public class IntentManager
@Override
public void submit(Intent intent) {
checkPermission(Permission.INTENT_WRITE);
checkNotNull(intent, INTENT_NULL);
IntentData data = new IntentData(intent, IntentState.INSTALL_REQ, null);
store.addPending(data);
......@@ -152,7 +144,6 @@ public class IntentManager
@Override
public void withdraw(Intent intent) {
checkPermission(Permission.INTENT_WRITE);
checkNotNull(intent, INTENT_NULL);
IntentData data = new IntentData(intent, IntentState.WITHDRAW_REQ, null);
store.addPending(data);
......@@ -161,7 +152,6 @@ public class IntentManager
@Override
public void purge(Intent intent) {
checkPermission(Permission.INTENT_WRITE);
checkNotNull(intent, INTENT_NULL);
IntentData data = new IntentData(intent, IntentState.PURGE_REQ, null);
store.addPending(data);
......@@ -170,14 +160,12 @@ public class IntentManager
@Override
public Intent getIntent(Key key) {
checkPermission(Permission.INTENT_READ);
return store.getIntent(key);
}
@Override
public Iterable<Intent> getIntents() {
checkPermission(Permission.INTENT_READ);
return store.getIntents();
}
......@@ -190,14 +178,12 @@ public class IntentManager
@Override
public long getIntentCount() {
checkPermission(Permission.INTENT_READ);
return store.getIntentCount();
}
@Override
public IntentState getIntentState(Key intentKey) {
checkPermission(Permission.INTENT_READ);
checkNotNull(intentKey, INTENT_ID_NULL);
return store.getIntentState(intentKey);
}
......@@ -205,7 +191,6 @@ public class IntentManager
@Override
public List<Intent> getInstallableIntents(Key intentKey) {
checkPermission(Permission.INTENT_READ);
checkNotNull(intentKey, INTENT_ID_NULL);
return store.getInstallableIntents(intentKey);
}
......@@ -213,25 +198,10 @@ public class IntentManager
@Override
public boolean isLocal(Key intentKey) {
checkPermission(Permission.INTENT_READ);
return store.isMaster(intentKey);
}
@Override
public void addListener(IntentListener listener) {
checkPermission(Permission.INTENT_EVENT);
listenerRegistry.addListener(listener);
}
@Override
public void removeListener(IntentListener listener) {
checkPermission(Permission.INTENT_EVENT);
listenerRegistry.removeListener(listener);
}
@Override
public <T extends Intent> void registerCompiler(Class<T> cls, IntentCompiler<T> compiler) {
compilerRegistry.registerCompiler(cls, compiler);
}
......@@ -257,7 +227,7 @@ public class IntentManager
private class InternalStoreDelegate implements IntentStoreDelegate {
@Override
public void notify(IntentEvent event) {
eventDispatcher.post(event);
post(event);
}
@Override
......
......@@ -24,9 +24,8 @@ 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.net.provider.AbstractListenerProviderRegistry;
import org.onosproject.core.Permission;
import org.onosproject.event.EventDeliveryService;
import org.onosproject.event.ListenerRegistry;
import org.onosproject.incubator.net.config.NetworkConfigEvent;
import org.onosproject.incubator.net.config.NetworkConfigListener;
import org.onosproject.incubator.net.config.NetworkConfigService;
......@@ -53,7 +52,6 @@ import org.onosproject.net.link.LinkProviderService;
import org.onosproject.net.link.LinkService;
import org.onosproject.net.link.LinkStore;
import org.onosproject.net.link.LinkStoreDelegate;
import org.onosproject.net.provider.AbstractProviderRegistry;
import org.onosproject.net.provider.AbstractProviderService;
import org.slf4j.Logger;
......@@ -63,8 +61,8 @@ import java.util.Set;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Preconditions.checkState;
import static org.onosproject.net.LinkKey.linkKey;
import static org.slf4j.LoggerFactory.getLogger;
import static org.onosproject.security.AppGuard.checkPermission;
import static org.slf4j.LoggerFactory.getLogger;
/**
......@@ -73,7 +71,7 @@ import static org.onosproject.security.AppGuard.checkPermission;
@Component(immediate = true)
@Service
public class LinkManager
extends AbstractProviderRegistry<LinkProvider, LinkProviderService>
extends AbstractListenerProviderRegistry<LinkEvent, LinkListener, LinkProvider, LinkProviderService>
implements LinkService, LinkAdminService, LinkProviderRegistry {
private static final String DEVICE_ID_NULL = "Device ID cannot be null";
......@@ -82,9 +80,6 @@ public class LinkManager
private final Logger log = getLogger(getClass());
protected final ListenerRegistry<LinkEvent, LinkListener>
listenerRegistry = new ListenerRegistry<>();
private final LinkStoreDelegate delegate = new InternalStoreDelegate();
private final DeviceListener deviceListener = new InternalDeviceListener();
......@@ -98,9 +93,6 @@ public class LinkManager
protected DeviceService deviceService;
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected EventDeliveryService eventDispatcher;
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected NetworkConfigService networkConfigService;
@Activate
......@@ -124,21 +116,18 @@ public class LinkManager
@Override
public int getLinkCount() {
checkPermission(Permission.LINK_READ);
return store.getLinkCount();
}
@Override
public Iterable<Link> getLinks() {
checkPermission(Permission.LINK_READ);
return store.getLinks();
}
@Override
public Iterable<Link> getActiveLinks() {
checkPermission(Permission.LINK_READ);
return FluentIterable.from(getLinks())
.filter(new Predicate<Link>() {
......@@ -152,7 +141,6 @@ public class LinkManager
@Override
public Set<Link> getDeviceLinks(DeviceId deviceId) {
checkPermission(Permission.LINK_READ);
checkNotNull(deviceId, DEVICE_ID_NULL);
return Sets.union(store.getDeviceEgressLinks(deviceId),
store.getDeviceIngressLinks(deviceId));
......@@ -161,7 +149,6 @@ public class LinkManager
@Override
public Set<Link> getDeviceEgressLinks(DeviceId deviceId) {
checkPermission(Permission.LINK_READ);
checkNotNull(deviceId, DEVICE_ID_NULL);
return store.getDeviceEgressLinks(deviceId);
}
......@@ -169,7 +156,6 @@ public class LinkManager
@Override
public Set<Link> getDeviceIngressLinks(DeviceId deviceId) {
checkPermission(Permission.LINK_READ);
checkNotNull(deviceId, DEVICE_ID_NULL);
return store.getDeviceIngressLinks(deviceId);
}
......@@ -177,7 +163,6 @@ public class LinkManager
@Override
public Set<Link> getLinks(ConnectPoint connectPoint) {
checkPermission(Permission.LINK_READ);
checkNotNull(connectPoint, CONNECT_POINT_NULL);
return Sets.union(store.getEgressLinks(connectPoint),
store.getIngressLinks(connectPoint));
......@@ -186,7 +171,6 @@ public class LinkManager
@Override
public Set<Link> getEgressLinks(ConnectPoint connectPoint) {
checkPermission(Permission.LINK_READ);
checkNotNull(connectPoint, CONNECT_POINT_NULL);
return store.getEgressLinks(connectPoint);
}
......@@ -194,7 +178,6 @@ public class LinkManager
@Override
public Set<Link> getIngressLinks(ConnectPoint connectPoint) {
checkPermission(Permission.LINK_READ);
checkNotNull(connectPoint, CONNECT_POINT_NULL);
return store.getIngressLinks(connectPoint);
}
......@@ -202,7 +185,6 @@ public class LinkManager
@Override
public Link getLink(ConnectPoint src, ConnectPoint dst) {
checkPermission(Permission.LINK_READ);
checkNotNull(src, CONNECT_POINT_NULL);
checkNotNull(dst, CONNECT_POINT_NULL);
return store.getLink(src, dst);
......@@ -228,18 +210,6 @@ public class LinkManager
post(store.removeLink(src, dst));
}
@Override
public void addListener(LinkListener listener) {
checkPermission(Permission.LINK_EVENT);
listenerRegistry.addListener(listener);
}
@Override
public void removeListener(LinkListener listener) {
checkPermission(Permission.LINK_EVENT);
listenerRegistry.removeListener(listener);
}
// Auxiliary interceptor for device remove events to prune links that
// are associated with the removed device or its port.
private class InternalDeviceListener implements DeviceListener {
......@@ -376,13 +346,6 @@ public class LinkManager
}
}
// Posts the specified event to the local event dispatcher.
private void post(LinkEvent event) {
if (event != null) {
eventDispatcher.post(event);
}
}
// Store delegate to re-post events emitted from the store.
private class InternalStoreDelegate implements LinkStoreDelegate {
@Override
......
......@@ -22,11 +22,13 @@ 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.AbstractListenerManager;
import org.onosproject.core.Permission;
import org.onosproject.event.ListenerRegistry;
import org.onosproject.event.EventDeliveryService;
import org.onosproject.net.Link;
import org.onosproject.net.intent.IntentId;
import org.onosproject.net.resource.ResourceAllocation;
import org.onosproject.net.resource.ResourceRequest;
import org.onosproject.net.resource.ResourceType;
import org.onosproject.net.resource.link.BandwidthResourceAllocation;
import org.onosproject.net.resource.link.BandwidthResourceRequest;
import org.onosproject.net.resource.link.DefaultLinkResourceAllocations;
......@@ -43,9 +45,6 @@ import org.onosproject.net.resource.link.LinkResourceStoreDelegate;
import org.onosproject.net.resource.link.MplsLabel;
import org.onosproject.net.resource.link.MplsLabelResourceAllocation;
import org.onosproject.net.resource.link.MplsLabelResourceRequest;
import org.onosproject.net.resource.ResourceAllocation;
import org.onosproject.net.resource.ResourceRequest;
import org.onosproject.net.resource.ResourceType;
import org.slf4j.Logger;
import java.util.Collections;
......@@ -57,8 +56,8 @@ import java.util.Set;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
import static org.slf4j.LoggerFactory.getLogger;
import static org.onosproject.security.AppGuard.checkPermission;
import static org.slf4j.LoggerFactory.getLogger;
/**
......@@ -66,19 +65,15 @@ import static org.onosproject.security.AppGuard.checkPermission;
*/
@Component(immediate = true)
@Service
public class LinkResourceManager implements LinkResourceService {
public class LinkResourceManager
extends AbstractListenerManager<LinkResourceEvent, LinkResourceListener>
implements LinkResourceService {
private final Logger log = getLogger(getClass());
protected final ListenerRegistry<LinkResourceEvent, LinkResourceListener>
listenerRegistry = new ListenerRegistry<>();
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
private LinkResourceStore store;
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected EventDeliveryService eventDispatcher;
@Activate
public void activate() {
eventDispatcher.addSink(LinkResourceEvent.class, listenerRegistry);
......@@ -87,6 +82,7 @@ public class LinkResourceManager implements LinkResourceService {
@Deactivate
public void deactivate() {
eventDispatcher.removeSink(LinkResourceEvent.class);
log.info("Stopped");
}
......@@ -218,7 +214,6 @@ public class LinkResourceManager implements LinkResourceService {
@Override
public void releaseResources(LinkResourceAllocations allocations) {
checkPermission(Permission.LINK_WRITE);
final LinkResourceEvent event = store.releaseResources(allocations);
if (event != null) {
post(event);
......@@ -229,7 +224,6 @@ public class LinkResourceManager implements LinkResourceService {
public LinkResourceAllocations updateResources(LinkResourceRequest req,
LinkResourceAllocations oldAllocations) {
checkPermission(Permission.LINK_WRITE);
releaseResources(oldAllocations);
return requestResources(req);
}
......@@ -237,21 +231,18 @@ public class LinkResourceManager implements LinkResourceService {
@Override
public Iterable<LinkResourceAllocations> getAllocations() {
checkPermission(Permission.LINK_READ);
return store.getAllocations();
}
@Override
public Iterable<LinkResourceAllocations> getAllocations(Link link) {
checkPermission(Permission.LINK_READ);
return store.getAllocations(link);
}
@Override
public LinkResourceAllocations getAllocations(IntentId intentId) {
checkPermission(Permission.LINK_READ);
return store.getAllocations(intentId);
}
......@@ -291,29 +282,6 @@ public class LinkResourceManager implements LinkResourceService {
return result;
}
@Override
public void addListener(LinkResourceListener listener) {
checkPermission(Permission.LINK_EVENT);
listenerRegistry.addListener(listener);
}
@Override
public void removeListener(LinkResourceListener listener) {
checkPermission(Permission.LINK_EVENT);
listenerRegistry.removeListener(listener);
}
/**
* Posts the specified event to the local event dispatcher.
*/
private void post(LinkResourceEvent event) {
if (event != null) {
eventDispatcher.post(event);
}
}
/**
* Store delegate to re-post events emitted from the store.
*/
......
......@@ -21,15 +21,13 @@ 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.net.provider.AbstractListenerProviderRegistry;
import org.onosproject.core.Permission;
import org.onosproject.event.ListenerRegistry;
import org.onosproject.event.Event;
import org.onosproject.event.EventDeliveryService;
import org.onosproject.net.ConnectPoint;
import org.onosproject.net.DeviceId;
import org.onosproject.net.Link;
import org.onosproject.net.Path;
import org.onosproject.net.provider.AbstractProviderRegistry;
import org.onosproject.net.provider.AbstractProviderService;
import org.onosproject.net.topology.ClusterId;
import org.onosproject.net.topology.GraphDescription;
......@@ -51,8 +49,8 @@ import java.util.List;
import java.util.Set;
import static com.google.common.base.Preconditions.checkNotNull;
import static org.slf4j.LoggerFactory.getLogger;
import static org.onosproject.security.AppGuard.checkPermission;
import static org.slf4j.LoggerFactory.getLogger;
/**
* Provides basic implementation of the topology SB &amp; NB APIs.
......@@ -60,7 +58,8 @@ import static org.onosproject.security.AppGuard.checkPermission;
@Component(immediate = true)
@Service
public class TopologyManager
extends AbstractProviderRegistry<TopologyProvider, TopologyProviderService>
extends AbstractListenerProviderRegistry<TopologyEvent, TopologyListener,
TopologyProvider, TopologyProviderService>
implements TopologyService, TopologyProviderRegistry {
public static final String TOPOLOGY_NULL = "Topology cannot be null";
......@@ -71,18 +70,11 @@ public class TopologyManager
private final Logger log = getLogger(getClass());
private final ListenerRegistry<TopologyEvent, TopologyListener>
listenerRegistry = new ListenerRegistry<>();
private TopologyStoreDelegate delegate = new InternalStoreDelegate();
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected TopologyStore store;
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected EventDeliveryService eventDispatcher;
@Activate
public void activate() {
store.setDelegate(delegate);
......@@ -100,14 +92,12 @@ public class TopologyManager
@Override
public Topology currentTopology() {
checkPermission(Permission.TOPOLOGY_READ);
return store.currentTopology();
}
@Override
public boolean isLatest(Topology topology) {
checkPermission(Permission.TOPOLOGY_READ);
checkNotNull(topology, TOPOLOGY_NULL);
return store.isLatest(topology);
}
......@@ -115,7 +105,6 @@ public class TopologyManager
@Override
public Set<TopologyCluster> getClusters(Topology topology) {
checkPermission(Permission.TOPOLOGY_READ);
checkNotNull(topology, TOPOLOGY_NULL);
return store.getClusters(topology);
}
......@@ -123,7 +112,6 @@ public class TopologyManager
@Override
public TopologyCluster getCluster(Topology topology, ClusterId clusterId) {
checkPermission(Permission.TOPOLOGY_READ);
checkNotNull(topology, TOPOLOGY_NULL);
checkNotNull(topology, CLUSTER_ID_NULL);
return store.getCluster(topology, clusterId);
......@@ -132,7 +120,6 @@ public class TopologyManager
@Override
public Set<DeviceId> getClusterDevices(Topology topology, TopologyCluster cluster) {
checkPermission(Permission.TOPOLOGY_READ);
checkNotNull(topology, TOPOLOGY_NULL);
checkNotNull(topology, CLUSTER_NULL);
return store.getClusterDevices(topology, cluster);
......@@ -141,7 +128,6 @@ public class TopologyManager
@Override
public Set<Link> getClusterLinks(Topology topology, TopologyCluster cluster) {
checkPermission(Permission.TOPOLOGY_READ);
checkNotNull(topology, TOPOLOGY_NULL);
checkNotNull(topology, CLUSTER_NULL);
return store.getClusterLinks(topology, cluster);
......@@ -150,7 +136,6 @@ public class TopologyManager
@Override
public TopologyGraph getGraph(Topology topology) {
checkPermission(Permission.TOPOLOGY_READ);
checkNotNull(topology, TOPOLOGY_NULL);
return store.getGraph(topology);
}
......@@ -158,7 +143,6 @@ public class TopologyManager
@Override
public Set<Path> getPaths(Topology topology, DeviceId src, DeviceId dst) {
checkPermission(Permission.TOPOLOGY_READ);
checkNotNull(topology, TOPOLOGY_NULL);
checkNotNull(src, DEVICE_ID_NULL);
checkNotNull(dst, DEVICE_ID_NULL);
......@@ -179,7 +163,6 @@ public class TopologyManager
@Override
public boolean isInfrastructure(Topology topology, ConnectPoint connectPoint) {
checkPermission(Permission.TOPOLOGY_READ);
checkNotNull(topology, TOPOLOGY_NULL);
checkNotNull(connectPoint, CONNECTION_POINT_NULL);
return store.isInfrastructure(topology, connectPoint);
......@@ -188,26 +171,11 @@ public class TopologyManager
@Override
public boolean isBroadcastPoint(Topology topology, ConnectPoint connectPoint) {
checkPermission(Permission.TOPOLOGY_READ);
checkNotNull(topology, TOPOLOGY_NULL);
checkNotNull(connectPoint, CONNECTION_POINT_NULL);
return store.isBroadcastPoint(topology, connectPoint);
}
@Override
public void addListener(TopologyListener listener) {
checkPermission(Permission.TOPOLOGY_EVENT);
listenerRegistry.addListener(listener);
}
@Override
public void removeListener(TopologyListener listener) {
checkPermission(Permission.TOPOLOGY_EVENT);
listenerRegistry.removeListener(listener);
}
// Personalized host provider service issued to the supplied provider.
@Override
protected TopologyProviderService createProviderService(TopologyProvider provider) {
......@@ -231,7 +199,7 @@ public class TopologyManager
topoDescription, reasons);
if (event != null) {
log.info("Topology {} changed", event.subject());
eventDispatcher.post(event);
post(event);
}
}
}
......@@ -240,7 +208,7 @@ public class TopologyManager
private class InternalStoreDelegate implements TopologyStoreDelegate {
@Override
public void notify(TopologyEvent event) {
eventDispatcher.post(event);
post(event);
}
}
}
......
......@@ -41,6 +41,7 @@ import static org.onosproject.app.ApplicationEvent.Type.*;
import static org.onosproject.app.ApplicationState.ACTIVE;
import static org.onosproject.app.ApplicationState.INSTALLED;
import static org.onosproject.app.DefaultApplicationDescriptionTest.*;
import static org.onosproject.net.NetTestTools.injectEventDispatcher;
/**
* Test of the application manager implementation.
......@@ -54,7 +55,7 @@ public class ApplicationManagerTest {
@Before
public void setUp() {
mgr.eventDispatcher = new TestEventDispatcher();
injectEventDispatcher(mgr, new TestEventDispatcher());
mgr.featuresService = new TestFeaturesService();
mgr.store = new TestStore();
mgr.activate();
......
......@@ -41,6 +41,7 @@ import static org.junit.Assert.assertNull;
import static org.onosproject.net.MastershipRole.MASTER;
import static org.onosproject.net.MastershipRole.NONE;
import static org.onosproject.net.MastershipRole.STANDBY;
import static org.onosproject.net.NetTestTools.injectEventDispatcher;
/**
* Test codifying the mastership service contracts.
......@@ -60,7 +61,7 @@ public class MastershipManagerTest {
public void setUp() {
mgr = new MastershipManager();
service = mgr;
mgr.eventDispatcher = new TestEventDispatcher();
injectEventDispatcher(mgr, new TestEventDispatcher());
mgr.clusterService = new TestClusterService();
mgr.store = new TestSimpleMastershipStore(mgr.clusterService);
mgr.activate();
......@@ -70,7 +71,7 @@ public class MastershipManagerTest {
public void tearDown() {
mgr.deactivate();
mgr.clusterService = null;
mgr.eventDispatcher = null;
injectEventDispatcher(mgr, null);
mgr.store = null;
}
......
......@@ -15,12 +15,7 @@
*/
package org.onosproject.net.device.impl;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import java.util.concurrent.CompletableFuture;
import com.google.common.collect.Sets;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
......@@ -30,8 +25,8 @@ import org.onosproject.cluster.ClusterServiceAdapter;
import org.onosproject.cluster.ControllerNode;
import org.onosproject.cluster.DefaultControllerNode;
import org.onosproject.cluster.NodeId;
import org.onosproject.event.Event;
import org.onosproject.common.event.impl.TestEventDispatcher;
import org.onosproject.event.Event;
import org.onosproject.incubator.net.config.NetworkConfigServiceAdapter;
import org.onosproject.mastership.MastershipServiceAdapter;
import org.onosproject.mastership.MastershipTerm;
......@@ -57,21 +52,17 @@ import org.onosproject.net.provider.AbstractProvider;
import org.onosproject.net.provider.ProviderId;
import org.onosproject.store.trivial.SimpleDeviceStore;
import com.google.common.collect.Sets;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import java.util.concurrent.CompletableFuture;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.*;
import static org.onosproject.net.Device.Type.SWITCH;
import static org.onosproject.net.DeviceId.deviceId;
import static org.onosproject.net.device.DeviceEvent.Type.DEVICE_ADDED;
import static org.onosproject.net.device.DeviceEvent.Type.DEVICE_AVAILABILITY_CHANGED;
import static org.onosproject.net.device.DeviceEvent.Type.DEVICE_UPDATED;
import static org.onosproject.net.device.DeviceEvent.Type.PORT_ADDED;
import static org.onosproject.net.device.DeviceEvent.Type.PORT_REMOVED;
import static org.onosproject.net.device.DeviceEvent.Type.PORT_UPDATED;
import static org.onosproject.net.NetTestTools.injectEventDispatcher;
import static org.onosproject.net.device.DeviceEvent.Type.*;
/**
* Test codifying the device service & device provider service contracts.
......@@ -110,7 +101,7 @@ public class DeviceManagerTest {
admin = mgr;
registry = mgr;
mgr.store = new SimpleDeviceStore();
mgr.eventDispatcher = new TestEventDispatcher();
injectEventDispatcher(mgr, new TestEventDispatcher());
TestMastershipManager mastershipManager = new TestMastershipManager();
mgr.mastershipService = mastershipManager;
mgr.termService = mastershipManager;
......
......@@ -52,6 +52,7 @@ import java.util.Optional;
import java.util.Set;
import static org.junit.Assert.*;
import static org.onosproject.net.NetTestTools.injectEventDispatcher;
import static org.onosproject.net.device.DeviceEvent.Type.*;
import static org.onosproject.net.edge.EdgePortEvent.Type.EDGE_PORT_ADDED;
import static org.onosproject.net.edge.EdgePortEvent.Type.EDGE_PORT_REMOVED;
......@@ -78,7 +79,7 @@ public class EdgeManagerTest {
@Before
public void setUp() {
mgr = new EdgeManager();
mgr.eventDispatcher = new TestEventDispatcher();
injectEventDispatcher(mgr, new TestEventDispatcher());
testTopologyManager = new TestTopologyManager(infrastructurePorts);
mgr.topologyService = testTopologyManager;
mgr.deviceService = new TestDeviceManager(devices);
......
......@@ -80,6 +80,7 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.onosproject.net.NetTestTools.injectEventDispatcher;
import static org.onosproject.net.flow.FlowRuleEvent.Type.RULE_ADDED;
import static org.onosproject.net.flow.FlowRuleEvent.Type.RULE_ADD_REQUESTED;
import static org.onosproject.net.flow.FlowRuleEvent.Type.RULE_REMOVED;
......@@ -112,7 +113,7 @@ public class FlowRuleManagerTest {
public void setUp() {
mgr = new FlowRuleManager();
mgr.store = new SimpleFlowRuleStore();
mgr.eventDispatcher = new TestEventDispatcher();
injectEventDispatcher(mgr, new TestEventDispatcher());
mgr.deviceService = new TestDeviceService();
mgr.coreService = new TestCoreService();
mgr.operationsService = MoreExecutors.newDirectExecutorService();
......@@ -137,7 +138,7 @@ public class FlowRuleManagerTest {
registry.getProviders().contains(provider.id()));
service.removeListener(listener);
mgr.deactivate();
mgr.eventDispatcher = null;
injectEventDispatcher(mgr, null);
mgr.deviceService = null;
}
......
......@@ -20,6 +20,7 @@ import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.onosproject.net.NetTestTools.injectEventDispatcher;
import java.util.ArrayList;
import java.util.Arrays;
......@@ -89,7 +90,7 @@ public class GroupManagerTest {
groupService = mgr;
mgr.deviceService = new DeviceManager();
mgr.store = new SimpleGroupStore();
mgr.eventDispatcher = new TestEventDispatcher();
injectEventDispatcher(mgr, new TestEventDispatcher());
providerRegistry = mgr;
mgr.activate();
......@@ -110,7 +111,7 @@ public class GroupManagerTest {
providerRegistry.getProviders().contains(provider.id()));
mgr.removeListener(listener);
mgr.deactivate();
mgr.eventDispatcher = null;
injectEventDispatcher(mgr, null);
}
/**
......
......@@ -20,6 +20,7 @@ import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.onosproject.net.NetTestTools.injectEventDispatcher;
import static org.onosproject.net.host.HostEvent.Type.HOST_ADDED;
import static org.onosproject.net.host.HostEvent.Type.HOST_MOVED;
import static org.onosproject.net.host.HostEvent.Type.HOST_REMOVED;
......@@ -122,7 +123,7 @@ public class HostManagerTest {
public void setUp() {
mgr = new HostManager();
mgr.store = new SimpleHostStore();
mgr.eventDispatcher = new TestEventDispatcher();
injectEventDispatcher(mgr, new TestEventDispatcher());
registry = mgr;
mgr.networkConfigService = new TestNetworkConfigService();
mgr.activate();
......@@ -143,7 +144,7 @@ public class HostManagerTest {
mgr.removeListener(listener);
mgr.deactivate();
mgr.eventDispatcher = null;
injectEventDispatcher(mgr, null);
}
private void detect(HostId hid, MacAddress mac, VlanId vlan,
......
......@@ -63,6 +63,7 @@ import static org.hamcrest.Matchers.is;
import static org.junit.Assert.*;
import static org.onlab.junit.TestTools.assertAfter;
import static org.onlab.util.Tools.delay;
import static org.onosproject.net.NetTestTools.injectEventDispatcher;
import static org.onosproject.net.intent.IntentState.*;
import static org.onosproject.net.intent.IntentTestsMocks.MockFlowRule;
import static org.onosproject.net.intent.IntentTestsMocks.MockIntent;
......@@ -226,7 +227,7 @@ public class IntentManagerTest {
manager = new IntentManager();
flowRuleService = new MockFlowRuleService();
manager.store = new SimpleIntentStore();
manager.eventDispatcher = new TestEventDispatcher();
injectEventDispatcher(manager, new TestEventDispatcher());
manager.trackerService = new TestIntentTracker();
manager.flowRuleService = flowRuleService;
manager.coreService = new TestCoreManager();
......
......@@ -53,6 +53,7 @@ import static org.junit.Assert.*;
import static org.onosproject.net.DeviceId.deviceId;
import static org.onosproject.net.Link.Type.DIRECT;
import static org.onosproject.net.Link.Type.INDIRECT;
import static org.onosproject.net.NetTestTools.injectEventDispatcher;
import static org.onosproject.net.link.LinkEvent.Type.*;
/**
......@@ -95,7 +96,7 @@ public class LinkManagerTest {
admin = mgr;
registry = mgr;
mgr.store = new SimpleLinkStore();
mgr.eventDispatcher = new TestEventDispatcher();
injectEventDispatcher(mgr, new TestEventDispatcher());
mgr.deviceService = devmgr;
mgr.networkConfigService = new TestNetworkConfigService();
mgr.activate();
......
......@@ -100,8 +100,8 @@ public class DefaultTopologyProviderTest {
assertEquals(1, topologyChangedCounts.awaitAdvanceInterruptibly(0, 1, TimeUnit.SECONDS));
validateSubmission();
deviceService.post(new DeviceEvent(DEVICE_ADDED, device("z"), null));
linkService.post(new LinkEvent(LINK_ADDED, link("z", 1, "a", 4)));
deviceService.postEvent(new DeviceEvent(DEVICE_ADDED, device("z"), null));
linkService.postEvent(new LinkEvent(LINK_ADDED, link("z", 1, "a", 4)));
assertThat(topologyChangedCounts.awaitAdvanceInterruptibly(1, 1, TimeUnit.SECONDS),
is(greaterThanOrEqualTo(2)));
// Note: posting event, to trigger topologyChanged call,
......@@ -162,7 +162,7 @@ public class DefaultTopologyProviderTest {
return getDevices();
}
void post(DeviceEvent event) {
void postEvent(DeviceEvent event) {
eventDispatcher.post(event);
}
}
......@@ -187,7 +187,7 @@ public class DefaultTopologyProviderTest {
return getLinks();
}
void post(LinkEvent event) {
void postEvent(LinkEvent event) {
eventDispatcher.post(event);
}
}
......
......@@ -73,7 +73,7 @@ public class TopologyManagerTest {
registry = mgr;
mgr.store = new SimpleTopologyStore();
mgr.eventDispatcher = new TestEventDispatcher();
injectEventDispatcher(mgr, new TestEventDispatcher());
mgr.activate();
service.addListener(listener);
......
......@@ -57,6 +57,10 @@
<groupId>org.osgi</groupId>
<artifactId>org.osgi.compendium</artifactId>
</dependency>
<dependency>
<groupId>org.apache.felix</groupId>
<artifactId>org.apache.felix.scr.annotations</artifactId>
</dependency>
</dependencies>
<build>
......@@ -70,6 +74,11 @@
<groupId>org.onosproject</groupId>
<artifactId>onos-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-scr-plugin</artifactId>
</plugin>
</plugins>
</build>
......
......@@ -37,14 +37,6 @@
<artifactId>org.osgi.core</artifactId>
</dependency>
<dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.compendium</artifactId>
</dependency>
<dependency>
<groupId>org.apache.felix</groupId>
<artifactId>org.apache.felix.scr.annotations</artifactId>
</dependency>
<dependency>
<groupId>org.onosproject</groupId>
<artifactId>onos-api</artifactId>
</dependency>
......@@ -54,14 +46,4 @@
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-scr-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
\ No newline at end of file
......
......@@ -49,20 +49,6 @@
<classifier>tests</classifier>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.felix</groupId>
<artifactId>org.apache.felix.scr.annotations</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-scr-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
......
......@@ -17,6 +17,7 @@ package org.onosproject.incubator.net.config;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.google.common.annotations.Beta;
import org.onosproject.event.ListenerService;
import java.util.Set;
......@@ -26,7 +27,8 @@ import java.util.Set;
* should act on or configure the network.
*/
@Beta
public interface NetworkConfigService {
public interface NetworkConfigService
extends ListenerService<NetworkConfigEvent, NetworkConfigListener> {
/**
* Returns the set of subject classes for which configuration may be
......@@ -140,17 +142,4 @@ public interface NetworkConfigService {
*/
<S, C extends Config<S>> void removeConfig(S subject, Class<C> configClass);
/**
* Adds the specified network config listener.
*
* @param listener network config listener
*/
void addListener(NetworkConfigListener listener);
/**
* Removes the specified network config listener.
*
* @param listener network config listener
*/
void removeListener(NetworkConfigListener listener);
}
......
......@@ -4,6 +4,7 @@ import java.util.Collection;
import java.util.Set;
import com.google.common.annotations.Beta;
import org.onosproject.event.ListenerService;
import org.onosproject.net.DeviceId;
import com.google.common.collect.Multimap;
......@@ -12,7 +13,8 @@ import com.google.common.collect.Multimap;
* Service for providing label resource allocation.
*/
@Beta
public interface LabelResourceService {
public interface LabelResourceService
extends ListenerService<LabelResourceEvent, LabelResourceListener> {
/**
* Returns labels from resource pool by a specific device id.
......@@ -95,17 +97,4 @@ public interface LabelResourceService {
*/
LabelResourcePool getGlobalLabelResourcePool();
/**
* Adds the specified label resource listener.
*
* @param listener label resource listener
*/
void addListener(LabelResourceListener listener);
/**
* Removes the specified label resource listener.
*
* @param listener label resource listener
*/
void removeListener(LabelResourceListener listener);
}
......
......@@ -19,6 +19,7 @@ import java.util.Collection;
import com.google.common.annotations.Beta;
import org.onosproject.core.ApplicationId;
import org.onosproject.event.ListenerService;
import org.onosproject.incubator.net.tunnel.Tunnel.Type;
import org.onosproject.net.Annotations;
import org.onosproject.net.DeviceId;
......@@ -27,7 +28,8 @@ import org.onosproject.net.DeviceId;
* Service for interacting with the inventory of tunnels.
*/
@Beta
public interface TunnelService {
public interface TunnelService
extends ListenerService<TunnelEvent, TunnelListener> {
/**
* Borrows a specific tunnel. Annotations parameter is reserved.If there
......@@ -196,17 +198,4 @@ public interface TunnelService {
*/
Iterable<Tunnel> getTunnels(DeviceId deviceId);
/**
* Adds the specified tunnel listener.
*
* @param listener tunnel listener
*/
void addListener(TunnelListener listener);
/**
* Removes the specified tunnel listener.
*
* @param listener tunnel listener
*/
void removeListener(TunnelListener listener);
}
......
......@@ -56,6 +56,11 @@
</dependency>
<dependency>
<groupId>org.onosproject</groupId>
<artifactId>onos-core-common</artifactId>
</dependency>
<dependency>
<groupId>org.easymock</groupId>
<artifactId>easymock</artifactId>
<scope>test</scope>
......
......@@ -24,8 +24,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.EventDeliveryService;
import org.onosproject.event.ListenerRegistry;
import org.onosproject.event.AbstractListenerManager;
import org.onosproject.incubator.net.config.Config;
import org.onosproject.incubator.net.config.ConfigFactory;
import org.onosproject.incubator.net.config.NetworkConfigEvent;
......@@ -49,7 +48,9 @@ import static com.google.common.base.Preconditions.checkNotNull;
*/
@Component(immediate = true)
@Service
public class NetworkConfigManager implements NetworkConfigRegistry, NetworkConfigService {
public class NetworkConfigManager
extends AbstractListenerManager<NetworkConfigEvent, NetworkConfigListener>
implements NetworkConfigRegistry, NetworkConfigService {
private final Logger log = LoggerFactory.getLogger(getClass());
......@@ -66,17 +67,11 @@ public class NetworkConfigManager implements NetworkConfigRegistry, NetworkConfi
private final Map<Class, SubjectFactory> subjectClassKeys = Maps.newConcurrentMap();
private final Map<ConfigIdentifier, Class<? extends Config>> configClasses = Maps.newConcurrentMap();
private final ListenerRegistry<NetworkConfigEvent, NetworkConfigListener>
listenerRegistry = new ListenerRegistry<>();
private final NetworkConfigStoreDelegate storeDelegate = new InternalStoreDelegate();
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected NetworkConfigStore store;
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected EventDeliveryService eventDispatcher;
@Activate
public void activate() {
......@@ -215,23 +210,12 @@ public class NetworkConfigManager implements NetworkConfigRegistry, NetworkConfi
store.clearConfig(subject, configClass);
}
@Override
public void addListener(NetworkConfigListener listener) {
listenerRegistry.addListener(listener);
}
@Override
public void removeListener(NetworkConfigListener listener) {
listenerRegistry.removeListener(listener);
}
// Auxiliary store delegate to receive notification about changes in
// the network configuration store state - by the store itself.
private class InternalStoreDelegate implements NetworkConfigStoreDelegate {
@Override
public void notify(NetworkConfigEvent event) {
eventDispatcher.post(event);
post(event);
}
}
......
package org.onosproject.incubator.net.resource.label.impl;
import static org.slf4j.LoggerFactory.getLogger;
import java.util.Collection;
import java.util.Set;
import com.google.common.collect.Multimap;
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.EventDeliveryService;
import org.onosproject.event.ListenerRegistry;
import org.onosproject.net.Device;
import org.onosproject.net.DeviceId;
import org.onosproject.net.device.DeviceEvent;
import org.onosproject.net.device.DeviceEvent.Type;
import org.onosproject.net.device.DeviceListener;
import org.onosproject.net.device.DeviceService;
import org.onosproject.net.provider.AbstractProviderRegistry;
import org.onosproject.net.provider.AbstractProviderService;
import org.onosproject.net.provider.AbstractListenerProviderRegistry;
import org.onosproject.incubator.net.resource.label.LabelResource;
import org.onosproject.incubator.net.resource.label.LabelResourceAdminService;
import org.onosproject.incubator.net.resource.label.LabelResourceDelegate;
......@@ -33,11 +20,21 @@ import org.onosproject.incubator.net.resource.label.LabelResourceProviderRegistr
import org.onosproject.incubator.net.resource.label.LabelResourceProviderService;
import org.onosproject.incubator.net.resource.label.LabelResourceService;
import org.onosproject.incubator.net.resource.label.LabelResourceStore;
import org.onosproject.net.Device;
import org.onosproject.net.DeviceId;
import org.onosproject.net.device.DeviceEvent;
import org.onosproject.net.device.DeviceEvent.Type;
import org.onosproject.net.device.DeviceListener;
import org.onosproject.net.device.DeviceService;
import org.onosproject.net.provider.AbstractProviderService;
import org.slf4j.Logger;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Preconditions.checkArgument;
import com.google.common.collect.Multimap;
import java.util.Collection;
import java.util.Set;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
import static org.slf4j.LoggerFactory.getLogger;
/**
* provides implementation of the label resource NB &amp; SB APIs.
......@@ -46,23 +43,16 @@ import com.google.common.collect.Multimap;
@Component(immediate = true)
@Service
public class LabelResourceManager
extends
AbstractProviderRegistry<LabelResourceProvider, LabelResourceProviderService>
implements LabelResourceService, LabelResourceAdminService,
LabelResourceProviderRegistry {
extends AbstractListenerProviderRegistry<LabelResourceEvent, LabelResourceListener,
LabelResourceProvider, LabelResourceProviderService>
implements LabelResourceService, LabelResourceAdminService, LabelResourceProviderRegistry {
private final Logger log = getLogger(getClass());
private final LabelResourceDelegate delegate = new InternalLabelResourceDelegate();
private final ListenerRegistry<LabelResourceEvent, LabelResourceListener> listenerRegistry
= new ListenerRegistry<>();
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected LabelResourceStore store;
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected EventDeliveryService eventDispatcher;
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected DeviceService deviceService;
private DeviceListener deviceListener = new InternalDeviceListener();
......@@ -104,9 +94,9 @@ public class LabelResourceManager
checkNotNull(beginLabel, "beginLabel is not null");
checkNotNull(endLabel, "beginLabel is not null");
checkArgument(beginLabel.labelId() >= 0 && endLabel.labelId() >= 0,
"The value of beginLabel and the value of endLabel must be both positive number.");
"The value of beginLabel and the value of endLabel must be both positive number.");
checkArgument(beginLabel.labelId() <= endLabel.labelId(),
"The value of endLabel must be greater than the value of endLabel.");
"The value of endLabel must be greater than the value of endLabel.");
return store.createGlobalPool(beginLabel, endLabel);
}
......@@ -180,26 +170,7 @@ public class LabelResourceManager
return store.getGlobalLabelResourcePool();
}
@Override
public void addListener(LabelResourceListener listener) {
listenerRegistry.addListener(listener);
}
@Override
public void removeListener(LabelResourceListener listener) {
listenerRegistry.removeListener(listener);
}
private void post(LabelResourceEvent event) {
if (event != null) {
eventDispatcher.post(event);
}
}
private class InternalLabelResourceDelegate
implements LabelResourceDelegate {
private class InternalLabelResourceDelegate implements LabelResourceDelegate {
@Override
public void notify(LabelResourceEvent event) {
post(event);
......@@ -208,7 +179,6 @@ public class LabelResourceManager
}
private class InternalDeviceListener implements DeviceListener {
@Override
public void event(DeviceEvent event) {
Device device = event.subject();
......
......@@ -15,25 +15,17 @@
*/
package org.onosproject.incubator.net.tunnel.impl;
import static com.google.common.base.Preconditions.checkNotNull;
import static org.slf4j.LoggerFactory.getLogger;
import java.util.Collection;
import java.util.Collections;
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.net.provider.AbstractListenerProviderRegistry;
import org.onosproject.core.ApplicationId;
import org.onosproject.event.EventDeliveryService;
import org.onosproject.event.ListenerRegistry;
import org.onosproject.incubator.net.tunnel.DefaultTunnel;
import org.onosproject.incubator.net.tunnel.Tunnel.Type;
import org.onosproject.incubator.net.tunnel.Tunnel;
import org.onosproject.incubator.net.tunnel.Tunnel.Type;
import org.onosproject.incubator.net.tunnel.TunnelAdminService;
import org.onosproject.incubator.net.tunnel.TunnelDescription;
import org.onosproject.incubator.net.tunnel.TunnelEndPoint;
......@@ -51,35 +43,36 @@ import org.onosproject.incubator.net.tunnel.TunnelSubscription;
import org.onosproject.net.Annotations;
import org.onosproject.net.DeviceId;
import org.onosproject.net.Path;
import org.onosproject.net.provider.AbstractProviderRegistry;
import org.onosproject.net.provider.AbstractProviderService;
import org.onosproject.net.provider.ProviderId;
import org.slf4j.Logger;
import java.util.Collection;
import java.util.Collections;
import java.util.Set;
import static com.google.common.base.Preconditions.checkNotNull;
import static org.slf4j.LoggerFactory.getLogger;
/**
* Provides implementation of the tunnel NB/SB APIs.
*/
@Component(immediate = true, enabled = true)
@Service
public class TunnelManager
extends AbstractProviderRegistry<TunnelProvider, TunnelProviderService>
extends AbstractListenerProviderRegistry<TunnelEvent, TunnelListener,
TunnelProvider, TunnelProviderService>
implements TunnelService, TunnelAdminService, TunnelProviderRegistry {
private static final String TUNNNEL_ID_NULL = "Tunnel ID cannot be null";
private final Logger log = getLogger(getClass());
protected final ListenerRegistry<TunnelEvent, TunnelListener>
listenerRegistry = new ListenerRegistry<>();
private final TunnelStoreDelegate delegate = new InternalStoreDelegate();
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected TunnelStore store;
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected EventDeliveryService eventDispatcher;
@Activate
public void activate() {
......@@ -294,16 +287,6 @@ public class TunnelManager
return new InternalTunnelProviderService(provider);
}
@Override
public void addListener(TunnelListener listener) {
listenerRegistry.addListener(listener);
}
@Override
public void removeListener(TunnelListener listener) {
listenerRegistry.removeListener(listener);
}
private class InternalTunnelProviderService
extends AbstractProviderService<TunnelProvider>
implements TunnelProviderService {
......@@ -370,7 +353,7 @@ public class TunnelManager
@Override
public void notify(TunnelEvent event) {
if (event != null) {
eventDispatcher.post(event);
post(event);
}
}
}
......