Changed some non concurrent structures to ConcurrentHashMaps in
SimpleIntentStore and OpenFlowRuleProvider.

Also improved logging in IntentManager so exception stack traces are logged.

Change-Id: I72f5e20893bda633dc36ea271a0f56c0ddb7fb5a
diff --git a/core/net/src/main/java/org/onlab/onos/net/intent/impl/IntentManager.java b/core/net/src/main/java/org/onlab/onos/net/intent/impl/IntentManager.java
index cb807d5..ff1e948 100644
--- a/core/net/src/main/java/org/onlab/onos/net/intent/impl/IntentManager.java
+++ b/core/net/src/main/java/org/onlab/onos/net/intent/impl/IntentManager.java
@@ -251,7 +251,7 @@
             executeInstallingPhase(intent);
 
         } catch (Exception e) {
-            log.warn("Unable to compile intent {} due to: {}", intent.id(), e);
+            log.warn("Unable to compile intent {} due to:", intent.id(), e);
 
             // If compilation failed, mark the intent as failed.
             store.setState(intent, FAILED);
@@ -304,7 +304,7 @@
             //eventDispatcher.post(store.setState(intent, INSTALLED));
             monitorExecutor.execute(new IntentInstallMonitor(intent, installWork, INSTALLED));
         } catch (Exception e) {
-            log.warn("Unable to install intent {} due to: {}", intent.id(), e);
+            log.warn("Unable to install intent {} due to:", intent.id(), e);
             uninstallIntent(intent, RECOMPILING);
 
             // If compilation failed, kick off the recompiling phase.
@@ -342,7 +342,7 @@
                 executeInstallingPhase(intent);
             }
         } catch (Exception e) {
-            log.warn("Unable to recompile intent {} due to: {}", intent.id(), e);
+            log.warn("Unable to recompile intent {} due to:", intent.id(), e);
 
             // If compilation failed, mark the intent as failed.
             eventDispatcher.post(store.setState(intent, FAILED));
@@ -385,7 +385,7 @@
             }
             monitorExecutor.execute(new IntentInstallMonitor(intent, uninstallWork, nextState));
         } catch (IntentException e) {
-            log.warn("Unable to uninstall intent {} due to: {}", intent.id(), e);
+            log.warn("Unable to uninstall intent {} due to:", intent.id(), e);
         }
     }
 
diff --git a/core/store/trivial/src/main/java/org/onlab/onos/store/trivial/impl/SimpleIntentStore.java b/core/store/trivial/src/main/java/org/onlab/onos/store/trivial/impl/SimpleIntentStore.java
index 732d753..c7f656a 100644
--- a/core/store/trivial/src/main/java/org/onlab/onos/store/trivial/impl/SimpleIntentStore.java
+++ b/core/store/trivial/src/main/java/org/onlab/onos/store/trivial/impl/SimpleIntentStore.java
@@ -1,6 +1,15 @@
 package org.onlab.onos.store.trivial.impl;
 
-import com.google.common.collect.ImmutableSet;
+import static org.onlab.onos.net.intent.IntentState.FAILED;
+import static org.onlab.onos.net.intent.IntentState.INSTALLED;
+import static org.onlab.onos.net.intent.IntentState.SUBMITTED;
+import static org.onlab.onos.net.intent.IntentState.WITHDRAWN;
+import static org.slf4j.LoggerFactory.getLogger;
+
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
 import org.apache.felix.scr.annotations.Activate;
 import org.apache.felix.scr.annotations.Component;
 import org.apache.felix.scr.annotations.Deactivate;
@@ -15,12 +24,7 @@
 import org.onlab.onos.store.AbstractStore;
 import org.slf4j.Logger;
 
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import static org.onlab.onos.net.intent.IntentState.*;
-import static org.slf4j.LoggerFactory.getLogger;
+import com.google.common.collect.ImmutableSet;
 
 @Component(immediate = true)
 @Service
@@ -29,9 +33,10 @@
         implements IntentStore {
 
     private final Logger log = getLogger(getClass());
-    private final Map<IntentId, Intent> intents = new HashMap<>();
-    private final Map<IntentId, IntentState> states = new HashMap<>();
-    private final Map<IntentId, List<InstallableIntent>> installable = new HashMap<>();
+    private final Map<IntentId, Intent> intents = new ConcurrentHashMap<>();
+    private final Map<IntentId, IntentState> states = new ConcurrentHashMap<>();
+    private final Map<IntentId, List<InstallableIntent>> installable =
+            new ConcurrentHashMap<>();
 
     @Activate
     public void activate() {
diff --git a/providers/openflow/flow/src/main/java/org/onlab/onos/provider/of/flow/impl/OpenFlowRuleProvider.java b/providers/openflow/flow/src/main/java/org/onlab/onos/provider/of/flow/impl/OpenFlowRuleProvider.java
index 94d1282..dfa2bea 100644
--- a/providers/openflow/flow/src/main/java/org/onlab/onos/provider/of/flow/impl/OpenFlowRuleProvider.java
+++ b/providers/openflow/flow/src/main/java/org/onlab/onos/provider/of/flow/impl/OpenFlowRuleProvider.java
@@ -1,9 +1,20 @@
 package org.onlab.onos.provider.of.flow.impl;
 
-import com.google.common.collect.ArrayListMultimap;
-import com.google.common.collect.Lists;
-import com.google.common.collect.Maps;
-import com.google.common.collect.Multimap;
+import static org.slf4j.LoggerFactory.getLogger;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.Future;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.TimeoutException;
+import java.util.concurrent.atomic.AtomicBoolean;
+
 import org.apache.felix.scr.annotations.Activate;
 import org.apache.felix.scr.annotations.Component;
 import org.apache.felix.scr.annotations.Deactivate;
@@ -57,20 +68,10 @@
 import org.projectfloodlight.openflow.types.U32;
 import org.slf4j.Logger;
 
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.CountDownLatch;
-import java.util.concurrent.ExecutionException;
-import java.util.concurrent.Future;
-import java.util.concurrent.TimeUnit;
-import java.util.concurrent.TimeoutException;
-import java.util.concurrent.atomic.AtomicBoolean;
-
-import static org.slf4j.LoggerFactory.getLogger;
+import com.google.common.collect.ArrayListMultimap;
+import com.google.common.collect.Lists;
+import com.google.common.collect.Maps;
+import com.google.common.collect.Multimap;
 
 /**
  * Provider which uses an OpenFlow controller to detect network
@@ -159,7 +160,8 @@
 
     @Override
     public Future<CompletedBatchOperation> executeBatch(BatchOperation<FlowRuleBatchEntry> batch) {
-        final Set<Dpid> sws = new HashSet<Dpid>();
+        final Set<Dpid> sws =
+                Collections.newSetFromMap(new ConcurrentHashMap<Dpid, Boolean>());
         final Map<Long, FlowRuleBatchEntry> fmXids = new HashMap<Long, FlowRuleBatchEntry>();
         OFFlowMod mod = null;
         for (FlowRuleBatchEntry fbe : batch.getOperations()) {