Refactor getIntegerProperty and isPropertyEnabled methods into Tools
- Add getIntegerProperty and isPropertyEnabled methods which take
default value as third parameter
- Remove all duplicated code from RefactiveForwarding, GroupManager,
FlowRuleManager, CoreManager, HostLocationProvider and ProxyArp
Change-Id: Ifc93aa813acfdd4cbac0166497d7b526b08b2090
diff --git a/core/net/src/main/java/org/onosproject/core/impl/CoreManager.java b/core/net/src/main/java/org/onosproject/core/impl/CoreManager.java
index b1e781a..98101ac 100644
--- a/core/net/src/main/java/org/onosproject/core/impl/CoreManager.java
+++ b/core/net/src/main/java/org/onosproject/core/impl/CoreManager.java
@@ -25,6 +25,7 @@
import org.apache.felix.scr.annotations.Service;
import org.onlab.metrics.MetricsService;
import org.onlab.util.SharedExecutors;
+import org.onlab.util.Tools;
import org.onosproject.app.ApplicationService;
import org.onosproject.cfg.ComponentConfigService;
import org.onosproject.core.ApplicationId;
@@ -48,9 +49,9 @@
import java.util.Set;
import static com.google.common.base.Preconditions.checkNotNull;
-import static com.google.common.base.Strings.isNullOrEmpty;
import static org.onosproject.security.AppGuard.checkPermission;
-import static org.onosproject.security.AppPermission.Type.*;
+import static org.onosproject.security.AppPermission.Type.APP_READ;
+import static org.onosproject.security.AppPermission.Type.APP_WRITE;
/**
@@ -172,7 +173,7 @@
@Modified
public void modified(ComponentContext context) {
Dictionary<?, ?> properties = context.getProperties();
- Integer poolSize = getIntegerProperty(properties, "sharedThreadPoolSize");
+ Integer poolSize = Tools.getIntegerProperty(properties, "sharedThreadPoolSize");
if (poolSize != null && poolSize > 1) {
sharedThreadPoolSize = poolSize;
@@ -181,7 +182,7 @@
log.warn("sharedThreadPoolSize must be greater than 1");
}
- Integer timeLimit = getIntegerProperty(properties, "maxEventTimeLimit");
+ Integer timeLimit = Tools.getIntegerProperty(properties, "maxEventTimeLimit");
if (timeLimit != null && timeLimit > 1) {
maxEventTimeLimit = timeLimit;
eventDeliveryService.setDispatchTimeLimit(maxEventTimeLimit);
@@ -189,7 +190,7 @@
log.warn("maxEventTimeLimit must be greater than 1");
}
- Boolean performanceCheck = isPropertyEnabled(properties, "sharedThreadPerformanceCheck");
+ Boolean performanceCheck = Tools.isPropertyEnabled(properties, "sharedThreadPerformanceCheck");
if (performanceCheck != null) {
calculatePoolPerformance = performanceCheck;
SharedExecutors.setCalculatePoolPerformance(calculatePoolPerformance, metricsService);
@@ -198,48 +199,4 @@
log.info("Settings: sharedThreadPoolSize={}, maxEventTimeLimit={}, calculatePoolPerformance={}",
sharedThreadPoolSize, maxEventTimeLimit, calculatePoolPerformance);
}
-
-
- /**
- * Get Integer property from the propertyName
- * Return null if propertyName is not found.
- *
- * @param properties properties to be looked up
- * @param propertyName the name of the property to look up
- * @return value when the propertyName is defined or return null
- */
- private static Integer getIntegerProperty(Dictionary<?, ?> properties,
- String propertyName) {
- Integer value;
- try {
- String s = (String) properties.get(propertyName);
- value = isNullOrEmpty(s) ? null : Integer.parseInt(s.trim());
- } catch (NumberFormatException | ClassCastException e) {
- value = null;
- }
- return value;
- }
-
- /**
- * Check property name is defined and set to true.
- *
- * @param properties properties to be looked up
- * @param propertyName the name of the property to look up
- * @return value when the propertyName is defined or return null
- */
- private static Boolean isPropertyEnabled(Dictionary<?, ?> properties,
- String propertyName) {
- Boolean value = null;
- try {
- String s = (String) properties.get(propertyName);
- value = isNullOrEmpty(s) ? null : s.trim().equals("true");
- } catch (ClassCastException e) {
- // No propertyName defined.
- value = null;
- }
- return value;
- }
-
-
-
}
diff --git a/core/net/src/main/java/org/onosproject/net/flow/impl/FlowRuleManager.java b/core/net/src/main/java/org/onosproject/net/flow/impl/FlowRuleManager.java
index 93ddf1a..94a782a 100644
--- a/core/net/src/main/java/org/onosproject/net/flow/impl/FlowRuleManager.java
+++ b/core/net/src/main/java/org/onosproject/net/flow/impl/FlowRuleManager.java
@@ -29,6 +29,7 @@
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.ReferenceCardinality;
import org.apache.felix.scr.annotations.Service;
+import org.onlab.util.Tools;
import org.onosproject.cfg.ComponentConfigService;
import org.onosproject.core.ApplicationId;
import org.onosproject.core.CoreService;
@@ -190,7 +191,7 @@
Dictionary<?, ?> properties = context.getProperties();
Boolean flag;
- flag = isPropertyEnabled(properties, "allowExtraneousRules");
+ flag = Tools.isPropertyEnabled(properties, "allowExtraneousRules");
if (flag == null) {
log.info("AllowExtraneousRules is not configured, " +
"using current value of {}", allowExtraneousRules);
@@ -200,7 +201,7 @@
allowExtraneousRules ? "enabled" : "disabled");
}
- flag = isPropertyEnabled(properties, "purgeOnDisconnection");
+ flag = Tools.isPropertyEnabled(properties, "purgeOnDisconnection");
if (flag == null) {
log.info("PurgeOnDisconnection is not configured, " +
"using current value of {}", purgeOnDisconnection);
@@ -218,24 +219,6 @@
}
}
- /**
- * Check property name is defined and set to true.
- *
- * @param properties properties to be looked up
- * @param propertyName the name of the property to look up
- * @return value when the propertyName is defined or return null
- */
- private static Boolean isPropertyEnabled(Dictionary<?, ?> properties,
- String propertyName) {
- try {
- String s = (String) properties.get(propertyName);
- return isNullOrEmpty(s) ? null : s.trim().equals("true");
- } catch (ClassCastException e) {
- // No propertyName defined.
- return null;
- }
- }
-
@Override
public int getFlowRuleCount() {
checkPermission(FLOWRULE_READ);
diff --git a/core/net/src/main/java/org/onosproject/net/group/impl/GroupManager.java b/core/net/src/main/java/org/onosproject/net/group/impl/GroupManager.java
index e9d76fb..8355aa8 100644
--- a/core/net/src/main/java/org/onosproject/net/group/impl/GroupManager.java
+++ b/core/net/src/main/java/org/onosproject/net/group/impl/GroupManager.java
@@ -23,8 +23,8 @@
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.ReferenceCardinality;
import org.apache.felix.scr.annotations.Service;
+import org.onlab.util.Tools;
import org.onosproject.cfg.ComponentConfigService;
-import org.onosproject.net.provider.AbstractListenerProviderRegistry;
import org.onosproject.core.ApplicationId;
import org.onosproject.net.DeviceId;
import org.onosproject.net.device.DeviceEvent;
@@ -45,6 +45,7 @@
import org.onosproject.net.group.GroupStore;
import org.onosproject.net.group.GroupStore.UpdateType;
import org.onosproject.net.group.GroupStoreDelegate;
+import org.onosproject.net.provider.AbstractListenerProviderRegistry;
import org.onosproject.net.provider.AbstractProviderService;
import org.osgi.service.component.ComponentContext;
import org.slf4j.Logger;
@@ -53,10 +54,10 @@
import java.util.Collections;
import java.util.Dictionary;
-import static com.google.common.base.Strings.isNullOrEmpty;
import static org.onosproject.security.AppGuard.checkPermission;
+import static org.onosproject.security.AppPermission.Type.GROUP_READ;
+import static org.onosproject.security.AppPermission.Type.GROUP_WRITE;
import static org.slf4j.LoggerFactory.getLogger;
-import static org.onosproject.security.AppPermission.Type.*;
@@ -129,7 +130,7 @@
Dictionary<?, ?> properties = context.getProperties();
Boolean flag;
- flag = isPropertyEnabled(properties, "purgeOnDisconnection");
+ flag = Tools.isPropertyEnabled(properties, "purgeOnDisconnection");
if (flag == null) {
log.info("PurgeOnDisconnection is not configured, " +
"using current value of {}", purgeOnDisconnection);
@@ -141,26 +142,6 @@
}
/**
- * Check property name is defined and set to true.
- *
- * @param properties properties to be looked up
- * @param propertyName the name of the property to look up
- * @return value when the propertyName is defined or return null
- */
- private static Boolean isPropertyEnabled(Dictionary<?, ?> properties,
- String propertyName) {
- Boolean value = null;
- try {
- String s = (String) properties.get(propertyName);
- value = isNullOrEmpty(s) ? null : s.trim().equals("true");
- } catch (ClassCastException e) {
- // No propertyName defined.
- value = null;
- }
- return value;
- }
-
- /**
* Create a group in the specified device with the provided parameters.
*
* @param groupDesc group creation parameters