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;
     }
 }
 
See Also:
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final List<String>
    The user-friendly aliases for the simple paged results control.
    A decoder which can be used for decoding the simple paged results control.
    static final String
    The OID for the paged results request/response control defined in RFC 2696.
  • Method Summary

    Modifier and Type
    Method
    Description
    Returns the control "friendly name" alias for the control.
    Returns the opaque cookie which is used by the server to track its position in the set of search results.
    Returns the numeric OID associated with this control.
    int
    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 value, if any, associated with this control.
    boolean
    Returns true if this control has a value.
    boolean
    Returns true if it is unacceptable to perform the operation without applying the semantics of this control.
    newControl(boolean isCritical, int size, ByteString cookie)
    Creates a new simple paged results control with the provided criticality, size, and cookie.
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Field Details

    • OID

      public static final String OID
      The OID for the paged results request/response control defined in RFC 2696.
      See Also:
    • ALIASES

      public static final List<String> ALIASES
      The user-friendly aliases for the simple paged results control.
    • DECODER

      public static final ControlDecoder<SimplePagedResultsControl> DECODER
      A decoder which can be used for decoding the simple paged results control.
  • Method Details

    • 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, or false 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 - If cookie was null.
    • 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.
      Specified by:
      getOid in 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.
      Specified by:
      getValue in interface Control
      Returns:
      The value associated with this control, or null if there is no value.
    • hasValue

      public boolean hasValue()
      Description copied from interface: Control
      Returns true 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.
      Specified by:
      hasValue in interface Control
      Returns:
      true if this control has a value, or false if there is no value.
    • isCritical

      public boolean isCritical()
      Description copied from interface: Control
      Returns true 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 of true indicates that it is unacceptable to perform the operation without applying the semantics of the control.

      Specified by:
      isCritical in interface Control
      Returns:
      true if this control must be processed by the Directory Server, or false if it can be ignored.
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • getAlias

      public String getAlias()
      Description copied from interface: Control
      Returns the control "friendly name" alias for the control.
      Specified by:
      getAlias in interface Control
      Returns:
      "Friendly name" alias for the control.