SOLR-8995: replace SAM implementations with lambda

This commit is contained in:
Noble Paul 2016-06-20 11:11:18 +05:30
parent 0179b3fb2d
commit bd9005d562
3 changed files with 36 additions and 52 deletions

View File

@ -180,10 +180,7 @@ class ShardLeaderElectionContextBase extends ElectionContext {
zcmd.ensureExists(parent, zkClient);
try {
RetryUtil.retryOnThrowable(NodeExistsException.class, 60000, 5000, new RetryCmd() {
@Override
public void execute() throws InterruptedException, KeeperException {
RetryUtil.retryOnThrowable(NodeExistsException.class, 60000, 5000, () -> {
synchronized (lock) {
log.info("Creating leader registration node {} after winning as {}", leaderPath, leaderSeqPath);
List<Op> ops = new ArrayList<>(2);
@ -209,7 +206,6 @@ class ShardLeaderElectionContextBase extends ElectionContext {
}
assert leaderZkNodeParentVersion != null;
}
}
});
} catch (Throwable t) {
if (t instanceof OutOfMemoryError) {

View File

@ -30,12 +30,12 @@ import org.slf4j.LoggerFactory;
public class RetryUtil {
private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
public static interface RetryCmd {
public void execute() throws Throwable;
public interface RetryCmd {
void execute() throws Throwable;
}
public static interface BooleanRetryCmd {
public boolean execute();
public interface BooleanRetryCmd {
boolean execute();
}
public static void retryOnThrowable(Class clazz, long timeoutms, long intervalms, RetryCmd cmd) throws Throwable {

View File

@ -28,15 +28,11 @@ public class TestRetryUtil extends SolrTestCaseJ4 {
public void testRetryOnThrowable() throws Throwable {
final AtomicInteger executes = new AtomicInteger();
RetryUtil.retryOnThrowable(SolrException.class, 10000, 10, new RetryCmd() {
@Override
public void execute() throws Throwable {
RetryUtil.retryOnThrowable(SolrException.class, 10000, 10, () -> {
int calls = executes.incrementAndGet();
if (calls <= 2) {
throw new SolrException(ErrorCode.SERVER_ERROR, "Bad Stuff Happened");
}
}
});
assertEquals(3, executes.get());
@ -45,16 +41,12 @@ public class TestRetryUtil extends SolrTestCaseJ4 {
boolean caughtSolrException = false;
try {
RetryUtil.retryOnThrowable(IllegalStateException.class, 10000, 10,
new RetryCmd() {
@Override
public void execute() throws Throwable {
() -> {
int calls = executes2.incrementAndGet();
if (calls <= 2) {
throw new SolrException(ErrorCode.SERVER_ERROR,
"Bad Stuff Happened");
}
}
});
} catch (SolrException e) {
caughtSolrException = true;
@ -65,13 +57,9 @@ public class TestRetryUtil extends SolrTestCaseJ4 {
final AtomicInteger executes3 = new AtomicInteger();
caughtSolrException = false;
try {
RetryUtil.retryOnThrowable(SolrException.class, 1000, 10, new RetryCmd() {
@Override
public void execute() throws Throwable {
RetryUtil.retryOnThrowable(SolrException.class, 1000, 10, () -> {
executes3.incrementAndGet();
throw new SolrException(ErrorCode.SERVER_ERROR, "Bad Stuff Happened");
}
});
} catch (SolrException e) {
caughtSolrException = true;