Skip to content

Commit

Permalink
Refactoring: Added helper function exceptionCauseIsInstanceOf
Browse files Browse the repository at this point in the history
  • Loading branch information
Jason Jackson committed May 10, 2013
1 parent 43053a7 commit 1761546
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
11 changes: 11 additions & 0 deletions src/jvm/backtype/storm/utils/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -357,4 +357,15 @@ public static byte[] toByteArray(ByteBuffer buffer) {
buffer.get(ret, 0, ret.length);
return ret;
}

public static boolean exceptionCauseIsInstanceOf(Class klass, Throwable throwable) {
Throwable t = throwable;
while(t != null) {
if(klass.isInstance(t)) {
return true;
}
t = t.getCause();
}
return false;
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package storm.trident.topology.state;

import backtype.storm.utils.Utils;
import org.apache.zookeeper.KeeperException;

import java.util.HashSet;
Expand Down Expand Up @@ -103,11 +104,10 @@ public void cleanupBefore(long txid) {
} catch(RuntimeException e) {
// Ignore NoNodeExists exceptions because when sync() it may populate _curr with stale data since
// zookeeper reads are eventually consistent.
if(!(e.getCause() instanceof KeeperException.NoNodeException)) {
if(!Utils.exceptionCauseIsInstanceOf(KeeperException.NoNodeException.class, e)) {
throw e;
}
}

}
}

Expand Down

0 comments on commit 1761546

Please sign in to comment.