| | |
| | | |
| | | import static org.forgerock.opendj.ldap.ErrorResultException.newErrorResult; |
| | | |
| | | import java.io.InterruptedIOException; |
| | | import java.util.NoSuchElementException; |
| | | import java.util.concurrent.BlockingQueue; |
| | | import java.util.concurrent.LinkedBlockingQueue; |
| | |
| | | // Prevent the reader from waiting for a result that will never |
| | | // arrive. |
| | | isInterrupted = true; |
| | | |
| | | Thread.currentThread().interrupt(); |
| | | return false; |
| | | } |
| | |
| | | // Prevent the reader from waiting for a result that will never |
| | | // arrive. |
| | | isInterrupted = true; |
| | | |
| | | Thread.currentThread().interrupt(); |
| | | } |
| | | } |
| | |
| | | // Prevent the reader from waiting for a result that will never |
| | | // arrive. |
| | | isInterrupted = true; |
| | | |
| | | Thread.currentThread().interrupt(); |
| | | return false; |
| | | } |
| | |
| | | // Prevent the reader from waiting for a result that will never |
| | | // arrive. |
| | | isInterrupted = true; |
| | | |
| | | Thread.currentThread().interrupt(); |
| | | } |
| | | } |
| | |
| | | } |
| | | |
| | | /** |
| | | * Closes this connection entry reader, cancelling the search request if it |
| | | * Closes this connection entry reader, canceling the search request if it |
| | | * is still active. |
| | | */ |
| | | @Override |
| | |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | public boolean hasNext() throws ErrorResultIOException, InterruptedIOException { |
| | | public boolean hasNext() throws ErrorResultIOException { |
| | | // Poll for the next response if needed. |
| | | final Response r = getNextResponse(); |
| | | if (!(r instanceof Result)) { |
| | |
| | | * If there are no more search result entries or references and |
| | | * the search result code indicates that the search operation |
| | | * failed for some reason. |
| | | * @throws InterruptedIOException |
| | | * If the current thread was interrupted while waiting. |
| | | * @throws NoSuchElementException |
| | | * If there are no more search result entries or references and |
| | | * the search result code indicates that the search operation |
| | | * succeeded. |
| | | */ |
| | | public boolean isEntry() throws ErrorResultIOException, InterruptedIOException { |
| | | public boolean isEntry() throws ErrorResultIOException { |
| | | // Throws ErrorResultIOException if search returned error. |
| | | if (!hasNext()) { |
| | | // Search has completed successfully. |
| | |
| | | * If there are no more search result entries or references and |
| | | * the search result code indicates that the search operation |
| | | * failed for some reason. |
| | | * @throws InterruptedIOException |
| | | * If the current thread was interrupted while waiting. |
| | | * @throws NoSuchElementException |
| | | * If there are no more search result entries or references and |
| | | * the search result code indicates that the search operation |
| | | * succeeded. |
| | | */ |
| | | public boolean isReference() throws ErrorResultIOException, InterruptedIOException { |
| | | public boolean isReference() throws ErrorResultIOException { |
| | | return !isEntry(); |
| | | } |
| | | |
| | |
| | | * If there are no more search result entries or references and |
| | | * the search result code indicates that the search operation |
| | | * failed for some reason. |
| | | * @throws InterruptedIOException |
| | | * If the current thread was interrupted while waiting. |
| | | * @throws NoSuchElementException |
| | | * If there are no more search result entries or references and |
| | | * the search result code indicates that the search operation |
| | |
| | | */ |
| | | @Override |
| | | public SearchResultEntry readEntry() throws SearchResultReferenceIOException, |
| | | ErrorResultIOException, InterruptedIOException { |
| | | ErrorResultIOException { |
| | | if (isEntry()) { |
| | | final SearchResultEntry entry = (SearchResultEntry) nextResponse; |
| | | nextResponse = null; |
| | |
| | | * If there are no more search result entries or references and |
| | | * the search result code indicates that the search operation |
| | | * failed for some reason. |
| | | * @throws InterruptedIOException |
| | | * If the current thread was interrupted while waiting. |
| | | * @throws NoSuchElementException |
| | | * If there are no more search result entries or references and |
| | | * the search result code indicates that the search operation |
| | | * succeeded. |
| | | */ |
| | | public SearchResultReference readReference() throws ErrorResultIOException, |
| | | InterruptedIOException { |
| | | public SearchResultReference readReference() throws ErrorResultIOException { |
| | | if (isReference()) { |
| | | final SearchResultReference reference = (SearchResultReference) nextResponse; |
| | | nextResponse = null; |
| | |
| | | } |
| | | } |
| | | |
| | | private Response getNextResponse() throws InterruptedIOException { |
| | | private Response getNextResponse() throws ErrorResultIOException { |
| | | while (nextResponse == null) { |
| | | try { |
| | | nextResponse = buffer.responses.poll(50, TimeUnit.MILLISECONDS); |
| | | } catch (final InterruptedException e) { |
| | | throw new InterruptedIOException(e.getMessage()); |
| | | final ErrorResultException ere = |
| | | newErrorResult(ResultCode.CLIENT_SIDE_USER_CANCELLED, e); |
| | | throw new ErrorResultIOException(ere); |
| | | } |
| | | |
| | | if (nextResponse == null && buffer.isInterrupted) { |