Author: breed
Date: Thu Jan 6 16:06:41 2011
New Revision: 1055924
URL: http://svn.apache.org/viewvc?rev=1055924&view=rev
Log:
ZOOKEEPER-500. Async methods shouldnt throw exceptions
Modified:
zookeeper/trunk/CHANGES.txt
zookeeper/trunk/src/contrib/bookkeeper/src/java/org/apache/bookkeeper/client/BKException.java
zookeeper/trunk/src/contrib/bookkeeper/src/java/org/apache/bookkeeper/client/LedgerHandle.java
zookeeper/trunk/src/contrib/bookkeeper/src/java/org/apache/bookkeeper/client/LedgerRecoveryOp.java
Modified: zookeeper/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/zookeeper/trunk/CHANGES.txt?rev=1055924&r1=1055923&r2=1055924&view=diff
==============================================================================
--- zookeeper/trunk/CHANGES.txt (original)
+++ zookeeper/trunk/CHANGES.txt Thu Jan 6 16:06:41 2011
@@ -223,6 +223,8 @@ IMPROVEMENTS:
ZOOKEEPER-963. Make Forrest work with JDK6 (Carl Steinbach via henryr)
+ ZOOKEEPER-500. Async methods shouldnt throw exceptions (fpj via breed)
+
NEW FEATURES:
ZOOKEEPER-729. Java client API to recursively delete a subtree.
(Kay Kay via henry)
Modified: zookeeper/trunk/src/contrib/bookkeeper/src/java/org/apache/bookkeeper/client/BKException.java
URL: http://svn.apache.org/viewvc/zookeeper/trunk/src/contrib/bookkeeper/src/java/org/apache/bookkeeper/client/BKException.java?rev=1055924&r1=1055923&r2=1055924&view=diff
==============================================================================
--- zookeeper/trunk/src/contrib/bookkeeper/src/java/org/apache/bookkeeper/client/BKException.java
(original)
+++ zookeeper/trunk/src/contrib/bookkeeper/src/java/org/apache/bookkeeper/client/BKException.java
Thu Jan 6 16:06:41 2011
@@ -72,6 +72,8 @@ public abstract class BKException extend
return new BKNoSuchEntryException();
case Code.IncorrectParameterException:
return new BKIncorrectParameterException();
+ case Code.InterruptedException:
+ return new BKInterruptedException();
default:
return new BKIllegalOpException();
}
@@ -97,6 +99,7 @@ public abstract class BKException extend
int WriteException = -12;
int NoSuchEntryException = -13;
int IncorrectParameterException = -14;
+ int InterruptedException = -15;
int IllegalOpException = -100;
}
@@ -141,6 +144,8 @@ public abstract class BKException extend
return "No such entry";
case Code.IncorrectParameterException:
return "Incorrect parameter input";
+ case Code.InterruptedException:
+ return "Interrupted while waiting for permit";
default:
return "Invalid operation";
}
@@ -235,4 +240,10 @@ public abstract class BKException extend
super(Code.IncorrectParameterException);
}
}
+
+ public static class BKInterruptedException extends BKException {
+ public BKInterruptedException() {
+ super(Code.InterruptedException);
+ }
+ }
}
Modified: zookeeper/trunk/src/contrib/bookkeeper/src/java/org/apache/bookkeeper/client/LedgerHandle.java
URL: http://svn.apache.org/viewvc/zookeeper/trunk/src/contrib/bookkeeper/src/java/org/apache/bookkeeper/client/LedgerHandle.java?rev=1055924&r1=1055923&r2=1055924&view=diff
==============================================================================
--- zookeeper/trunk/src/contrib/bookkeeper/src/java/org/apache/bookkeeper/client/LedgerHandle.java
(original)
+++ zookeeper/trunk/src/contrib/bookkeeper/src/java/org/apache/bookkeeper/client/LedgerHandle.java
Thu Jan 6 16:06:41 2011
@@ -277,7 +277,7 @@ public class LedgerHandle implements Rea
* control object
*/
public void asyncReadEntries(long firstEntry, long lastEntry,
- ReadCallback cb, Object ctx) throws InterruptedException {
+ ReadCallback cb, Object ctx) {
// Little sanity check
if (firstEntry < 0 || lastEntry > lastAddConfirmed
|| firstEntry > lastEntry) {
@@ -285,7 +285,12 @@ public class LedgerHandle implements Rea
return;
}
- new PendingReadOp(this, firstEntry, lastEntry, cb, ctx).initiate();
+ try{
+ new PendingReadOp(this, firstEntry, lastEntry, cb, ctx).initiate();
+
+ } catch (InterruptedException e) {
+ cb.readComplete(BKException.Code.InterruptedException, this, null, ctx);
+ }
}
/**
@@ -317,8 +322,13 @@ public class LedgerHandle implements Rea
* some control object
*/
public void asyncAddEntry(final byte[] data, final AddCallback cb,
- final Object ctx) throws InterruptedException {
- opCounterSem.acquire();
+ final Object ctx) {
+ try{
+ opCounterSem.acquire();
+ } catch (InterruptedException e) {
+ cb.addComplete(BKException.Code.InterruptedException,
+ LedgerHandle.this, -1, ctx);
+ }
try{
bk.mainWorkerPool.submitOrdered(ledgerId, new SafeRunnable() {
Modified: zookeeper/trunk/src/contrib/bookkeeper/src/java/org/apache/bookkeeper/client/LedgerRecoveryOp.java
URL: http://svn.apache.org/viewvc/zookeeper/trunk/src/contrib/bookkeeper/src/java/org/apache/bookkeeper/client/LedgerRecoveryOp.java?rev=1055924&r1=1055923&r2=1055924&view=diff
==============================================================================
--- zookeeper/trunk/src/contrib/bookkeeper/src/java/org/apache/bookkeeper/client/LedgerRecoveryOp.java
(original)
+++ zookeeper/trunk/src/contrib/bookkeeper/src/java/org/apache/bookkeeper/client/LedgerRecoveryOp.java
Thu Jan 6 16:06:41 2011
@@ -117,13 +117,8 @@ class LedgerRecoveryOp implements ReadEn
* Try to read past the last confirmed.
*/
private void doRecoveryRead() {
- try{
- lh.lastAddConfirmed++;
- lh.asyncReadEntries(lh.lastAddConfirmed, lh.lastAddConfirmed, this, null);
- } catch (InterruptedException e) {
- LOG.error("Interrupted while trying to read entry.", e);
- Thread.currentThread().interrupt();
- }
+ lh.lastAddConfirmed++;
+ lh.asyncReadEntries(lh.lastAddConfirmed, lh.lastAddConfirmed, this, null);
}
@Override
@@ -131,12 +126,7 @@ class LedgerRecoveryOp implements ReadEn
// get back to prev value
lh.lastAddConfirmed--;
if (rc == BKException.Code.OK) {
- try{
- lh.asyncAddEntry(seq.nextElement().getEntry(), this, null);
- } catch (InterruptedException e) {
- LOG.error("Interrupted while adding entry.", e);
- Thread.currentThread().interrupt();
- }
+ lh.asyncAddEntry(seq.nextElement().getEntry(), this, null);
return;
}
|