Merge branch 'master' of https://github.com/OPENNETWORKINGLAB/ONOS
diff --git a/src/main/java/net/floodlightcontroller/core/internal/Controller.java b/src/main/java/net/floodlightcontroller/core/internal/Controller.java
index 6e816c7..a5ee71a 100644
--- a/src/main/java/net/floodlightcontroller/core/internal/Controller.java
+++ b/src/main/java/net/floodlightcontroller/core/internal/Controller.java
@@ -139,8 +139,18 @@
  */
 public class Controller implements IFloodlightProviderService, 
             IStorageSourceListener {
-    
-	protected SwitchStorageImpl swStore;
+   
+	ThreadLocal<SwitchStorageImpl> store = new ThreadLocal<SwitchStorageImpl>() {
+		@Override
+		protected SwitchStorageImpl initialValue() {
+			SwitchStorageImpl swStore = new SwitchStorageImpl();
+			//TODO: Get the file path from global properties
+			swStore.init("/tmp/cassandra.titan");
+			return swStore;
+		}
+	};
+	
+	protected SwitchStorageImpl swStore = store.get();
 	
     protected static Logger log = LoggerFactory.getLogger(Controller.class);
 
@@ -2072,8 +2082,6 @@
         this.roleChanger = new RoleChanger();
         initVendorMessages();
         this.systemStartTime = System.currentTimeMillis();
-        this.swStore = new SwitchStorageImpl();
-        this.swStore.init("/tmp/cassandra.titan");
     }
     
     /**
diff --git a/src/main/java/net/floodlightcontroller/linkdiscovery/internal/LinkDiscoveryManager.java b/src/main/java/net/floodlightcontroller/linkdiscovery/internal/LinkDiscoveryManager.java
index 78fe407..c432987 100644
--- a/src/main/java/net/floodlightcontroller/linkdiscovery/internal/LinkDiscoveryManager.java
+++ b/src/main/java/net/floodlightcontroller/linkdiscovery/internal/LinkDiscoveryManager.java
@@ -193,7 +193,17 @@
     int lldpTimeCount = 0;
 
     // Storage
-    protected LinkStorageImpl linkStore;
+
+    ThreadLocal<LinkStorageImpl> store = new ThreadLocal<LinkStorageImpl>() {
+		@Override
+		protected LinkStorageImpl initialValue() {
+			LinkStorageImpl swStore = new LinkStorageImpl();
+			//TODO: Get the file path from global properties
+			swStore.init("/tmp/cassandra.titan");
+			return swStore;
+		}
+	};
+    protected LinkStorageImpl linkStore = store.get();
    // protected SwitchStorageImpl swStore;
     
     /**
@@ -525,7 +535,8 @@
     	
     	// add a switch if we have not seen it before
     	remotesw = remoteSwitches.get(sw);
-        if (remotesw == null) {
+
+    	if (remotesw == null) {
         	remotesw = new OFSwitchImpl();
         	remotesw.setupRemoteSwitch(sw);
         	remoteSwitches.put(remotesw.getId(), remotesw);
@@ -1861,7 +1872,7 @@
         this.quarantineQueue = new LinkedBlockingQueue<NodePortTuple>();
         this.maintenanceQueue = new LinkedBlockingQueue<NodePortTuple>();
         this.remoteSwitches = new HashMap<Long, IOFSwitch>();
-        
+
         this.evHistTopologySwitch =
                 new EventHistory<EventHistoryTopologySwitch>("Topology: Switch");
         this.evHistTopologyLink =
@@ -1911,16 +1922,7 @@
             log.error("Error in installing listener for " +
             		  "switch table {}", SWITCH_CONFIG_TABLE_NAME);
         }
-
-        // Initialize the link storage connector to the network map
-        this.linkStore = new LinkStorageImpl();
-        this.linkStore.init("/tmp/cassandra.titan");
-        
-        // Initialieze the switch storage connector to the network map. We may need to delete switches.
-        // TODO find a better place to delete switches and ports from network map
-        // this.swStore = new SwitchStorageImpl();
-        // this.swStore.init("/tmp/cassandra.titan");
-        
+                
         ScheduledExecutorService ses = threadPool.getScheduledExecutor();
 
         // To be started by the first switch connection