You've been checkstyled!
Change-Id: I0425764b2f3b07bc224a387ab7d544c6b360c691
diff --git a/core/api/src/main/java/org/onosproject/ui/UiTopoLayoutService.java b/core/api/src/main/java/org/onosproject/ui/UiTopoLayoutService.java
new file mode 100644
index 0000000..b03cbd4
--- /dev/null
+++ b/core/api/src/main/java/org/onosproject/ui/UiTopoLayoutService.java
@@ -0,0 +1,50 @@
+/*
+ * 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;
+
+import org.onosproject.ui.model.topo.UiTopoLayout;
+
+import java.util.List;
+
+/**
+ * Service for managing {@link UiTopoLayout} instances.
+ */
+public interface UiTopoLayoutService {
+
+ /**
+ * Returns the list of available layouts.
+ *
+ * @return available layouts
+ */
+ List<UiTopoLayout> getLayouts();
+
+ /**
+ * Adds a layout to the system.
+ *
+ * @param layout the layout to add
+ * @return an indication of success
+ */
+ boolean addLayout(UiTopoLayout layout);
+
+ /**
+ * Removes a layout from the system.
+ *
+ * @param layout the layout to remove
+ * @return an indication of success
+ */
+ boolean removeLayout(UiTopoLayout layout);
+
+}
diff --git a/core/api/src/main/java/org/onosproject/ui/model/topo/UiTopoLayout.java b/core/api/src/main/java/org/onosproject/ui/model/topo/UiTopoLayout.java
new file mode 100644
index 0000000..b93cb0d
--- /dev/null
+++ b/core/api/src/main/java/org/onosproject/ui/model/topo/UiTopoLayout.java
@@ -0,0 +1,29 @@
+/*
+ * 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;
+
+import org.onosproject.net.region.Region;
+
+/**
+ * Represents a specific "subset" of the UI model of the network topology
+ * that a user might wish to view. Backed by a {@link Region}.
+ */
+public class UiTopoLayout {
+
+ private Region backingRegion;
+
+}
diff --git a/web/gui/src/main/java/org/onosproject/ui/impl/topo/UiTopoLayoutManager.java b/web/gui/src/main/java/org/onosproject/ui/impl/topo/UiTopoLayoutManager.java
new file mode 100644
index 0000000..170f1c3
--- /dev/null
+++ b/web/gui/src/main/java/org/onosproject/ui/impl/topo/UiTopoLayoutManager.java
@@ -0,0 +1,73 @@
+/*
+ * 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;
+
+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.Service;
+import org.onosproject.ui.UiTopoLayoutService;
+import org.onosproject.ui.model.topo.UiTopoLayout;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.List;
+
+/**
+ * Manages the user interface topology layouts.
+ * Note that these layouts are persisted and distributed across the cluster.
+ */
+@Component(immediate = true)
+@Service
+public class UiTopoLayoutManager implements UiTopoLayoutService {
+
+// private static final ClassLoader CL =
+// UiTopoLayoutManager.class.getClassLoader();
+
+ private final Logger log = LoggerFactory.getLogger(getClass());
+
+ @Activate
+ public void activate() {
+ // TODO: implement starting stuff
+ log.info("Started");
+ }
+
+ @Deactivate
+ public void deactivate() {
+ // TODO: implement stopping stuff
+ log.info("Stopped");
+ }
+
+
+ @Override
+ public List<UiTopoLayout> getLayouts() {
+ // TODO: implement
+ return null;
+ }
+
+ @Override
+ public boolean addLayout(UiTopoLayout layout) {
+ // TODO: implement
+ return false;
+ }
+
+ @Override
+ public boolean removeLayout(UiTopoLayout layout) {
+ // TODO: implement
+ return false;
+ }
+}
diff --git a/web/gui/src/main/java/org/onosproject/ui/impl/topo/model/UiTopoLayout.java b/web/gui/src/main/java/org/onosproject/ui/impl/topo/UiTopoSession.java
similarity index 66%
rename from web/gui/src/main/java/org/onosproject/ui/impl/topo/model/UiTopoLayout.java
rename to web/gui/src/main/java/org/onosproject/ui/impl/topo/UiTopoSession.java
index b71b81e..f1c2f26 100644
--- a/web/gui/src/main/java/org/onosproject/ui/impl/topo/model/UiTopoLayout.java
+++ b/web/gui/src/main/java/org/onosproject/ui/impl/topo/UiTopoSession.java
@@ -14,31 +14,43 @@
* limitations under the License.
*/
-package org.onosproject.ui.impl.topo.model;
+package org.onosproject.ui.impl.topo;
+import org.onosproject.ui.UiTopoLayoutService;
+import org.onosproject.ui.impl.UiWebSocket;
+import org.onosproject.ui.impl.topo.model.UiSharedTopologyModel;
+import org.onosproject.ui.model.topo.UiTopoLayout;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
- * Base class for modeling the Topology View layout.
+ * 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.
* <p>
* Note that an instance of this class will be created for each
- * {@link org.onosproject.ui.impl.UiWebSocket} connection, and will contain
+ * {@link UiWebSocket} connection, and will contain
* the state of how the topology is laid out for the logged-in user.
*/
-public class UiTopoLayout {
+public class UiTopoSession {
private final Logger log = LoggerFactory.getLogger(getClass());
private final String username;
+ private final UiWebSocket webSocket;
private final UiSharedTopologyModel sharedModel;
private boolean registered = false;
+ private UiTopoLayoutService service;
+ private UiTopoLayout layout;
+
/**
* Creates a new topology layout.
*/
- public UiTopoLayout(String username) {
+ public UiTopoSession(String username, UiWebSocket webSocket) {
this.username = username;
+ this.webSocket = webSocket;
this.sharedModel = UiSharedTopologyModel.instance();
}
@@ -60,6 +72,7 @@
public void destroy() {
if (!registered) {
sharedModel.unregister(this);
+ registered = false;
} else {
log.warn("already unregistered");
}
@@ -67,6 +80,6 @@
@Override
public String toString() {
- return String.format("{UiTopoLayout for user <%s>}", username);
+ return String.format("{UiTopoSession for user <%s>}", username);
}
}
diff --git a/web/gui/src/main/java/org/onosproject/ui/impl/topo/model/UiSharedTopologyModel.java b/web/gui/src/main/java/org/onosproject/ui/impl/topo/model/UiSharedTopologyModel.java
index 1e1374a..b9b5e8c 100644
--- a/web/gui/src/main/java/org/onosproject/ui/impl/topo/model/UiSharedTopologyModel.java
+++ b/web/gui/src/main/java/org/onosproject/ui/impl/topo/model/UiSharedTopologyModel.java
@@ -16,6 +16,7 @@
package org.onosproject.ui.impl.topo.model;
+import org.onosproject.ui.impl.topo.UiTopoSession;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -28,20 +29,43 @@
private static final Logger log =
LoggerFactory.getLogger(UiSharedTopologyModel.class);
- private static UiSharedTopologyModel singleton = null;
private UiSharedTopologyModel() {
// TODO: set up core model listeners and build the state of the model
}
- public void register(UiTopoLayout layout) {
- log.info("Registering topology layout {}", layout);
- // TODO: register the view
+ // TODO: Note to Thomas (or others)..
+ // Don't we have a common pattern for adding/removing listeners and
+ // invoking them when things happen?
+
+
+ /**
+ * Registers a UI topology session with the topology model.
+ *
+ * @param session the session to register
+ */
+ public void register(UiTopoSession session) {
+ log.info("Registering topology session {}", session);
+ // TODO: register the session
}
- public void unregister(UiTopoLayout layout) {
- log.info("Unregistering topology layout {}", layout);
- // TODO: unregister the view
+ /**
+ * Unregisters a UI topology session from the topology model.
+ *
+ * @param session the session to unregister
+ */
+ public void unregister(UiTopoSession session) {
+ log.info("Unregistering topology session {}", session);
+ // TODO: unregister the session
+ }
+
+ /**
+ * Bill Pugh Singleton pattern. INSTANCE won't be instantiated until the
+ * LazyHolder class is loaded via a call to the instance() method below.
+ */
+ private static class LazyHolder {
+ private static final UiSharedTopologyModel INSTANCE =
+ new UiSharedTopologyModel();
}
/**
@@ -49,11 +73,7 @@
*
* @return the singleton topology model
*/
- public static synchronized UiSharedTopologyModel instance() {
- if (singleton == null) {
- log.info("Instantiating Singleton.");
- singleton = new UiSharedTopologyModel();
- }
- return singleton;
+ public static UiSharedTopologyModel instance() {
+ return LazyHolder.INSTANCE;
}
}