Minor Registry changes and Controller now registers itself on startup using the registry
diff --git a/src/main/java/net/onrc/onos/registry/controller/ZookeeperRegistry.java b/src/main/java/net/onrc/onos/registry/controller/ZookeeperRegistry.java
index 58b8bc7..1695451 100644
--- a/src/main/java/net/onrc/onos/registry/controller/ZookeeperRegistry.java
+++ b/src/main/java/net/onrc/onos/registry/controller/ZookeeperRegistry.java
@@ -22,6 +22,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import com.google.common.base.Charsets;
import com.netflix.curator.RetryPolicy;
import com.netflix.curator.framework.CuratorFramework;
import com.netflix.curator.framework.CuratorFrameworkFactory;
@@ -286,15 +287,20 @@
@Override
public void registerController(String id) throws RegistryException {
//if (!zookeeperEnabled) return;
+ if (controllerId != null) {
+ throw new RegistryException(
+ "Controller already registered with id " + controllerId);
+ }
controllerId = id;
- byte bytes[] = null;
+ byte bytes[] = id.getBytes(Charsets.UTF_8);
+ /*byte bytes[] = null;
try {
bytes = id.getBytes("UTF-8");
} catch (UnsupportedEncodingException e1) {
throw new RegistryException("Error encoding string", e1);
- }
+ }*/
String path = controllerPath + "/" + id;
@@ -364,12 +370,13 @@
}
*/
- String controllerId = null;
+ /*String controllerId = null;
try {
controllerId = new String(d.getData(), "UTF-8");
} catch (UnsupportedEncodingException e) {
log.warn("Encoding exception: {}", e.getMessage());
- }
+ }*/
+ String controllerId = new String(d.getData(), Charsets.UTF_8);
String[] splitted = d.getPath().split("-");
int sequenceNumber = Integer.parseInt(splitted[splitted.length - 1]);