diff --git a/opendj-cli/src/main/java/com/forgerock/opendj/cli/ConnectionFactoryProvider.java b/opendj-cli/src/main/java/com/forgerock/opendj/cli/ConnectionFactoryProvider.java index 77c90ccd8f..c15a0c1e98 100644 --- a/opendj-cli/src/main/java/com/forgerock/opendj/cli/ConnectionFactoryProvider.java +++ b/opendj-cli/src/main/java/com/forgerock/opendj/cli/ConnectionFactoryProvider.java @@ -18,6 +18,7 @@ package com.forgerock.opendj.cli; import static com.forgerock.opendj.cli.ArgumentConstants.*; +import static com.forgerock.opendj.cli.CliConstants.DEFAULT_LDAP_CONNECT_TIMEOUT; import static com.forgerock.opendj.cli.CliConstants.DEFAULT_LDAP_PORT; import static com.forgerock.opendj.cli.CliMessages.*; import static com.forgerock.opendj.cli.Utils.getHostNameForLdapUrl; @@ -140,6 +141,9 @@ public final class ConnectionFactoryProvider { /** If this connection should be an admin connection. */ private boolean isAdminConnection; + /** The port to use when the port argument has no default value. */ + private final int defaultPort; + /** * Default constructor to create a connection factory designed for use with command line tools, * adding basic LDAP connection arguments to the specified parser (e.g: hostname, bindname...etc). @@ -177,6 +181,7 @@ public ConnectionFactoryProvider(final ArgumentParser argumentParser, final ConsoleApplication app, final String defaultBindDN, final int defaultPort, final boolean alwaysSSL) throws ArgumentException { this.app = app; + this.defaultPort = defaultPort; useSSLArg = useSSLArgument(); if (!alwaysSSL) { @@ -261,10 +266,14 @@ public int getConnectTimeout() { try { return connectTimeOut.getIntValue(); } catch (ArgumentException e) { - return Integer.valueOf(connectTimeOut.getDefaultValue()); + return getDefaultConnectTimeout(); } } - return Integer.valueOf(connectTimeOut.getDefaultValue()); + return getDefaultConnectTimeout(); + } + + private int getDefaultConnectTimeout() { + return connectTimeOut.getDefaultIntValue(DEFAULT_LDAP_CONNECT_TIMEOUT); } @@ -311,18 +320,22 @@ public int getPort() { try { return portArg.getIntValue(); } catch (ArgumentException e) { - return Integer.valueOf(portArg.getDefaultValue()); + return getDefaultPort(); } } else if (app.isInteractive()) { final LocalizableMessage portMsg = isAdminConnection ? INFO_DESCRIPTION_ADMIN_PORT.get() : INFO_DESCRIPTION_PORT.get(); - int value = app.askPort(portMsg, Integer.valueOf(portArg.getDefaultValue()), logger); + int value = app.askPort(portMsg, getDefaultPort(), logger); app.println(); portArg.addValue(Integer.toString(value)); portArg.setPresent(true); return value; } - return Integer.valueOf(portArg.getDefaultValue()); + return getDefaultPort(); + } + + private int getDefaultPort() { + return portArg.getDefaultIntValue(defaultPort); } /** diff --git a/opendj-cli/src/main/java/com/forgerock/opendj/cli/IntegerArgument.java b/opendj-cli/src/main/java/com/forgerock/opendj/cli/IntegerArgument.java index a17cb12581..0bb59d937f 100644 --- a/opendj-cli/src/main/java/com/forgerock/opendj/cli/IntegerArgument.java +++ b/opendj-cli/src/main/java/com/forgerock/opendj/cli/IntegerArgument.java @@ -13,6 +13,7 @@ * * Copyright 2006-2010 Sun Microsystems, Inc. * Portions copyright 2014-2016 ForgeRock AS. + * Portions Copyright 2026 3A Systems, LLC. */ package com.forgerock.opendj.cli; @@ -104,6 +105,25 @@ private IntegerArgument(final Builder builder, final int lowerBound, final int u } } + /** + * Returns the default value of this argument as an int. + *
+ * The default value of an integer argument is always built from an {@code int}, so the only
+ * reason for this method to return the fallback value is that this argument has no default
+ * value at all.
+ *
+ * @param fallbackValue
+ * The value to return if this argument does not have a default value.
+ * @return The default value of this argument, or {@code fallbackValue} if it does not have one.
+ */
+ public int getDefaultIntValue(final int fallbackValue) {
+ try {
+ return Integer.parseInt(getDefaultValue());
+ } catch (final NumberFormatException e) {
+ return fallbackValue;
+ }
+ }
+
/**
* Indicates whether the provided value is acceptable for use in this
* argument.
diff --git a/opendj-cli/src/main/java/com/forgerock/opendj/cli/Utils.java b/opendj-cli/src/main/java/com/forgerock/opendj/cli/Utils.java
index b9dc254bc7..d69a0142d1 100644
--- a/opendj-cli/src/main/java/com/forgerock/opendj/cli/Utils.java
+++ b/opendj-cli/src/main/java/com/forgerock/opendj/cli/Utils.java
@@ -384,13 +384,29 @@ public static String wrapText(final String text, int width, final int indent) {
*/
public static void checkJavaVersion() throws ClientException {
final String version = System.getProperty("java.specification.version");
- if (Float.valueOf(version) < CliConstants.MINIMUM_JAVA_VERSION) {
+ if (getJavaSpecificationVersion(version) < CliConstants.MINIMUM_JAVA_VERSION) {
final String javaBin = System.getProperty("java.home") + File.separator + "bin" + File.separator + "java";
throw new ClientException(ReturnCode.JAVA_VERSION_INCOMPATIBLE,
ERR_INCOMPATIBLE_JAVA_VERSION.get(CliConstants.MINIMUM_JAVA_VERSION, version, javaBin), null);
}
}
+ /**
+ * Returns the provided java specification version as a number, or zero if it does not hold one,
+ * in which case the java version is reported as incompatible rather than failing the check with
+ * a runtime exception.
+ */
+ private static float getJavaSpecificationVersion(final String version) {
+ if (version == null) {
+ return 0;
+ }
+ try {
+ return Float.parseFloat(version);
+ } catch (final NumberFormatException e) {
+ return 0;
+ }
+ }
+
/**
* Returns the default host name.
*
diff --git a/opendj-ldap-toolkit/src/main/java/com/forgerock/opendj/ldap/tools/PerformanceRunner.java b/opendj-ldap-toolkit/src/main/java/com/forgerock/opendj/ldap/tools/PerformanceRunner.java
index bd119ef224..fde226f994 100644
--- a/opendj-ldap-toolkit/src/main/java/com/forgerock/opendj/ldap/tools/PerformanceRunner.java
+++ b/opendj-ldap-toolkit/src/main/java/com/forgerock/opendj/ldap/tools/PerformanceRunner.java
@@ -13,6 +13,7 @@
*
* Copyright 2010 Sun Microsystems, Inc.
* Portions Copyright 2011-2016 ForgeRock AS.
+ * Portions Copyright 2026 3A Systems, LLC.
*/
package com.forgerock.opendj.ldap.tools;
@@ -481,13 +482,18 @@ protected void joinAllWorkerThreads() throws InterruptedException {
double[] getPercentiles() {
if (percentilesArgument.isPresent()) {
- double[] percentiles = new double[percentilesArgument.getValues().size()];
- int index = 0;
- for (final String percentile : percentilesArgument.getValues()) {
- percentiles[index++] = Double.parseDouble(percentile);
+ try {
+ final double[] percentiles = new double[percentilesArgument.getValues().size()];
+ int index = 0;
+ for (final String percentile : percentilesArgument.getValues()) {
+ percentiles[index++] = Double.parseDouble(percentile);
+ }
+ Arrays.sort(percentiles);
+ return percentiles;
+ } catch (final NumberFormatException e) {
+ // The argument parser only accepts integers in the [0, 100] range, so this cannot
+ // happen. Fall back to the default percentiles rather than failing the run.
}
- Arrays.sort(percentiles);
- return percentiles;
}
return DEFAULT_PERCENTILES;
diff --git a/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/IndexPanel.java b/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/IndexPanel.java
index 444fb53cc8..29cff75a2c 100644
--- a/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/IndexPanel.java
+++ b/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/IndexPanel.java
@@ -60,6 +60,7 @@
import org.opends.guitools.controlpanel.task.DeleteIndexTask;
import org.opends.guitools.controlpanel.task.Task;
import org.opends.guitools.controlpanel.util.Utilities;
+import org.opends.quicksetup.util.Utils;
/**
* The panel that displays an existing index (it appears on the right of the
@@ -492,7 +493,7 @@ private ModifyIndexTask(ControlPanelInfo info, ProgressDialog dlg)
backendSet = new HashSet<>();
backendSet.add(backendName);
attributeName = index.getName();
- entryLimitValue = Integer.parseInt(entryLimit.getText());
+ entryLimitValue = Utils.parseIntOrDefault(entryLimit.getText(), index.getEntryLimit());
indexTypes = getTypes();
indexToModify = index;
diff --git a/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/LocalOrRemotePanel.java b/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/LocalOrRemotePanel.java
index 52c586ca9e..cd84988d16 100644
--- a/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/LocalOrRemotePanel.java
+++ b/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/LocalOrRemotePanel.java
@@ -13,6 +13,7 @@
*
* Copyright 2009-2010 Sun Microsystems, Inc.
* Portions Copyright 2011-2016 ForgeRock AS.
+ * Portions Copyright 2026 3A Systems, LLC.
*/
package org.opends.guitools.controlpanel.ui;
@@ -575,7 +576,7 @@ public void run()
private HostPort getHostPort()
{
- return new HostPort(hostName.getText().trim(), Integer.valueOf(port.getText().trim()));
+ return new HostPort(hostName.getText().trim(), Utils.parseIntOrDefault(port.getText(), -1));
}
@Override
diff --git a/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/NewBaseDNPanel.java b/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/NewBaseDNPanel.java
index 176eaf553d..56786a5725 100644
--- a/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/NewBaseDNPanel.java
+++ b/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/NewBaseDNPanel.java
@@ -735,7 +735,7 @@ else if (leaveDatabaseEmpty.isSelected())
}
else if (importAutomaticallyGenerated.isSelected())
{
- int nEntries = Integer.parseInt(numberOfEntries.getText().trim());
+ int nEntries = Utils.parseIntOrDefault(numberOfEntries.getText(), 0);
if (nEntries < 500)
{
return 30;
@@ -1164,7 +1164,8 @@ public void run()
}
});
- final File templateFile = SetupUtils.createTemplateFile(newBaseDN, Integer.parseInt(nEntries));
+ final File templateFile =
+ SetupUtils.createTemplateFile(newBaseDN, Utils.parseIntOrDefault(nEntries, 0));
if (!isLocal())
{
try
diff --git a/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/NewIndexPanel.java b/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/NewIndexPanel.java
index a7f3be9595..97cedc18b0 100644
--- a/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/NewIndexPanel.java
+++ b/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/NewIndexPanel.java
@@ -53,6 +53,7 @@
import org.opends.guitools.controlpanel.event.ConfigurationChangeEvent;
import org.opends.guitools.controlpanel.task.Task;
import org.opends.guitools.controlpanel.util.Utilities;
+import org.opends.quicksetup.util.Utils;
import org.forgerock.opendj.ldap.schema.Schema;
/** Panel that appears when the user defines a new index. */
@@ -339,7 +340,7 @@ public NewIndexTask(final ControlPanelInfo info, final ProgressDialog dlg)
super(info, dlg);
backendSet.add(backendName.getText());
attributeName = getAttributeName();
- entryLimitValue = Integer.parseInt(entryLimit.getText());
+ entryLimitValue = Utils.parseIntOrDefault(entryLimit.getText(), DEFAULT_ENTRY_LIMIT);
indexTypes = getTypes();
}
diff --git a/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/TaskToSchedulePanel.java b/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/TaskToSchedulePanel.java
index ab9b7b2255..2d4b00dc04 100644
--- a/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/TaskToSchedulePanel.java
+++ b/opendj-server-legacy/src/main/java/org/opends/guitools/controlpanel/ui/TaskToSchedulePanel.java
@@ -13,6 +13,7 @@
*
* Copyright 2009-2010 Sun Microsystems, Inc.
* Portions Copyright 2014-2016 ForgeRock AS.
+ * Portions Copyright 2026 3A Systems, LLC.
*/
package org.opends.guitools.controlpanel.ui;
@@ -49,6 +50,7 @@
import org.opends.guitools.controlpanel.ui.components.TimeDocumentFilter;
import org.opends.guitools.controlpanel.ui.renderer.NoLeftInsetCategoryComboBoxRenderer;
import org.opends.guitools.controlpanel.util.Utilities;
+import org.opends.quicksetup.util.Utils;
import org.opends.server.backends.task.RecurringTask;
/** The panel that allows the user to specify when a task will be launched. */
@@ -351,7 +353,7 @@ private void updateLaunchLaterErrorMessages(Collection
+ * The panels validate their fields before using their values, so the default value is only
+ * returned when a field has not been validated beforehand.
+ *
+ * @param value
+ * the value to be parsed, which may be {@code null}
+ * @param defaultValue
+ * the value to return when {@code value} does not hold a number
+ * @return the number held by the provided value
+ */
+ public static int parseIntOrDefault(String value, int defaultValue)
+ {
+ if (value == null)
+ {
+ return defaultValue;
+ }
+ try
+ {
+ return Integer.parseInt(value.trim());
+ }
+ catch (NumberFormatException e)
+ {
+ return defaultValue;
+ }
+ }
}
/**
diff --git a/opendj-server-legacy/src/main/java/org/opends/server/tools/InstallDS.java b/opendj-server-legacy/src/main/java/org/opends/server/tools/InstallDS.java
index 2594512906..23619e66e2 100644
--- a/opendj-server-legacy/src/main/java/org/opends/server/tools/InstallDS.java
+++ b/opendj-server-legacy/src/main/java/org/opends/server/tools/InstallDS.java
@@ -14,6 +14,7 @@
* Copyright 2006-2010 Sun Microsystems, Inc.
* Portions Copyright 2011 profiq s.r.o.
* Portions Copyright 2011-2016 ForgeRock AS.
+ * Portions Copyright 2026 3A Systems, LLC.
*/
package org.opends.server.tools;
@@ -291,10 +292,10 @@ private int execute(String[] args)
}
lastResetDirectoryManagerDN = DN.valueOf(argParser.directoryManagerDNArg.getDefaultValue());
- lastResetLdapPort = Integer.parseInt(argParser.ldapPortArg.getDefaultValue());
- lastResetLdapsPort = Integer.parseInt(argParser.ldapsPortArg.getDefaultValue());
- lastResetAdminConnectorPort = Integer.parseInt(argParser.adminConnectorPortArg.getDefaultValue());
- lastResetJmxPort = Integer.parseInt(argParser.jmxPortArg.getDefaultValue());
+ lastResetLdapPort = argParser.ldapPortArg.getDefaultIntValue(-1);
+ lastResetLdapsPort = argParser.ldapsPortArg.getDefaultIntValue(-1);
+ lastResetAdminConnectorPort = argParser.adminConnectorPortArg.getDefaultIntValue(-1);
+ lastResetJmxPort = argParser.jmxPortArg.getDefaultIntValue(-1);
// Validate user provided data
try
@@ -758,8 +759,15 @@ else if (argParser.addBaseEntryArg.isPresent())
}
else if (argParser.sampleDataArg.isPresent())
{
- dataOptions = NewSuffixOptions.createAutomaticallyGenerated(baseDNs,
- Integer.valueOf(argParser.sampleDataArg.getValue()));
+ try
+ {
+ dataOptions = NewSuffixOptions.createAutomaticallyGenerated(baseDNs, argParser.sampleDataArg.getIntValue());
+ }
+ catch (final ArgumentException ae)
+ {
+ errorMessages.add(ae.getMessageObject());
+ dataOptions = NewSuffixOptions.createEmpty(baseDNs);
+ }
}
else
{
diff --git a/opendj-server-legacy/src/main/java/org/opends/server/tools/WaitForFileDelete.java b/opendj-server-legacy/src/main/java/org/opends/server/tools/WaitForFileDelete.java
index ced85e0b5a..0fe9db375a 100644
--- a/opendj-server-legacy/src/main/java/org/opends/server/tools/WaitForFileDelete.java
+++ b/opendj-server-legacy/src/main/java/org/opends/server/tools/WaitForFileDelete.java
@@ -13,6 +13,7 @@
*
* Copyright 2006-2009 Sun Microsystems, Inc.
* Portions Copyright 2013-2016 ForgeRock AS.
+ * Portions Copyright 2026 3A Systems, LLC.
*/
package org.opends.server.tools;
@@ -287,9 +288,11 @@ private int mainWait(String[] args)
}
// Figure out when to stop waiting.
long stopWaitingTime;
+ int timeoutSeconds;
try
{
- long timeoutMillis = 1000L * Integer.parseInt(timeout.getValue());
+ timeoutSeconds = Integer.parseInt(timeout.getValue());
+ long timeoutMillis = 1000L * timeoutSeconds;
if (timeoutMillis > 0)
{
stopWaitingTime = System.currentTimeMillis() + timeoutMillis;
@@ -302,6 +305,7 @@ private int mainWait(String[] args)
catch (Exception e)
{
// This shouldn't happen, but if it does then ignore it.
+ timeoutSeconds = 60;
stopWaitingTime = System.currentTimeMillis() + 60000;
}
@@ -357,9 +361,7 @@ else if (!quietMode.isPresent())
if (targetFile.exists())
{
- println(ERR_TIMEOUT_DURING_STARTUP.get(
- Integer.parseInt(timeout.getValue()),
- timeout.getLongIdentifier()));
+ println(ERR_TIMEOUT_DURING_STARTUP.get(timeoutSeconds, timeout.getLongIdentifier()));
return EXIT_CODE_TIMEOUT;
}
else
diff --git a/opendj-server-legacy/src/main/java/org/opends/server/tools/dsreplication/ReplicationCliArgumentParser.java b/opendj-server-legacy/src/main/java/org/opends/server/tools/dsreplication/ReplicationCliArgumentParser.java
index e796c5427c..b488bf1954 100644
--- a/opendj-server-legacy/src/main/java/org/opends/server/tools/dsreplication/ReplicationCliArgumentParser.java
+++ b/opendj-server-legacy/src/main/java/org/opends/server/tools/dsreplication/ReplicationCliArgumentParser.java
@@ -13,6 +13,7 @@
*
* Copyright 2007-2010 Sun Microsystems, Inc.
* Portions Copyright 2012-2016 ForgeRock AS.
+ * Portions Copyright 2026 3A Systems, LLC.
*/
package org.opends.server.tools.dsreplication;
@@ -1266,8 +1267,7 @@ static int getValue(IntegerArgument arg)
*/
static int getDefaultValue(IntegerArgument arg)
{
- String v = arg.getDefaultValue();
- return v != null ? Integer.parseInt(v) : -1;
+ return arg.getDefaultIntValue(-1);
}
/**
diff --git a/opendj-server-legacy/src/main/java/org/opends/server/tools/tasks/TaskTool.java b/opendj-server-legacy/src/main/java/org/opends/server/tools/tasks/TaskTool.java
index cefc15041d..55dee9e1b8 100644
--- a/opendj-server-legacy/src/main/java/org/opends/server/tools/tasks/TaskTool.java
+++ b/opendj-server-legacy/src/main/java/org/opends/server/tools/tasks/TaskTool.java
@@ -13,6 +13,7 @@
*
* Copyright 2007-2010 Sun Microsystems, Inc.
* Portions Copyright 2012-2016 ForgeRock AS.
+ * Portions Copyright 2026 3A Systems, LLC.
*/
package org.opends.server.tools.tasks;
@@ -320,8 +321,7 @@ protected int process(LDAPConnectionArgumentParser argParser,
}
return 0;
} catch (LDAPConnectionException e) {
- if (isWrongPortException(e,
- Integer.valueOf(argParser.getArguments().getPort())))
+ if (isWrongPortException(e, getPortNumber()))
{
printWrappedText(err, ERR_TASK_LDAP_FAILED_TO_CONNECT_WRONG_PORT.get(
argParser.getArguments().getHostName(), argParser.getArguments().getPort()));
@@ -361,6 +361,23 @@ protected int process(LDAPConnectionArgumentParser argParser,
}
}
+ /**
+ * Returns the port this tool tried to connect to, or {@code -1} if the port argument does not
+ * hold a number, in which case the connection failure cannot be a wrong port one.
+ * @return the port this tool tried to connect to.
+ */
+ private int getPortNumber()
+ {
+ try
+ {
+ return Integer.parseInt(argParser.getArguments().getPort());
+ }
+ catch (NumberFormatException e)
+ {
+ return -1;
+ }
+ }
+
/**
* Returns {@code true} if the provided exception was caused by trying to
* connect to the wrong port and {@code false} otherwise.
diff --git a/opendj-server-legacy/src/snmp/src/org/opends/server/snmp/DsApplIfOpsEntryImpl.java b/opendj-server-legacy/src/snmp/src/org/opends/server/snmp/DsApplIfOpsEntryImpl.java
index 683e884660..fc27c0a2af 100644
--- a/opendj-server-legacy/src/snmp/src/org/opends/server/snmp/DsApplIfOpsEntryImpl.java
+++ b/opendj-server-legacy/src/snmp/src/org/opends/server/snmp/DsApplIfOpsEntryImpl.java
@@ -13,6 +13,7 @@
*
* Copyright 2008 Sun Microsystems, Inc.
* Portions Copyright 2012-2014 ForgeRock AS.
+ * Portions Copyright 2026 3A Systems, LLC.
*/
package org.opends.server.snmp;
@@ -86,8 +87,14 @@ public DsApplIfOpsEntryImpl(SnmpMib mib, MBeanServer server,
* @return an OID representing the connection handler:port
*/
public String getDsApplIfProtocol() {
- String portNumber = (String)this.monitor.getAttribute
- (this.connectionHandlerName, "ds-connectionhandler-listener");
+ Object listener = this.monitor.getAttribute(
+ this.connectionHandlerName, "ds-connectionhandler-listener");
+ if (listener instanceof Object[]) {
+ // A connection handler with several listen addresses reports them as an array.
+ Object[] listeners = (Object[]) listener;
+ listener = listeners.length > 0 ? listeners[0] : null;
+ }
+ String portNumber = listener != null ? String.valueOf(listener) : null;
if (portNumber==null) {
return this.DsApplIfProtocol;
}
@@ -101,41 +108,47 @@ public String getDsApplIfProtocol() {
}
/**
- * {@inheritDoc}
- * @return DsApplIfSearchOps
+ * Returns the value of the provided connection handler statistic as a
+ * counter, or zero if the statistic is not available or does not hold a
+ * number.
+ *
+ * @param statisticName the name of the connection handler statistic
+ * @return the counter value of the statistic
*/
- @Override
- public Long getDsApplIfSearchOps() {
+ private Long getCounter32Statistic(String statisticName) {
if (stats == null) {
stats = this.monitor.getConnectionHandlerStatistics(
connectionHandlerName);
}
- if (stats != null) {
- long value = Long.parseLong((String) this.monitor.getAttribute(stats,
- "searchRequests"));
+ if (stats == null) {
+ return 0L;
+ }
+ try {
+ long value = Long.parseLong(
+ String.valueOf(this.monitor.getAttribute(stats, statisticName)));
return SNMPMonitor.counter32Value(value);
- } else {
+ } catch (NumberFormatException e) {
+ // The statistic is not available or is not a number.
return 0L;
}
}
+ /**
+ * {@inheritDoc}
+ * @return DsApplIfSearchOps
+ */
+ @Override
+ public Long getDsApplIfSearchOps() {
+ return getCounter32Statistic("searchRequests");
+ }
+
/**
* {@inheritDoc}
* @return DsApplIfOneLevelSearchOps
*/
@Override
public Long getDsApplIfOneLevelSearchOps() {
- if (stats == null) {
- stats = this.monitor.getConnectionHandlerStatistics(
- connectionHandlerName);
- }
- if (stats != null) {
- long value = Long.parseLong((String) this.monitor.getAttribute(stats,
- "searchOneRequests"));
- return SNMPMonitor.counter32Value(value);
- } else {
- return 0L;
- }
+ return getCounter32Statistic("searchOneRequests");
}
/**
@@ -144,17 +157,7 @@ public Long getDsApplIfOneLevelSearchOps() {
*/
@Override
public Long getDsApplIfWholeSubtreeSearchOps() {
- if (stats == null) {
- stats = this.monitor.getConnectionHandlerStatistics(
- connectionHandlerName);
- }
- if (stats != null) {
- long value = Long.parseLong((String) this.monitor.getAttribute(stats,
- "searchSubRequests"));
- return SNMPMonitor.counter32Value(value);
- } else {
- return 0L;
- }
+ return getCounter32Statistic("searchSubRequests");
}
/**
@@ -163,17 +166,7 @@ public Long getDsApplIfWholeSubtreeSearchOps() {
*/
@Override
public Long getDsApplIfModifyRDNOps() {
- if (stats == null) {
- stats = this.monitor.getConnectionHandlerStatistics(
- connectionHandlerName);
- }
- if (stats != null) {
- long value = Long.parseLong((String) this.monitor.getAttribute(
- stats, "modifyDNRequests"));
- return SNMPMonitor.counter32Value(value);
- } else {
- return 0L;
- }
+ return getCounter32Statistic("modifyDNRequests");
}
/**
@@ -182,17 +175,7 @@ public Long getDsApplIfModifyRDNOps() {
*/
@Override
public Long getDsApplIfModifyEntryOps() {
- if (stats == null) {
- stats = this.monitor.getConnectionHandlerStatistics(
- connectionHandlerName);
- }
- if (stats != null) {
- long value = Long.parseLong((String) this.monitor.getAttribute(
- stats, "modifyRequests"));
- return SNMPMonitor.counter32Value(value);
- } else {
- return 0L;
- }
+ return getCounter32Statistic("modifyRequests");
}
/**
@@ -201,17 +184,7 @@ public Long getDsApplIfModifyEntryOps() {
*/
@Override
public Long getDsApplIfRemoveEntryOps() {
- if (stats == null) {
- stats = this.monitor.getConnectionHandlerStatistics(
- connectionHandlerName);
- }
- if (stats != null) {
- long value = Long.parseLong((String) this.monitor.getAttribute(
- stats, "deleteRequests"));
- return SNMPMonitor.counter32Value(value);
- } else {
- return 0L;
- }
+ return getCounter32Statistic("deleteRequests");
}
/**
@@ -220,17 +193,7 @@ public Long getDsApplIfRemoveEntryOps() {
*/
@Override
public Long getDsApplIfAddEntryOps() {
- if (stats == null) {
- stats = this.monitor.getConnectionHandlerStatistics(
- connectionHandlerName);
- }
- if (stats != null) {
- long value = Long.parseLong((String) this.monitor.getAttribute(
- stats, "addRequests"));
- return SNMPMonitor.counter32Value(value);
- } else {
- return 0L;
- }
+ return getCounter32Statistic("addRequests");
}
/**
@@ -239,17 +202,7 @@ public Long getDsApplIfAddEntryOps() {
*/
@Override
public Long getDsApplIfCompareOps() {
- if (stats == null) {
- stats = this.monitor.getConnectionHandlerStatistics(
- connectionHandlerName);
- }
- if (stats != null) {
- long value = Long.parseLong((String) this.monitor.getAttribute(
- stats, "compareRequests"));
- return SNMPMonitor.counter32Value(value);
- } else {
- return 0L;
- }
+ return getCounter32Statistic("compareRequests");
}
/**
@@ -272,17 +225,7 @@ public Long getDsApplIfReadOps() {
*/
@Override
public Long getDsApplIfOutBytes() {
- if (stats == null) {
- stats = this.monitor.getConnectionHandlerStatistics(
- connectionHandlerName);
- }
- if (stats != null) {
- long value = Long.parseLong((String) this.monitor.getAttribute(
- stats, "bytesWritten"));
- return SNMPMonitor.counter32Value(value);
- } else {
- return 0L;
- }
+ return getCounter32Statistic("bytesWritten");
}
/**
@@ -291,17 +234,7 @@ public Long getDsApplIfOutBytes() {
*/
@Override
public Long getDsApplIfInBytes() {
- if (stats == null) {
- stats = this.monitor.getConnectionHandlerStatistics(
- connectionHandlerName);
- }
- if (stats != null) {
- long value = Long.parseLong((String) this.monitor.getAttribute(
- stats, "bytesRead"));
- return SNMPMonitor.counter32Value(value);
- } else {
- return 0L;
- }
+ return getCounter32Statistic("bytesRead");
}
/**
> getDsConfigReplicationEnableEquivalentCommandLi
cmdLines.add(cmdReplicationServer);
return cmdLines;
}
+
+ /**
+ * Returns the number held by the provided field value, or the provided default value if it does
+ * not hold a number.
+ *