tom

Enahnced link and host stores to extend general store.

......@@ -4,12 +4,13 @@ import java.util.Set;
import org.onlab.onos.net.DeviceId;
import org.onlab.onos.net.MastershipRole;
import org.onlab.onos.store.Store;
/**
* Manages inventory of mastership roles for devices, across controller
* instances; not intended for direct use.
*/
public interface MastershipStore {
public interface MastershipStore extends Store<MastershipEvent, MastershipStoreDelegate> {
// three things to map: NodeId, DeviceId, MastershipRole
......
......@@ -5,13 +5,14 @@ import org.onlab.onos.net.DeviceId;
import org.onlab.onos.net.Port;
import org.onlab.onos.net.PortNumber;
import org.onlab.onos.net.provider.ProviderId;
import org.onlab.onos.store.Store;
import java.util.List;
/**
* Manages inventory of infrastructure devices; not intended for direct use.
*/
public interface DeviceStore {
public interface DeviceStore extends Store<DeviceEvent, DeviceStoreDelegate> {
/**
* Returns the number of devices known to the system.
......
package org.onlab.onos.net.host;
import java.util.Set;
import org.onlab.onos.net.ConnectPoint;
import org.onlab.onos.net.DeviceId;
import org.onlab.onos.net.Host;
import org.onlab.onos.net.HostId;
import org.onlab.onos.net.provider.ProviderId;
import org.onlab.onos.store.Store;
import org.onlab.packet.IpPrefix;
import org.onlab.packet.MacAddress;
import org.onlab.packet.VlanId;
import java.util.Set;
/**
* Manages inventory of end-station hosts; not intended for direct use.
*/
public interface HostStore {
public interface HostStore extends Store<HostEvent, HostStoreDelegate> {
/**
* Creates a new host or updates the existing one based on the specified
......@@ -133,7 +134,7 @@ public interface HostStore {
* Returns the address bindings for a particular connection point.
*
* @param connectPoint the connection point to return address information
* for
* for
* @return address information for the connection point
*/
PortAddresses getAddressBindingsForPort(ConnectPoint connectPoint);
......
package org.onlab.onos.net.host;
import org.onlab.onos.store.StoreDelegate;
/**
* Infrastructure link store delegate abstraction.
*/
public interface HostStoreDelegate extends StoreDelegate<HostEvent> {
}
......@@ -4,13 +4,14 @@ import org.onlab.onos.net.ConnectPoint;
import org.onlab.onos.net.DeviceId;
import org.onlab.onos.net.Link;
import org.onlab.onos.net.provider.ProviderId;
import org.onlab.onos.store.Store;
import java.util.Set;
/**
* Manages inventory of infrastructure links; not intended for direct use.
*/
public interface LinkStore {
public interface LinkStore extends Store<LinkEvent, LinkStoreDelegate> {
/**
* Returns the number of links in the store.
......
package org.onlab.onos.net.link;
import org.onlab.onos.store.StoreDelegate;
/**
* Infrastructure link store delegate abstraction.
*/
public interface LinkStoreDelegate extends StoreDelegate<LinkEvent> {
}
......@@ -2,6 +2,8 @@ package org.onlab.onos.store;
import org.onlab.onos.event.Event;
import static com.google.common.base.Preconditions.checkState;
/**
* Base implementation of a store.
*/
......@@ -12,12 +14,21 @@ public class AbstractStore<E extends Event, D extends StoreDelegate<E>>
@Override
public void setDelegate(D delegate) {
checkState(this.delegate == null || this.delegate == delegate,
"Store delegate already set");
this.delegate = delegate;
}
@Override
public D getDelegate() {
return delegate;
public void unsetDelegate(D delegate) {
if (this.delegate == delegate) {
this.delegate = null;
}
}
@Override
public boolean hasDelegate() {
return delegate != null;
}
/**
......
......@@ -12,14 +12,25 @@ public interface Store<E extends Event, D extends StoreDelegate<E>> {
* Sets the delegate on the store.
*
* @param delegate new store delegate
* @throws java.lang.IllegalStateException if a delegate is already
* currently set on the store and is a different one that
*/
void setDelegate(D delegate);
/**
* Get the current store delegate.
* Withdraws the delegate from the store.
*
* @return store delegate
* @param delegate store delegate to withdraw
* @throws java.lang.IllegalArgumentException if the delegate is not
* currently set on the store
*/
D getDelegate();
void unsetDelegate(D delegate);
/**
* Indicates whether the store has a delegate.
*
* @return true if delegate is set
*/
boolean hasDelegate();
}
......
......@@ -53,6 +53,7 @@ public class ClusterManager implements ClusterService, ClusterAdminService {
@Deactivate
public void deactivate() {
store.unsetDelegate(delegate);
eventDispatcher.removeSink(ClusterEvent.class);
log.info("Stopped");
}
......
......@@ -26,6 +26,7 @@ import org.onlab.onos.net.device.DeviceProviderRegistry;
import org.onlab.onos.net.device.DeviceProviderService;
import org.onlab.onos.net.device.DeviceService;
import org.onlab.onos.net.device.DeviceStore;
import org.onlab.onos.net.device.DeviceStoreDelegate;
import org.onlab.onos.net.device.PortDescription;
import org.onlab.onos.net.provider.AbstractProviderRegistry;
import org.onlab.onos.net.provider.AbstractProviderService;
......@@ -33,8 +34,8 @@ import org.slf4j.Logger;
import java.util.List;
import static org.onlab.onos.net.device.DeviceEvent.Type.*;
import static com.google.common.base.Preconditions.checkNotNull;
import static org.onlab.onos.net.device.DeviceEvent.Type.DEVICE_MASTERSHIP_CHANGED;
import static org.slf4j.LoggerFactory.getLogger;
/**
......@@ -57,6 +58,8 @@ public class DeviceManager
protected final AbstractListenerRegistry<DeviceEvent, DeviceListener>
listenerRegistry = new AbstractListenerRegistry<>();
private DeviceStoreDelegate delegate = new InternalStoreDelegate();
private final MastershipListener mastershipListener = new InnerMastershipListener();
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
......@@ -73,6 +76,7 @@ public class DeviceManager
@Activate
public void activate() {
store.setDelegate(delegate);
eventDispatcher.addSink(DeviceEvent.class, listenerRegistry);
mastershipService.addListener(mastershipListener);
log.info("Started");
......@@ -80,6 +84,7 @@ public class DeviceManager
@Deactivate
public void deactivate() {
store.unsetDelegate(delegate);
mastershipService.removeListener(mastershipListener);
eventDispatcher.removeSink(DeviceEvent.class);
log.info("Stopped");
......@@ -248,4 +253,12 @@ public class DeviceManager
}
}
}
// Store delegate to re-post events emitted from the store.
private class InternalStoreDelegate implements DeviceStoreDelegate {
@Override
public void notify(DeviceEvent event) {
post(event);
}
}
}
......
......@@ -15,8 +15,10 @@ import org.onlab.onos.net.PortNumber;
import org.onlab.onos.net.device.DeviceDescription;
import org.onlab.onos.net.device.DeviceEvent;
import org.onlab.onos.net.device.DeviceStore;
import org.onlab.onos.net.device.DeviceStoreDelegate;
import org.onlab.onos.net.device.PortDescription;
import org.onlab.onos.net.provider.ProviderId;
import org.onlab.onos.store.AbstractStore;
import org.slf4j.Logger;
import java.util.ArrayList;
......@@ -40,7 +42,9 @@ import static org.slf4j.LoggerFactory.getLogger;
*/
@Component(immediate = true)
@Service
public class SimpleDeviceStore implements DeviceStore {
public class SimpleDeviceStore
extends AbstractStore<DeviceEvent, DeviceStoreDelegate>
implements DeviceStore {
private final Logger log = getLogger(getClass());
......
......@@ -24,8 +24,10 @@ import org.onlab.onos.net.HostId;
import org.onlab.onos.net.host.HostDescription;
import org.onlab.onos.net.host.HostEvent;
import org.onlab.onos.net.host.HostStore;
import org.onlab.onos.net.host.HostStoreDelegate;
import org.onlab.onos.net.host.PortAddresses;
import org.onlab.onos.net.provider.ProviderId;
import org.onlab.onos.store.AbstractStore;
import org.onlab.packet.IpPrefix;
import org.onlab.packet.MacAddress;
import org.onlab.packet.VlanId;
......@@ -41,7 +43,9 @@ import com.google.common.collect.Multimap;
*/
@Component(immediate = true)
@Service
public class SimpleHostStore implements HostStore {
public class SimpleHostStore
extends AbstractStore<HostEvent, HostStoreDelegate>
implements HostStore {
private final Logger log = getLogger(getClass());
......
......@@ -14,7 +14,9 @@ import org.onlab.onos.net.Link;
import org.onlab.onos.net.link.LinkDescription;
import org.onlab.onos.net.link.LinkEvent;
import org.onlab.onos.net.link.LinkStore;
import org.onlab.onos.net.link.LinkStoreDelegate;
import org.onlab.onos.net.provider.ProviderId;
import org.onlab.onos.store.AbstractStore;
import org.slf4j.Logger;
import java.util.Collections;
......@@ -35,7 +37,9 @@ import static org.slf4j.LoggerFactory.getLogger;
*/
@Component(immediate = true)
@Service
public class SimpleLinkStore implements LinkStore {
public class SimpleLinkStore
extends AbstractStore<LinkEvent, LinkStoreDelegate>
implements LinkStore {
private final Logger log = getLogger(getClass());
......
......@@ -15,9 +15,11 @@ import org.onlab.onos.cluster.ControllerNode;
import org.onlab.onos.cluster.DefaultControllerNode;
import org.onlab.onos.cluster.MastershipEvent;
import org.onlab.onos.cluster.MastershipStore;
import org.onlab.onos.cluster.MastershipStoreDelegate;
import org.onlab.onos.cluster.NodeId;
import org.onlab.onos.net.DeviceId;
import org.onlab.onos.net.MastershipRole;
import org.onlab.onos.store.AbstractStore;
import org.onlab.packet.IpPrefix;
import org.slf4j.Logger;
......@@ -29,7 +31,9 @@ import static org.onlab.onos.cluster.MastershipEvent.Type.*;
*/
@Component(immediate = true)
@Service
public class SimpleMastershipStore implements MastershipStore {
public class SimpleMastershipStore
extends AbstractStore<MastershipEvent, MastershipStoreDelegate>
implements MastershipStore {
public static final IpPrefix LOCALHOST = IpPrefix.valueOf("127.0.0.1");
......