Simon Hunt

Converted UiSharedTopologyModel to be a @Service.

Change-Id: Idc8df1b9c0a52db01ac545567dacc0e1c770f84a
......@@ -16,6 +16,7 @@
package org.onosproject.net.region;
import org.onosproject.event.ListenerService;
import org.onosproject.net.DeviceId;
import java.util.Set;
......@@ -23,7 +24,7 @@ import java.util.Set;
/**
* Service for interacting with inventory of network control regions.
*/
public interface RegionService {
public interface RegionService extends ListenerService<RegionEvent, RegionListener> {
/**
* Returns set of all regions.
......
......@@ -19,5 +19,5 @@ package org.onosproject.ui.model.topo;
/**
* Encapsulates the notion of the ONOS cluster.
*/
public class UiCluster {
public class UiCluster extends UiElement {
}
......
......@@ -19,5 +19,5 @@ package org.onosproject.ui.model.topo;
/**
* Represents an individual member of the cluster (ONOS instance).
*/
public class UiClusterMember {
public class UiClusterMember extends UiElement {
}
......
/*
* Copyright 2016 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.ui.model.topo;
/**
* Abstract base class of all elements in the UI topology model.
*/
public class UiElement {
}
......@@ -19,5 +19,5 @@ package org.onosproject.ui.model.topo;
/**
* Represents a bi-directional link backed by two uni-directional links.
*/
public class UiLink {
public class UiLink extends UiElement {
}
......
......@@ -19,5 +19,5 @@ package org.onosproject.ui.model.topo;
/**
* Represents a node drawn on the topology view (region, device, host).
*/
public abstract class UiNode {
public abstract class UiNode extends UiElement {
}
......
......@@ -19,5 +19,5 @@ package org.onosproject.ui.model.topo;
/**
* Represents the overall network topology.
*/
public class UiTopology {
public class UiTopology extends UiElement {
}
......
......@@ -29,6 +29,7 @@ import org.onosproject.ui.UiMessageHandlerFactory;
import org.onosproject.ui.UiMessageHandler;
import org.onosproject.ui.UiTopoOverlayFactory;
import org.onosproject.ui.impl.topo.UiTopoSession;
import org.onosproject.ui.impl.topo.model.UiSharedTopologyModel;
import org.onosproject.ui.topo.TopoConstants;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......@@ -65,7 +66,7 @@ public class UiWebSocket
private TopoOverlayCache overlayCache;
/**
* Creates a new web-socket for serving data to GUI.
* Creates a new web-socket for serving data to the Web UI.
*
* @param directory service directory
* @param userName user name of the logged-in user
......@@ -73,7 +74,8 @@ public class UiWebSocket
public UiWebSocket(ServiceDirectory directory, String userName) {
this.directory = directory;
this.userName = userName;
this.topoSession = new UiTopoSession(this);
this.topoSession =
new UiTopoSession(this, directory.get(UiSharedTopologyModel.class));
}
@Override
......
......@@ -18,6 +18,8 @@ package org.onosproject.ui.impl.topo;
import org.onosproject.ui.UiTopoLayoutService;
import org.onosproject.ui.impl.UiWebSocket;
import org.onosproject.ui.impl.topo.model.UiModelEvent;
import org.onosproject.ui.impl.topo.model.UiModelListener;
import org.onosproject.ui.impl.topo.model.UiSharedTopologyModel;
import org.onosproject.ui.model.topo.UiTopoLayout;
import org.slf4j.Logger;
......@@ -26,14 +28,14 @@ import org.slf4j.LoggerFactory;
/**
* Coordinates with the {@link UiTopoLayoutService} to access
* {@link UiTopoLayout}s, and with the {@link UiSharedTopologyModel} which
* maintains a local model of the network entities,
* tailored specifically for displaying on the UI.
* maintains a local model of the network entities, tailored specifically
* for displaying on the UI.
* <p>
* Note that an instance of this class will be created for each
* {@link UiWebSocket} connection, and will contain
* the state of how the topology is laid out for the logged-in user.
*/
public class UiTopoSession {
public class UiTopoSession implements UiModelListener {
private final Logger log = LoggerFactory.getLogger(getClass());
private final UiWebSocket webSocket;
......@@ -50,11 +52,12 @@ public class UiTopoSession {
* Creates a new topology session for the specified web socket connection.
*
* @param webSocket web socket
* @param model share topology model
*/
public UiTopoSession(UiWebSocket webSocket) {
public UiTopoSession(UiWebSocket webSocket, UiSharedTopologyModel model) {
this.webSocket = webSocket;
this.username = webSocket.userName();
this.sharedModel = UiSharedTopologyModel.instance();
this.sharedModel = model;
}
/**
......@@ -87,4 +90,10 @@ public class UiTopoSession {
public String toString() {
return String.format("{UiTopoSession for user <%s>}", username);
}
@Override
public void event(UiModelEvent event) {
log.info("Event received: {}", event);
// TODO: handle model events from the cache...
}
}
......
/*
* Copyright 2016 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.ui.impl.topo.model;
import org.onosproject.event.EventDispatcher;
import org.onosproject.net.Device;
import org.onosproject.ui.model.topo.UiDevice;
/**
* UI Topology Model cache.
*/
class ModelCache {
private final EventDispatcher dispatcher;
ModelCache(EventDispatcher eventDispatcher) {
this.dispatcher = eventDispatcher;
}
/**
* Clear our model.
*/
void clear() {
// TODO: clear our internal state
}
/**
* Create our internal model of the global topology.
*/
void load() {
// loadClusterMembers();
// loadRegions();
// loadDevices();
// loadHosts();
// loadLinks();
}
// add or update device
void addOrUpdateDevice(Device device) {
// fetch UiDevice
UiDevice uiDevice = new UiDevice();
dispatcher.post(
new UiModelEvent(UiModelEvent.Type.DEVICE_ADDED, uiDevice)
);
}
void removeDevice(Device device) {
UiDevice uiDevice = new UiDevice();
dispatcher.post(
new UiModelEvent(UiModelEvent.Type.DEVICE_REMOVED, uiDevice)
);
}
// TODO remaining model objects
}
/*
* Copyright 2016 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.ui.impl.topo.model;
import org.onosproject.event.AbstractEvent;
import org.onosproject.ui.model.topo.UiElement;
/**
* UI Topology model events.
*/
public class UiModelEvent extends AbstractEvent<UiModelEvent.Type, UiElement> {
protected UiModelEvent(Type type, UiElement subject) {
super(type, subject);
}
enum Type {
DEVICE_ADDED,
DEVICE_REMOVED,
// TODO...
}
}
/*
* Copyright 2016 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.ui.impl.topo.model;
import org.onosproject.event.EventListener;
/**
* Can receive {@link UiModelEvent}s.
*/
public interface UiModelListener extends EventListener<UiModelEvent> {
}