Code cleaning
Change-Id: I9c32de6a3c36820fe54651cd5d9ccabc394fd0cb
diff --git a/src/main/java/net/onrc/onos/datastore/RCObject.java b/src/main/java/net/onrc/onos/datastore/RCObject.java
index 0ac0d49..a4bbf1c 100644
--- a/src/main/java/net/onrc/onos/datastore/RCObject.java
+++ b/src/main/java/net/onrc/onos/datastore/RCObject.java
@@ -464,26 +464,7 @@
return fail_exists;
}
- public static Iterable<RCObject> getAllObjects(RCTable table) {
- return new ObjectEnumerator(table);
- }
-
- public static class ObjectEnumerator implements Iterable<RCObject> {
-
- private RCTable table;
-
- public ObjectEnumerator(RCTable table) {
- this.table = table;
- }
-
- @Override
- public Iterator<RCObject> iterator() {
- return new ObjectIterator<RCObject>(table);
- }
-
- }
-
- public static class ObjectIterator<E extends RCObject> implements
+ public static abstract class ObjectIterator<E extends RCObject> implements
Iterator<E> {
protected TableEnumerator enumerator;
@@ -500,13 +481,14 @@
return enumerator.hasNext();
}
- @Override
- public E next() {
- JRamCloud.Object o = enumerator.next();
- RCObject obj = RCObject.createFromKey(o.key);
- obj.setValueAndDeserialize(o.value, o.version);
- return (E) obj;
- }
+// Implement something similar to below to realize Iterator
+// @Override
+// public E next() {
+// JRamCloud.Object o = enumerator.next();
+// E obj = E.createFromKey(o.key);
+// obj.setValueAndDeserialize(o.value, o.version);
+// return obj;
+// }
@Deprecated
@Override
diff --git a/src/main/java/net/onrc/onos/datastore/topology/RCSwitch.java b/src/main/java/net/onrc/onos/datastore/topology/RCSwitch.java
index c98c726..3b00084 100644
--- a/src/main/java/net/onrc/onos/datastore/topology/RCSwitch.java
+++ b/src/main/java/net/onrc/onos/datastore/topology/RCSwitch.java
@@ -1,6 +1,7 @@
package net.onrc.onos.datastore.topology;
import java.nio.ByteBuffer;
+import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
@@ -257,8 +258,8 @@
// create active switch 0x1 with 2 ports
RCSwitch sw = new RCSwitch(0x1L);
sw.setStatus(STATUS.ACTIVE);
- sw.addPortId("SW0x0001P001".getBytes());
- sw.addPortId("SW0x0001P002".getBytes());
+ sw.addPortId("SW0x0001P001".getBytes(StandardCharsets.UTF_8));
+ sw.addPortId("SW0x0001P002".getBytes(StandardCharsets.UTF_8));
try {
sw.create();
@@ -277,13 +278,13 @@
assert (swRead.getStatus() == STATUS.ACTIVE);
for (byte[] portId : swRead.getAllPortIds()) {
// XXX bad example code, portId is not expected to be ASCII string
- log.debug("PortId: {}", new String(portId));
+ log.debug("PortId: {}", new String(portId, StandardCharsets.UTF_8));
}
assert (swRead.getAllPortIds().size() == 2);
// update 0x1
swRead.setStatus(STATUS.INACTIVE);
- swRead.removePortId("SW0x0001P001".getBytes());
+ swRead.removePortId("SW0x0001P001".getBytes(StandardCharsets.UTF_8));
try {
swRead.update();
} catch (ObjectDoesntExistException | WrongVersionException e) {
@@ -300,7 +301,7 @@
assert (swRead2.getStatus() == STATUS.INACTIVE);
for (byte[] portId : swRead2.getAllPortIds()) {
// XXX bad example code, portId is not expected to be ASCII string
- log.debug("PortId: {}", new String(portId));
+ log.debug("PortId: {}", new String(portId, StandardCharsets.UTF_8));
}
assert (swRead2.getAllPortIds().size() == 1);
try {
diff --git a/src/main/java/net/onrc/onos/ofcontroller/networkgraph/NetworkGraphImpl.java b/src/main/java/net/onrc/onos/ofcontroller/networkgraph/NetworkGraphImpl.java
index 0b836c3..b821050 100644
--- a/src/main/java/net/onrc/onos/ofcontroller/networkgraph/NetworkGraphImpl.java
+++ b/src/main/java/net/onrc/onos/ofcontroller/networkgraph/NetworkGraphImpl.java
@@ -704,13 +704,13 @@
// Attached Ports' Parent Switch must exist
Switch sw = getSwitch(swp.dpid);
if ( sw == null ) {
- log.warn("Switch {} for the attachment point did not exist. skipping mutation", sw);
+ log.warn("Switch for the attachment point {} did not exist. skipping mutation", swp);
continue;
}
// Attached Ports must exist
Port port = sw.getPort(swp.number);
if ( port == null ) {
- log.warn("Port {} for the attachment point did not exist. skipping mutation", port);
+ log.warn("Port for the attachment point {} did not exist. skipping mutation", swp);
continue;
}
// Attached Ports must not have Link
@@ -770,13 +770,13 @@
// Attached Ports' Parent Switch must exist
Switch sw = getSwitch(swp.dpid);
if ( sw == null ) {
- log.warn("Switch {} for the attachment point did not exist. skipping attachment point mutation", sw);
+ log.warn("Switch for the attachment point {} did not exist. skipping attachment point mutation", swp);
continue;
}
// Attached Ports must exist
Port port = sw.getPort(swp.number);
if ( port == null ) {
- log.warn("Port {} for the attachment point did not exist. skipping attachment point mutation", port);
+ log.warn("Port for the attachment point {} did not exist. skipping attachment point mutation", swp);
continue;
}
diff --git a/src/main/java/net/onrc/onos/ofcontroller/networkgraph/SwitchImpl.java b/src/main/java/net/onrc/onos/ofcontroller/networkgraph/SwitchImpl.java
index 874bf37..97e9004 100644
--- a/src/main/java/net/onrc/onos/ofcontroller/networkgraph/SwitchImpl.java
+++ b/src/main/java/net/onrc/onos/ofcontroller/networkgraph/SwitchImpl.java
@@ -76,13 +76,13 @@
// TODO Should switch also store a list of attached devices to avoid
// calculating this every time?
List<Device> devices = new ArrayList<Device>();
-
+
for (Port port : ports.values()) {
for (Device device : port.getDevices()) {
devices.add(device);
}
}
-
+
return devices;
}
@@ -101,11 +101,12 @@
return port;
}
+ // XXX Do we still need this method?
public void store() {
RCSwitch rcSwitch = new RCSwitch(dpid);
for (Port port : ports.values()) {
- RCPort rcPort = new RCPort(dpid, (long)port.getNumber());
+ RCPort rcPort = new RCPort(dpid, port.getNumber());
rcSwitch.addPortId(rcPort.getId());
}