Class SimplePagedResultsControl
- java.lang.Object
-
- org.forgerock.opendj.ldap.controls.SimplePagedResultsControl
-
- All Implemented Interfaces:
Control
public final class SimplePagedResultsControl extends Object implements Control
The simple paged results request and response control as defined in RFC 2696. This control allows a client to control the rate at which an LDAP server returns the results of an LDAP search operation. This control may be useful when the LDAP client has limited resources and may not be able to process the entire result set from a given LDAP query, or when the LDAP client is connected over a low-bandwidth connection.This control is included in the searchRequest and searchResultDone messages and has the following structure:
realSearchControlValue ::= SEQUENCE { size INTEGER (0..maxInt), -- requested page size from client -- result set size estimate from server cookie OCTET STRING }
The following example demonstrates use of simple paged results to handle three entries at a time.
ByteString cookie = ByteString.empty(); SearchRequest request; SearchResultHandler resultHandler = new MySearchResultHandler(); Result result; int page = 1; do { System.out.println("# Simple paged results: Page " + page); request = Requests.newSearchRequest( "dc=example,dc=com", SearchScope.WHOLE_SUBTREE, "(sn=Jensen)", "cn") .addControl(SimplePagedResultsControl.newControl(true, 3, cookie)); result = connection.search(request, resultHandler); try { SimplePagedResultsControl control = result.getControl( SimplePagedResultsControl.DECODER, new DecodeOptions()); cookie = control.getCookie(); } catch (final DecodeException e) { // Failed to decode the response control. } ++page; } while (!cookie.isEmpty());
The search result handler in this case displays pages of results as LDIF on standard out.private static class MySearchResultHandler implements SearchResultHandler { @Override public void handleExceptionResult(LdapException error) { // Ignore. } @Override public void handleResult(Result result) { // Ignore. } @Override public boolean handleEntry(SearchResultEntry entry) { final LDIFEntryWriter writer = new LDIFEntryWriter(System.out); try { writer.writeEntry(entry); writer.flush(); } catch (final IOException e) { // The writer could not write to System.out. } return true; } @Override public boolean handleReference(SearchResultReference reference) { System.out.println("Got a reference: " + reference.toString()); return false; } }
-
-
Field Summary
Fields Modifier and Type Field Description static ControlDecoder<SimplePagedResultsControl>
DECODER
A decoder which can be used for decoding the simple paged results control.static String
OID
The OID for the paged results request/response control defined in RFC 2696.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description ByteString
getCookie()
Returns the opaque cookie which is used by the server to track its position in the set of search results.String
getOid()
Returns the numeric OID associated with this control.int
getSize()
Returns the requested page size when used in a request control from the client, or an estimate of the result set size when used in a response control from the server (may be 0, indicating that the server does not know).ByteString
getValue()
Returns the value, if any, associated with this control.boolean
hasValue()
Returnstrue
if this control has a value.boolean
isCritical()
Returnstrue
if it is unacceptable to perform the operation without applying the semantics of this control.static SimplePagedResultsControl
newControl(boolean isCritical, int size, ByteString cookie)
Creates a new simple paged results control with the provided criticality, size, and cookie.String
toString()
-
-
-
Field Detail
-
OID
public static final String OID
The OID for the paged results request/response control defined in RFC 2696.- See Also:
- Constant Field Values
-
DECODER
public static final ControlDecoder<SimplePagedResultsControl> DECODER
A decoder which can be used for decoding the simple paged results control.
-
-
Method Detail
-
newControl
public static SimplePagedResultsControl newControl(boolean isCritical, int size, ByteString cookie)
Creates a new simple paged results control with the provided criticality, size, and cookie.- Parameters:
isCritical
-true
if it is unacceptable to perform the operation without applying the semantics of this control, orfalse
if it can be ignored.size
- The requested page size when used in a request control from the client, or an estimate of the result set size when used in a response control from the server (may be 0, indicating that the server does not know).cookie
- An opaque cookie which is used by the server to track its position in the set of search results. The cookie must be empty in the initial search request sent by the client. For subsequent search requests the client must include the cookie returned with the previous search result, until the server returns an empty cookie indicating that the final page of results has been returned.- Returns:
- The new control.
- Throws:
NullPointerException
- Ifcookie
wasnull
.
-
getCookie
public ByteString getCookie()
Returns the opaque cookie which is used by the server to track its position in the set of search results. The cookie must be empty in the initial search request sent by the client. For subsequent search requests the client must include the cookie returned with the previous search result, until the server returns an empty cookie indicating that the final page of results has been returned.- Returns:
- The opaque cookie which is used by the server to track its
position in the set of search results.
It is not
null
and will be empty for the final page of results.
-
getOid
public String getOid()
Description copied from interface:Control
Returns the numeric OID associated with this control.
-
getSize
public int getSize()
Returns the requested page size when used in a request control from the client, or an estimate of the result set size when used in a response control from the server (may be 0, indicating that the server does not know).- Returns:
- The requested page size when used in a request control from the client, or an estimate of the result set size when used in a response control from the server.
-
getValue
public ByteString getValue()
Description copied from interface:Control
Returns the value, if any, associated with this control. Its format is defined by the specification of this control.
-
hasValue
public boolean hasValue()
Description copied from interface:Control
Returnstrue
if this control has a value. In some circumstances it may be useful to determine if a control has a value, without actually calculating the value and incurring any performance costs.
-
isCritical
public boolean isCritical()
Description copied from interface:Control
Returnstrue
if it is unacceptable to perform the operation without applying the semantics of this control.The criticality field only has meaning in controls attached to request messages (except UnbindRequest). For controls attached to response messages and the UnbindRequest, the criticality field SHOULD be
false
, and MUST be ignored by the receiving protocol peer. A value oftrue
indicates that it is unacceptable to perform the operation without applying the semantics of the control.- Specified by:
isCritical
in interfaceControl
- Returns:
true
if this control must be processed by the Directory Server, orfalse
if it can be ignored.
-
-