Registry module is disabled by default so we can still run ONOS without it trying to connect to zookeeper.

Added a config option to enable it. The option is (currently)
net.floodlightcontroller.mastership.MastershipManager.enableZookeeper = true
diff --git a/src/main/java/net/floodlightcontroller/mastership/IMastershipService.java b/src/main/java/net/floodlightcontroller/mastership/IMastershipService.java
index cc0ddf4..bfb2e9a 100644
--- a/src/main/java/net/floodlightcontroller/mastership/IMastershipService.java
+++ b/src/main/java/net/floodlightcontroller/mastership/IMastershipService.java
@@ -32,16 +32,16 @@
 	 * @param controller A string identifying the controller and (possibly) how to talk to it.
 	 * (We will have to develop a convention for this - most likely hostname:port)
 	 */
-	public void registerController(String controllerId) throws Exception;
+	public void registerController(String controllerId) throws RegistryException;
 	
 	/**
 	 * Get all controllers in the cluster
 	 * @return
 	 */
-	public Collection<String> getAllControllers() throws Exception;
+	public Collection<String> getAllControllers() throws RegistryException;
 	
 	
-	public String getControllerForSwitch(long dpid) throws Exception;
+	public String getControllerForSwitch(long dpid) throws RegistryException;
 	
 	public Collection<Long> getSwitchesControlledByController(String controllerId);
 }
diff --git a/src/main/java/net/floodlightcontroller/mastership/MastershipManager.java b/src/main/java/net/floodlightcontroller/mastership/MastershipManager.java
index bff588b..2e50670 100644
--- a/src/main/java/net/floodlightcontroller/mastership/MastershipManager.java
+++ b/src/main/java/net/floodlightcontroller/mastership/MastershipManager.java
@@ -25,12 +25,13 @@
 import com.netflix.curator.framework.CuratorFramework;
 import com.netflix.curator.framework.CuratorFrameworkFactory;
 import com.netflix.curator.framework.api.CuratorWatcher;
+import com.netflix.curator.framework.imps.CuratorFrameworkState;
 import com.netflix.curator.framework.recipes.cache.ChildData;
 import com.netflix.curator.framework.recipes.cache.PathChildrenCache;
 import com.netflix.curator.framework.recipes.cache.PathChildrenCache.StartMode;
 import com.netflix.curator.framework.recipes.leader.LeaderLatch;
 import com.netflix.curator.framework.recipes.leader.Participant;
