Class PagedResultsControl
Class PagedResultsControl
public final class PagedResultsControl
extends BasicControl
검색 연산의 결과를 LDAP 서버가 지정된 크기의 배치(batch)로 반환하도록 요청해요. 요청자는 검색 연산을 호출하는 속도로 배치가 반환되는 속도를 제어해요. 다음 코드 샘플은 이 클래스의 사용법을 보여줘요.
// Open an LDAP association
LdapContext ctx = new InitialLdapContext();
// Activate paged results
int pageSize = 20; // 20 entries per page
byte[] cookie = null;
int total;
ctx.setRequestControls(new Control[]{
new PagedResultsControl(pageSize, Control.CRITICAL) });
do {
// Perform the search
NamingEnumeration results =
ctx.search("", "(objectclass=*)", new SearchControls());
// Iterate over a batch of search results
while (results != null && results.hasMore()) {
// Display an entry
SearchResult entry = (SearchResult)results.next();
System.out.println(entry.getName());
System.out.println(entry.getAttributes());
// Handle the entry's response controls (if any)
if (entry instanceof HasControls) {
// ((HasControls)entry).getControls();
}
}
// Examine the paged results control response
Control[] controls = ctx.getResponseControls();
if (controls != null) {
for (int i = 0; i < controls.length; i++) {
if (controls[i] instanceof PagedResultsResponseControl) {
PagedResultsResponseControl prrc =
(PagedResultsResponseControl)controls[i];
total = prrc.getResultSize();
cookie = prrc.getCookie();
} else {
// Handle other response controls (if any)
}
}
}
// Re-activate paged results
ctx.setRequestControls(new Control[]{
new PagedResultsControl(pageSize, cookie, Control.CRITICAL) });
} while (cookie != null);
// Close the LDAP association
ctx.close();
이 클래스는 RFC 2696에 정의된 페이징 결과(paged-results)에 대한 LDAPv3 Control을 구현해요. 컨트롤 값은 다음과 같은 ASN.1 정의를 가져요.
realSearchControlValue ::= SEQUENCE {
size INTEGER (0..maxInt),
-- requested page size from client
-- result set size estimate from server
cookie OCTET STRING }
OID
public static final String OID
페이징 결과 컨트롤의 할당된 객체 식별자는 1.2.840.113556.1.4.319이에요.
- See Also: 상수 필드 값(Constant Field Values)
PagedResultsControl
public PagedResultsControl(int pageSize,
boolean criticality)
throws IOException
결과 페이지당 반환할 항목 수를 설정하는 컨트롤을 생성해요.
- Parameters: pageSize - 페이지에 반환할 항목 수
- Throws: IOException - 제공된 인자를 컨트롤로 인코딩하는 동안 오류가 발생했을 때
PagedResultsControl
public PagedResultsControl(int pageSize,
byte[] cookie,
boolean criticality)
throws IOException
결과 페이지당 반환할 항목 수를 설정하는 컨트롤을 생성해요. cookie는 서버가 제공하며 페이징 결과 응답 컨트롤에서 얻을 수 있어요. pageSize를 0으로 설정하고 서버에서 마지막으로 받은 쿠키로 cookie를 설정하면 페이징 결과 시퀀스를 중단할 수 있어요.
- Parameters: pageSize - 페이지에 반환할 항목 수
- Throws: IOException - 제공된 인자를 컨트롤로 인코딩하는 동안 오류가 발생했을 때