From 9fe23c3d6e9db28fa7ad14a1949b3add13b9015d Mon Sep 17 00:00:00 2001 From: Robert Varga Date: Fri, 30 May 2014 17:55:17 +0200 Subject: [PATCH] BUG-529: Remove Reactor getter contention 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 --- .../action/ActionSetNwDstReactor.java | 29 +++++++++---------- .../action/ActionSetNwSrcReactor.java | 29 +++++++++---------- .../convertor/flowflag/FlowFlagReactor.java | 23 +++++++-------- .../sal/convertor/match/MatchReactor.java | 24 +++++++-------- 4 files changed, 46 insertions(+), 59 deletions(-) diff --git a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/ActionSetNwDstReactor.java b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/ActionSetNwDstReactor.java index 7213335083..1e5f863798 100644 --- a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/ActionSetNwDstReactor.java +++ b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/ActionSetNwDstReactor.java @@ -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 { - - 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> conversions, - Map> injections) { + protected void initMappings(final Map> conversions, + final Map> 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()); diff --git a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/ActionSetNwSrcReactor.java b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/ActionSetNwSrcReactor.java index ad3ba9c108..e9d55f875e 100644 --- a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/ActionSetNwSrcReactor.java +++ b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/action/ActionSetNwSrcReactor.java @@ -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 { - - 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> conversions, - Map> injections) { + protected void initMappings(final Map> conversions, + final Map> 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()); diff --git a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/flowflag/FlowFlagReactor.java b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/flowflag/FlowFlagReactor.java index 4d208e8aa5..05f6a5a064 100644 --- a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/flowflag/FlowFlagReactor.java +++ b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/flowflag/FlowFlagReactor.java @@ -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 { - - 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> conversions, - Map> injections) { + protected void initMappings(final Map> conversions, + final Map> injections) { FlowFlagReactorMappingFactory.addFlowFlagsConvertors(conversions); FlowFlagReactorMappingFactory.addFlowFlagsIjectors(injections); } diff --git a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/match/MatchReactor.java b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/match/MatchReactor.java index 1b27b84748..abb5ea0698 100644 --- a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/match/MatchReactor.java +++ b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/sal/convertor/match/MatchReactor.java @@ -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 { - - 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> conversions, - Map> injections) { + protected void initMappings(final Map> conversions, + final Map> injections) { MatchReactorMappingFactory.addMatchConvertors(conversions); MatchReactorMappingFactory.addMatchIjectors(injections); } - } -- 2.36.6