Package com.unboundid.ldap.sdk.examples
Class SearchRate
- java.lang.Object
-
- com.unboundid.util.CommandLineTool
-
- com.unboundid.util.LDAPCommandLineTool
-
- com.unboundid.ldap.sdk.examples.SearchRate
-
- All Implemented Interfaces:
java.io.Serializable
@ThreadSafety(level=NOT_THREADSAFE) public final class SearchRate extends LDAPCommandLineTool implements java.io.Serializable
This class provides a tool that can be used to search an LDAP directory server repeatedly using multiple threads. It can help provide an estimate of the search performance that a directory server is able to achieve. Either or both of the base DN and the search filter may be a value pattern as described in theValuePattern
class. This makes it possible to search over a range of entries rather than repeatedly performing searches with the same base DN and filter.
Some of the APIs demonstrated by this example include:- Argument Parsing (from the
com.unboundid.util.args
package) - LDAP Command-Line Tool (from the
com.unboundid.util
package) - LDAP Communication (from the
com.unboundid.ldap.sdk
package) - Value Patterns (from the
com.unboundid.util
package)
All of the necessary information is provided using command line arguments. Supported arguments include those allowed by theLDAPCommandLineTool
class, as well as the following additional arguments:- "-b {baseDN}" or "--baseDN {baseDN}" -- specifies the base DN to use for the searches. This must be provided. It may be a simple DN, or it may be a value pattern to express a range of base DNs.
- "-s {scope}" or "--scope {scope}" -- specifies the scope to use for the search. The scope value should be one of "base", "one", "sub", or "subord". If this isn't specified, then a scope of "sub" will be used.
- "-z {num}" or "--sizeLimit {num}" -- specifies the maximum number of entries that should be returned in response to each search request.
- "-l {num}" or "--timeLimitSeconds {num}" -- specifies the maximum length of time, in seconds, that the server should spend processing each search request.
- "--dereferencePolicy {value}" -- specifies the alias dereferencing policy that should be used for each search request. Allowed values are "never", "always", "search", and "find".
- "--typesOnly" -- indicates that search requests should have the typesOnly flag set to true, indicating that matching entries should only include attributes with an attribute description but no values.
- "-f {filter}" or "--filter {filter}" -- specifies the filter to use for the searches. This must be provided. It may be a simple filter, or it may be a value pattern to express a range of filters.
- "-A {name}" or "--attribute {name}" -- specifies the name of an attribute that should be included in entries returned from the server. If this is not provided, then all user attributes will be requested. This may include special tokens that the server may interpret, like "1.1" to indicate that no attributes should be returned, "*", for all user attributes, or "+" for all operational attributes. Multiple attributes may be requested with multiple instances of this argument.
- "--ldapURL {url}" -- Specifies an LDAP URL that represents the base DN, scope, filter, and set of requested attributes that should be used for the search requests. It may be a simple LDAP URL, or it may be a value pattern to express a range of LDAP URLs. If this argument is provided, then none of the --baseDN, --scope, --filter, or --attribute arguments may be used.
- "-t {num}" or "--numThreads {num}" -- specifies the number of concurrent threads to use when performing the searches. If this is not provided, then a default of one thread will be used.
- "-i {sec}" or "--intervalDuration {sec}" -- specifies the length of time in seconds between lines out output. If this is not provided, then a default interval duration of five seconds will be used.
- "-I {num}" or "--numIntervals {num}" -- specifies the maximum number of intervals for which to run. If this is not provided, then it will run forever.
- "--iterationsBeforeReconnect {num}" -- specifies the number of search iterations that should be performed on a connection before that connection is closed and replaced with a newly-established (and authenticated, if appropriate) connection.
- "-r {searches-per-second}" or "--ratePerSecond {searches-per-second}" -- specifies the target number of searches to perform per second. It is still necessary to specify a sufficient number of threads for achieving this rate. If this option is not provided, then the tool will run at the maximum rate for the specified number of threads.
- "--variableRateData {path}" -- specifies the path to a file containing information needed to allow the tool to vary the target rate over time. If this option is not provided, then the tool will either use a fixed target rate as specified by the "--ratePerSecond" argument, or it will run at the maximum rate.
- "--generateSampleRateFile {path}" -- specifies the path to a file to which sample data will be written illustrating and describing the format of the file expected to be used in conjunction with the "--variableRateData" argument.
- "--warmUpIntervals {num}" -- specifies the number of intervals to complete before beginning overall statistics collection.
- "--timestampFormat {format}" -- specifies the format to use for timestamps included before each output line. The format may be one of "none" (for no timestamps), "with-date" (to include both the date and the time), or "without-date" (to include only time time).
- "-Y {authzID}" or "--proxyAs {authzID}" -- Use the proxied authorization v2 control to request that the operation be processed using an alternate authorization identity. In this case, the bind DN should be that of a user that has permission to use this control. The authorization identity may be a value pattern.
- "-a" or "--asynchronous" -- Indicates that searches should be performed in asynchronous mode, in which the client will not wait for a response to a previous request before sending the next request. Either the "--ratePerSecond" or "--maxOutstandingRequests" arguments must be provided to limit the number of outstanding requests.
- "-O {num}" or "--maxOutstandingRequests {num}" -- Specifies the maximum number of outstanding requests that will be allowed in asynchronous mode.
- "--suppressErrorResultCodes" -- Indicates that information about the result codes for failed operations should not be displayed.
- "-c" or "--csv" -- Generate output in CSV format rather than a display-friendly format.
- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description SearchRate(java.io.OutputStream outStream, java.io.OutputStream errStream)
Creates a new instance of this tool.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addNonLDAPArguments(ArgumentParser parser)
Adds the arguments used by this program that aren't already provided by the genericLDAPCommandLineTool
framework.boolean
defaultsToInteractiveMode()
Indicates whether this tool defaults to launching in interactive mode if the tool is invoked without any command-line arguments.protected boolean
defaultToPromptForBindPassword()
Indicates whether this tool should default to interactively prompting for the bind password if a password is required but no argument was provided to indicate how to get the password.ResultCode
doToolProcessing()
Performs the actual processing for this tool.LDAPConnectionOptions
getConnectionOptions()
Retrieves the connection options that should be used for connections created for use with this tool.java.util.LinkedHashMap<java.lang.String[],java.lang.String>
getExampleUsages()
Retrieves a set of information that may be used to generate example usage information.java.lang.String
getToolDescription()
Retrieves the description for this tool.java.lang.String
getToolName()
Retrieves the name for this tool.java.lang.String
getToolVersion()
Retrieves the version string for this tool.protected boolean
includeAlternateLongIdentifiers()
Indicates whether the LDAP-specific arguments should include alternate versions of all long identifiers that consist of multiple words so that they are available in both camelCase and dash-separated versions.static void
main(java.lang.String[] args)
Parse the provided command line arguments and make the appropriate set of changes.static ResultCode
main(java.lang.String[] args, java.io.OutputStream outStream, java.io.OutputStream errStream)
Parse the provided command line arguments and make the appropriate set of changes.void
stopRunning()
Requests that this tool stop running.protected boolean
supportsDebugLogging()
Indicates whether this tool supports the ability to generate a debug log file.boolean
supportsInteractiveMode()
Indicates whether this tool should provide support for an interactive mode, in which the tool offers a mode in which the arguments can be provided in a text-driven menu rather than requiring them to be given on the command line.protected boolean
supportsMultipleServers()
Indicates whether this tool supports creating connections to multiple servers.protected boolean
supportsOutputFile()
Indicates whether this tool should provide arguments for redirecting output to a file.boolean
supportsPropertiesFile()
Indicates whether this tool supports the use of a properties file for specifying default values for arguments that aren't specified on the command line.-
Methods inherited from class com.unboundid.util.LDAPCommandLineTool
addToolArguments, anyLDAPArgumentsProvided, createBindRequest, createServerSet, createSSLUtil, createSSLUtil, doExtendedArgumentValidation, doExtendedNonLDAPArgumentValidation, getBindControls, getConnection, getConnectionOptionsWithRequestedSettings, getConnectionPool, getConnectionPool, getSuppressedShortIdentifiers, getUnauthenticatedConnection, supportsAuthentication, supportsSASLHelp, supportsSSLDebugging
-
Methods inherited from class com.unboundid.util.CommandLineTool
addEnableSSLDebuggingArgument, createArgumentParser, doShutdownHookProcessing, err, getAdditionalDescriptionParagraphs, getErr, getMaxTrailingArguments, getMinTrailingArguments, getOriginalErr, getOriginalOut, getOut, getPasswordFileReader, getToolCompletionMessage, getTrailingArgumentsPlaceholder, logToolInvocationByDefault, out, registerShutdownHook, requestToolArgumentsInteractively, runTool, wrapErr, wrapOut
-
-
-
-
Constructor Detail
-
SearchRate
public SearchRate(@Nullable java.io.OutputStream outStream, @Nullable java.io.OutputStream errStream)
Creates a new instance of this tool.- Parameters:
outStream
- The output stream to which standard out should be written. It may benull
if output should be suppressed.errStream
- The output stream to which standard error should be written. It may benull
if error messages should be suppressed.
-
-
Method Detail
-
main
public static void main(@NotNull java.lang.String[] args)
Parse the provided command line arguments and make the appropriate set of changes.- Parameters:
args
- The command line arguments provided to this program.
-
main
@NotNull public static ResultCode main(@NotNull java.lang.String[] args, @Nullable java.io.OutputStream outStream, @Nullable java.io.OutputStream errStream)
Parse the provided command line arguments and make the appropriate set of changes.- Parameters:
args
- The command line arguments provided to this program.outStream
- The output stream to which standard out should be written. It may benull
if output should be suppressed.errStream
- The output stream to which standard error should be written. It may benull
if error messages should be suppressed.- Returns:
- A result code indicating whether the processing was successful.
-
getToolName
@NotNull public java.lang.String getToolName()
Retrieves the name for this tool.- Specified by:
getToolName
in classCommandLineTool
- Returns:
- The name for this tool.
-
getToolDescription
@NotNull public java.lang.String getToolDescription()
Retrieves the description for this tool.- Specified by:
getToolDescription
in classCommandLineTool
- Returns:
- The description for this tool.
-
getToolVersion
@NotNull public java.lang.String getToolVersion()
Retrieves the version string for this tool.- Overrides:
getToolVersion
in classCommandLineTool
- Returns:
- The version string for this tool.
-
supportsInteractiveMode
public boolean supportsInteractiveMode()
Indicates whether this tool should provide support for an interactive mode, in which the tool offers a mode in which the arguments can be provided in a text-driven menu rather than requiring them to be given on the command line. If interactive mode is supported, it may be invoked using the "--interactive" argument. Alternately, if interactive mode is supported anddefaultsToInteractiveMode()
returnstrue
, then interactive mode may be invoked by simply launching the tool without any arguments.- Overrides:
supportsInteractiveMode
in classCommandLineTool
- Returns:
true
if this tool supports interactive mode, orfalse
if not.
-
defaultsToInteractiveMode
public boolean defaultsToInteractiveMode()
Indicates whether this tool defaults to launching in interactive mode if the tool is invoked without any command-line arguments. This will only be used ifsupportsInteractiveMode()
returnstrue
.- Overrides:
defaultsToInteractiveMode
in classCommandLineTool
- Returns:
true
if this tool defaults to using interactive mode if launched without any command-line arguments, orfalse
if not.
-
supportsOutputFile
protected boolean supportsOutputFile()
Indicates whether this tool should provide arguments for redirecting output to a file. If this method returnstrue
, then the tool will offer an "--outputFile" argument that will specify the path to a file to which all standard output and standard error content will be written, and it will also offer a "--teeToStandardOut" argument that can only be used if the "--outputFile" argument is present and will cause all output to be written to both the specified output file and to standard output.- Overrides:
supportsOutputFile
in classCommandLineTool
- Returns:
true
if this tool should provide arguments for redirecting output to a file, orfalse
if not.
-
defaultToPromptForBindPassword
protected boolean defaultToPromptForBindPassword()
Indicates whether this tool should default to interactively prompting for the bind password if a password is required but no argument was provided to indicate how to get the password.- Overrides:
defaultToPromptForBindPassword
in classLDAPCommandLineTool
- Returns:
true
if this tool should default to interactively prompting for the bind password, orfalse
if not.
-
supportsPropertiesFile
public boolean supportsPropertiesFile()
Indicates whether this tool supports the use of a properties file for specifying default values for arguments that aren't specified on the command line.- Overrides:
supportsPropertiesFile
in classCommandLineTool
- Returns:
true
if this tool supports the use of a properties file for specifying default values for arguments that aren't specified on the command line, orfalse
if not.
-
supportsDebugLogging
protected boolean supportsDebugLogging()
Indicates whether this tool supports the ability to generate a debug log file. If this method returnstrue
, then the tool will expose additional arguments that can control debug logging.- Overrides:
supportsDebugLogging
in classCommandLineTool
- Returns:
true
if this tool supports the ability to generate a debug log file, orfalse
if not.
-
includeAlternateLongIdentifiers
protected boolean includeAlternateLongIdentifiers()
Indicates whether the LDAP-specific arguments should include alternate versions of all long identifiers that consist of multiple words so that they are available in both camelCase and dash-separated versions.- Overrides:
includeAlternateLongIdentifiers
in classLDAPCommandLineTool
- Returns:
true
if this tool should provide multiple versions of long identifiers for LDAP-specific arguments, orfalse
if not.
-
addNonLDAPArguments
public void addNonLDAPArguments(@NotNull ArgumentParser parser) throws ArgumentException
Adds the arguments used by this program that aren't already provided by the genericLDAPCommandLineTool
framework.- Specified by:
addNonLDAPArguments
in classLDAPCommandLineTool
- Parameters:
parser
- The argument parser to which the arguments should be added.- Throws:
ArgumentException
- If a problem occurs while adding the arguments.
-
supportsMultipleServers
protected boolean supportsMultipleServers()
Indicates whether this tool supports creating connections to multiple servers. If it is to support multiple servers, then the "--hostname" and "--port" arguments will be allowed to be provided multiple times, and will be required to be provided the same number of times. The same type of communication security and bind credentials will be used for all servers.- Overrides:
supportsMultipleServers
in classLDAPCommandLineTool
- Returns:
true
if this tool supports creating connections to multiple servers, orfalse
if not.
-
getConnectionOptions
@NotNull public LDAPConnectionOptions getConnectionOptions()
Retrieves the connection options that should be used for connections created for use with this tool.- Overrides:
getConnectionOptions
in classLDAPCommandLineTool
- Returns:
- The connection options that should be used for connections created for use with this tool.
-
doToolProcessing
@NotNull public ResultCode doToolProcessing()
Performs the actual processing for this tool. In this case, it gets a connection to the directory server and uses it to perform the requested searches.- Specified by:
doToolProcessing
in classCommandLineTool
- Returns:
- The result code for the processing that was performed.
-
stopRunning
public void stopRunning()
Requests that this tool stop running. This method will attempt to wait for all threads to complete before returning control to the caller.
-
getExampleUsages
@NotNull public java.util.LinkedHashMap<java.lang.String[],java.lang.String> getExampleUsages()
Retrieves a set of information that may be used to generate example usage information. Each element in the returned map should consist of a map between an example set of arguments and a string that describes the behavior of the tool when invoked with that set of arguments.- Overrides:
getExampleUsages
in classCommandLineTool
- Returns:
- A set of information that may be used to generate example usage
information. It may be
null
or empty if no example usage information is available.
-
-