From f134ef63e016bf13b70bef1ec277603b8a9a6f21 Mon Sep 17 00:00:00 2001
From: Matthew Swift <matthew.swift@forgerock.com>
Date: Wed, 25 Apr 2012 11:06:50 +0000
Subject: [PATCH] Fix OPENDJ-474: Remove requirement for clients to deal with InterruptedExceptions in synchronous APIs
---
opendj3/opendj-ldap-sdk/src/main/java/org/forgerock/opendj/ldif/ConnectionEntryReader.java | 32 ++++++++++----------------------
1 files changed, 10 insertions(+), 22 deletions(-)
diff --git a/opendj3/opendj-ldap-sdk/src/main/java/org/forgerock/opendj/ldif/ConnectionEntryReader.java b/opendj3/opendj-ldap-sdk/src/main/java/org/forgerock/opendj/ldif/ConnectionEntryReader.java
index 39c3129..d1fa617 100644
--- a/opendj3/opendj-ldap-sdk/src/main/java/org/forgerock/opendj/ldif/ConnectionEntryReader.java
+++ b/opendj3/opendj-ldap-sdk/src/main/java/org/forgerock/opendj/ldif/ConnectionEntryReader.java
@@ -29,7 +29,6 @@
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;
@@ -121,7 +120,6 @@
// Prevent the reader from waiting for a result that will never
// arrive.
isInterrupted = true;
-
Thread.currentThread().interrupt();
return false;
}
@@ -135,7 +133,6 @@
// Prevent the reader from waiting for a result that will never
// arrive.
isInterrupted = true;
-
Thread.currentThread().interrupt();
}
}
@@ -149,7 +146,6 @@
// Prevent the reader from waiting for a result that will never
// arrive.
isInterrupted = true;
-
Thread.currentThread().interrupt();
return false;
}
@@ -163,7 +159,6 @@
// Prevent the reader from waiting for a result that will never
// arrive.
isInterrupted = true;
-
Thread.currentThread().interrupt();
}
}
@@ -210,7 +205,7 @@
}
/**
- * 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
@@ -223,7 +218,7 @@
* {@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)) {
@@ -251,14 +246,12 @@
* 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.
@@ -287,14 +280,12 @@
* 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();
}
@@ -314,8 +305,6 @@
* 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
@@ -323,7 +312,7 @@
*/
@Override
public SearchResultEntry readEntry() throws SearchResultReferenceIOException,
- ErrorResultIOException, InterruptedIOException {
+ ErrorResultIOException {
if (isEntry()) {
final SearchResultEntry entry = (SearchResultEntry) nextResponse;
nextResponse = null;
@@ -347,15 +336,12 @@
* 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;
@@ -365,12 +351,14 @@
}
}
- 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) {
--
Gitblit v1.10.0