add persistance of intents to ramcloud

Change-Id: I9a8b5886cf57da0621dc92e341d46c53d252528a
diff --git a/src/main/java/net/onrc/onos/registry/controller/IControllerRegistryService.java b/src/main/java/net/onrc/onos/registry/controller/IControllerRegistryService.java
old mode 100644
new mode 100755
index 33ba272..576eed4
--- a/src/main/java/net/onrc/onos/registry/controller/IControllerRegistryService.java
+++ b/src/main/java/net/onrc/onos/registry/controller/IControllerRegistryService.java
@@ -116,6 +116,15 @@
 	 */
 	public Collection<Long> getSwitchesControlledByController(String controllerId);
 	
+        /**
+         * Get 
+         * @return 
+         */
 	public IdBlock allocateUniqueIdBlock();
+        
+        /**
+         * Get next unique id and retrieve a new range of ids if needed.
+         */
+        public IdBlock allocateUniqueIdBlock(long range);
 	
 }
diff --git a/src/main/java/net/onrc/onos/registry/controller/StandaloneRegistry.java b/src/main/java/net/onrc/onos/registry/controller/StandaloneRegistry.java
old mode 100644
new mode 100755
index 319ea48..69e7b3e
--- a/src/main/java/net/onrc/onos/registry/controller/StandaloneRegistry.java
+++ b/src/main/java/net/onrc/onos/registry/controller/StandaloneRegistry.java
@@ -172,4 +172,9 @@
 		restApi.addRestletRoutable(new RegistryWebRoutable());
 	}
 
+    @Override
+    public IdBlock allocateUniqueIdBlock(long range) {
+        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
+    }
+
 }
diff --git a/src/main/java/net/onrc/onos/registry/controller/ZookeeperRegistry.java b/src/main/java/net/onrc/onos/registry/controller/ZookeeperRegistry.java
old mode 100644
new mode 100755
index 3e4d5bf..8706e85
--- a/src/main/java/net/onrc/onos/registry/controller/ZookeeperRegistry.java
+++ b/src/main/java/net/onrc/onos/registry/controller/ZookeeperRegistry.java
@@ -41,6 +41,8 @@
 import com.netflix.curator.x.discovery.ServiceDiscovery;
 import com.netflix.curator.x.discovery.ServiceDiscoveryBuilder;
 import com.netflix.curator.x.discovery.ServiceInstance;
+import java.util.concurrent.ArrayBlockingQueue;
+import java.util.concurrent.BlockingQueue;
 
 /**
  * A registry service that uses Zookeeper. All data is stored in Zookeeper,
@@ -78,6 +80,7 @@
 	//Zookeeper performance-related configuration
 	protected static final int sessionTimeout = 5000;
 	protected static final int connectionTimeout = 7000;
+        private volatile IdBlock idBlock = null;
 	
 
 	protected class SwitchLeaderListener implements LeaderLatchListener{
@@ -385,27 +388,31 @@
 		return data;
 	}
 	
+        public IdBlock allocateUniqueIdBlock(long range) {
+            try {
+                AtomicValue<Long> result = null;
+                do {
+                    result = distributedIdCounter.add(range);
+                } while (result == null || !result.succeeded());
+
+                return new IdBlock(result.preValue(), result.postValue() - 1, range);
+            } catch (Exception e) {
+                log.error("Error allocating ID block");
+            }
+            return null;
+        }
+        
 	/**
 	 * Returns a block of IDs which are unique and unused.
 	 * Range of IDs is fixed size and is assigned incrementally as this method called.
 	 * Since the range of IDs is managed by Zookeeper in distributed way, this method may block when
 	 * requests come up simultaneously.
 	 */
+        @Override
 	public IdBlock allocateUniqueIdBlock(){
-		try {
-			AtomicValue<Long> result = null;
-			do {
-				result = distributedIdCounter.add(ID_BLOCK_SIZE);
-			} while (result == null || !result.succeeded());
-			
-			return new IdBlock(result.preValue(), result.postValue() - 1, ID_BLOCK_SIZE);
-		} catch (Exception e) {
-			log.error("Error allocating ID block");
-		} 
-		
-		return null;
+            return allocateUniqueIdBlock(ID_BLOCK_SIZE);
 	}
-	
+            
 	/*
 	 * IFloodlightModule
 	 */