BUG-529: Remove Reactor getter contention 41/7541/1
authorRobert Varga <robert.varga@pantheon.sk>
Fri, 30 May 2014 15:55:17 +0000 (17:55 +0200)
committerRobert Varga <robert.varga@pantheon.sk>
Fri, 30 May 2014 15:57:19 +0000 (17:57 +0200)
Performance testing has identified contention on getInstance() methods.
It turns out that we can pre-create the instance and then get it in a
lock-free manner.

Change-Id: I49c219d5954fa792218040a0ae66bf344992413a
Signed-off-by: Robert Varga <robert.varga@pantheon.sk>
openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/ActionSetNwDstReactor.java
openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/ActionSetNwSrcReactor.java
openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/flowflag/FlowFlagReactor.java
openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/match/MatchReactor.java

index 7213335083903a95c67ab9f4e64a733c502cee83..1e5f8637987836eab3bcb44a43bdc8b592d5ae93 100644 (file)
@@ -18,36 +18,33 @@ import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.Res
 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetNwDstActionCase;
 
 /**
- * 
+ *
  */
 public class ActionSetNwDstReactor extends ConvertReactor<SetNwDstActionCase> {
-    
-    private static ActionSetNwDstReactor instance;
-    
+
+    private static ActionSetNwDstReactor INSTANCE = new ActionSetNwDstReactor();
+
     private ActionSetNwDstReactor() {
         //NOOP
     }
-    
+
     /**
      * @return singleton
      */
-    public static synchronized ActionSetNwDstReactor getInstance() {
-        if (instance == null) {
-            instance = new ActionSetNwDstReactor();
-        }
-        return instance;
+    public static ActionSetNwDstReactor getInstance() {
+        return INSTANCE;
     }
-    
+
     @Override
-    protected void initMappings(Map<Short, Convertor<SetNwDstActionCase,?>> conversions, 
-            Map<InjectionKey, ResultInjector<?,?>> injections) {
+    protected void initMappings(final Map<Short, Convertor<SetNwDstActionCase,?>> conversions,
+            final Map<InjectionKey, ResultInjector<?,?>> injections) {
         ActionSetNwDstReactorMappingFactory.addSetNwDstConvertors(conversions);
         ActionSetNwDstReactorMappingFactory.addSetNwDstInjectors(injections);
     }
-    
+
     @Override
-    protected InjectionKey buildInjectionKey(short version,
-            Object convertedItem, Object target) {
+    protected InjectionKey buildInjectionKey(final short version,
+            final Object convertedItem, final Object target) {
         InjectionResultTargetKey key = null;
         if (convertedItem != null) {
              key = new InjectionResultTargetKey(version, target.getClass().getName(), convertedItem.getClass().getName());
index ad3ba9c1089543a7379d4051997855b2b721aca4..e9d55f875e2907eb719a1dab41bcdfc3630f0a87 100644 (file)
@@ -18,36 +18,33 @@ import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.Res
 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetNwSrcActionCase;
 
 /**
- * 
+ *
  */
 public class ActionSetNwSrcReactor extends ConvertReactor<SetNwSrcActionCase> {
-    
-    private static ActionSetNwSrcReactor instance;
-    
+
+    private static ActionSetNwSrcReactor INSTANCE = new ActionSetNwSrcReactor();
+
     private ActionSetNwSrcReactor() {
         //NOOP
     }
-    
+
     /**
      * @return singleton
      */
-    public static synchronized ActionSetNwSrcReactor getInstance() {
-        if (instance == null) {
-            instance = new ActionSetNwSrcReactor();
-        }
-        return instance;
+    public static ActionSetNwSrcReactor getInstance() {
+        return INSTANCE;
     }
-    
+
     @Override
-    protected void initMappings(Map<Short, Convertor<SetNwSrcActionCase,?>> conversions, 
-            Map<InjectionKey, ResultInjector<?,?>> injections) {
+    protected void initMappings(final Map<Short, Convertor<SetNwSrcActionCase,?>> conversions,
+            final Map<InjectionKey, ResultInjector<?,?>> injections) {
         ActionSetNwSrcReactorMappingFactory.addSetNwSrcConvertors(conversions);
         ActionSetNwSrcReactorMappingFactory.addSetNwSrcInjectors(injections);
     }
-    
+
     @Override
-    protected InjectionKey buildInjectionKey(short version,
-            Object convertedItem, Object target) {
+    protected InjectionKey buildInjectionKey(final short version,
+            final Object convertedItem, final Object target) {
         InjectionResultTargetKey key = null;
         if (convertedItem != null) {
              key = new InjectionResultTargetKey(version, target.getClass().getName(), convertedItem.getClass().getName());
index 4d208e8aa5cb0e237ad892af59fe07296921aeba..05f6a5a06414a514713eec183b522a7a4e687bed 100644 (file)
@@ -17,29 +17,26 @@ import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.Res
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.FlowModFlags;
 
 /**
- * 
+ *
  */
 public class FlowFlagReactor extends ConvertReactor<FlowModFlags> {
-    
-    private static FlowFlagReactor instance;
-    
+
+    private static FlowFlagReactor INSTANCE = new FlowFlagReactor();
+
     private FlowFlagReactor() {
         //NOOP
     }
-    
+
     /**
      * @return singleton
      */
-    public static synchronized FlowFlagReactor getInstance() {
-        if (instance == null) {
-            instance = new FlowFlagReactor();
-        }
-        return instance;
+    public static FlowFlagReactor getInstance() {
+        return INSTANCE;
     }
-    
+
     @Override
-    protected void initMappings(Map<Short, Convertor<FlowModFlags, ?>> conversions, 
-            Map<InjectionKey, ResultInjector<?,?>> injections) {
+    protected void initMappings(final Map<Short, Convertor<FlowModFlags, ?>> conversions,
+            final Map<InjectionKey, ResultInjector<?,?>> injections) {
         FlowFlagReactorMappingFactory.addFlowFlagsConvertors(conversions);
         FlowFlagReactorMappingFactory.addFlowFlagsIjectors(injections);
     }
index 1b27b84748e56622d672ecba206431a2e35b6279..abb5ea0698ddb4fb5b30c57fbb590cfa18a6119f 100644 (file)
@@ -17,31 +17,27 @@ import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.common.Res
 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.Match;
 
 /**
- * 
+ *
  */
 public class MatchReactor extends ConvertReactor<Match> {
-    
-    private static MatchReactor instance;
-    
+
+    private static MatchReactor INSTANCE = new MatchReactor();
+
     private MatchReactor() {
         //NOOP
     }
-    
+
     /**
      * @return singleton
      */
-    public static synchronized MatchReactor getInstance() {
-        if (instance == null) {
-            instance = new MatchReactor();
-        }
-        return instance;
+    public static MatchReactor getInstance() {
+        return INSTANCE;
     }
-    
+
     @Override
-    protected void initMappings(Map<Short, Convertor<Match,?>> conversions, 
-            Map<InjectionKey, ResultInjector<?,?>> injections) {
+    protected void initMappings(final Map<Short, Convertor<Match,?>> conversions,
+            final Map<InjectionKey, ResultInjector<?,?>> injections) {
         MatchReactorMappingFactory.addMatchConvertors(conversions);
         MatchReactorMappingFactory.addMatchIjectors(injections);
     }
-
 }