-import com.netflix.curator.retry.ExponentialBackoffRetry;
+import com.netflix.curator.retry.RetryOneTime;
 
 public class MastershipManager implements IFloodlightModule, IMastershipService {
 
@@ -50,6 +51,8 @@
 	protected Map<String, LeaderLatch> switchLatches;
 	protected Map<String, MastershipCallback> switchCallbacks;
 	
+	protected boolean moduleEnabled = false;
+	
 	protected class ParamaterizedCuratorWatcher implements CuratorWatcher {
 		private String dpid;
 		private boolean isLeader = false;
@@ -111,6 +114,8 @@
 	@Override
 	public void acquireMastership(long dpid, MastershipCallback cb) throws Exception {
 		
+		if (!moduleEnabled) return;
+		
 		if (mastershipId == null){
 			throw new RuntimeException("Must set mastershipId before calling aquireMastership");
 		}
@@ -142,6 +147,8 @@
 
 	@Override
 	public void releaseMastership(long dpid) {
+		if (!moduleEnabled) return;
+		
 		String dpidStr = HexString.toHexString(dpid);
 		
 		LeaderLatch latch = switchLatches.get(dpidStr);
@@ -163,6 +170,8 @@
 
 	@Override
 	public boolean amMaster(long dpid) {
+		if (!moduleEnabled) return false;
+		
 		LeaderLatch latch = switchLatches.get(HexString.toHexString(dpid));
 		
 		if (latch == null) {
@@ -189,7 +198,9 @@
 	}
 	
 	@Override
-	public Collection<String> getAllControllers() throws Exception {
+	public Collection<String> getAllControllers() throws RegistryException {
+		if (!moduleEnabled) return null;
+		
 		log.debug("Getting all controllers");
 		
 		List<String> controllers = new ArrayList<String>();
@@ -199,7 +210,7 @@
 			try {
 				d = new String(data.getData(), "UTF-8");
 			} catch (UnsupportedEncodingException e) {
-				throw new Exception("Error encoding string", e);
+				throw new RegistryException("Error encoding string", e);
 			}
 
 			controllers.add(d);
@@ -208,29 +219,32 @@
 	}
 
 	@Override
-	public void registerController(String id) throws Exception {
+	public void registerController(String id) throws RegistryException {
+		if (!moduleEnabled) return;
+		
 		byte bytes[] = null;
 		try {
 			bytes = id.getBytes("UTF-8");
 		} catch (UnsupportedEncodingException e1) {
-			throw new Exception("Error encoding string", e1);
+			throw new RegistryException("Error encoding string", e1);
 		}
 		
 		String path = controllerPath + "/" + id;
 		
 		log.info("Registering controller with id {}", id);
 		
-		//Create ephemeral node with my id
+		//Create ephemeral node in controller registry
 		try {
 			client.create().withProtection().withMode(CreateMode.EPHEMERAL)
 					.forPath(path, bytes);
 		} catch (Exception e) {
-			throw new Exception("Error contacting the Zookeeper service", e);
+			throw new RegistryException("Error contacting the Zookeeper service", e);
 		}
 	}
 	
 	@Override
-	public String getControllerForSwitch(long dpid) throws Exception {
+	public String getControllerForSwitch(long dpid) throws RegistryException {
+		if (!moduleEnabled) return null;
 		// TODO Work out how we should store this controller/switch data.
 		// The leader latch might be a index to the /controllers collections
 		// which holds more info on the controller (how to talk to it for example).
@@ -248,7 +262,7 @@
 		try {
 			leader = latch.getLeader();
 		} catch (Exception e) {
-			throw new Exception("Error contacting the Zookeeper service", e);
+			throw new RegistryException("Error contacting the Zookeeper service", e);
 		}
 		
 		return leader.getId();
@@ -288,7 +302,19 @@
 	
 	@Override
 	public void init (FloodlightModuleContext context) throws FloodlightModuleException {
-		/*
+		
+		//Read config to see if we should try and connect to zookeeper
+		Map<String, String> configOptions = context.getConfigParams(this);
+		String enableZookeeper = configOptions.get("enableZookeeper");
+		if (enableZookeeper != null) {
+			log.info("Enabling Mastership module - requires Zookeeper connection");
+			moduleEnabled = true;
+		}
+		else {
+			log.info("Mastership module is disabled");
+			return;
+		}
+		
 		try {
 			String localHostname = java.net.InetAddress.getLocalHost().getHostName();
 			mastershipId = localHostname;
@@ -301,7 +327,8 @@
 		switchLatches = new HashMap<String, LeaderLatch>();
 		switchCallbacks = new HashMap<String, MastershipCallback>();
 		
-		RetryPolicy retryPolicy = new ExponentialBackoffRetry(1000, 3);
+		//RetryPolicy retryPolicy = new ExponentialBackoffRetry(1000, 3);
+		RetryPolicy retryPolicy = new RetryOneTime(0);
 		client = CuratorFrameworkFactory.newClient(connectionString, retryPolicy);
 		
 		client.start();
@@ -312,13 +339,10 @@
 		
 		try {
 			controllerCache.start(StartMode.BUILD_INITIAL_CACHE);
-			
-			
 		} catch (Exception e) {
 			// TODO Auto-generated catch block
 			e.printStackTrace();
 		}
-	*/
 	}
 	
 	@Override
diff --git a/src/main/java/net/floodlightcontroller/mastership/RegistryException.java b/src/main/java/net/floodlightcontroller/mastership/RegistryException.java
index 134117c..fcc14a6 100644
--- a/src/main/java/net/floodlightcontroller/mastership/RegistryException.java
+++ b/src/main/java/net/floodlightcontroller/mastership/RegistryException.java
@@ -3,12 +3,13 @@
 public class RegistryException extends Exception {
 
 	private static final long serialVersionUID = -8276300722010217913L;
-
+	
 	/*
 	public RegistryException() {
 		// TODO Auto-generated constructor stub
 	}
 
+	
 	public RegistryException(String message) {
 		super(message);
 		// TODO Auto-generated constructor stub
@@ -18,17 +19,10 @@
 		super(cause);
 		// TODO Auto-generated constructor stub
 	}
-
+	*/
+	
 	public RegistryException(String message, Throwable cause) {
 		super(message, cause);
-		// TODO Auto-generated constructor stub
 	}
 
-	public RegistryException(String message, Throwable cause,
-			boolean enableSuppression, boolean writableStackTrace) {
-		super(message, cause, enableSuppression, writableStackTrace);
-		// TODO Auto-generated constructor stub
-	}
-	*/
-
 }