mirror of
https://github.com/google/nomulus.git
synced 2025-05-13 16:07:15 +02:00
Add Runnable overrides to ease use of Java 8 language features
Runnable and Callable are both @FunctionalInterfaces. The difference is that Callable requires a return value whereas Runnable does not, so in situations where we don't care about a return value, rather than having to add an unnecessary 'return null;' at the end of the lambda, we can simply use a non-returning Runnable instead. Unfortunately, owing to legacy reasons, Runnable is not declared to throw checked exceptions whereas Callable is, so in situations where checked exceptions are thrown we still need to have a 'return null;' call at the end. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=172935400
This commit is contained in:
parent
d577a281b8
commit
1790914058
13 changed files with 141 additions and 134 deletions
|
@ -44,7 +44,6 @@ import java.io.ByteArrayInputStream;
|
|||
import java.net.MalformedURLException;
|
||||
import java.net.SocketTimeoutException;
|
||||
import java.net.URL;
|
||||
import java.util.concurrent.Callable;
|
||||
import javax.inject.Inject;
|
||||
|
||||
/**
|
||||
|
@ -81,21 +80,20 @@ public class RdeReporter {
|
|||
req.addHeader(new HTTPHeader(AUTHORIZATION, "Basic " + token));
|
||||
req.setPayload(reportBytes);
|
||||
logger.infofmt("Sending report:\n%s", new String(reportBytes, UTF_8));
|
||||
HTTPResponse rsp = retrier.callWithRetry(
|
||||
new Callable<HTTPResponse>() {
|
||||
@Override
|
||||
public HTTPResponse call() throws Exception {
|
||||
HTTPResponse rsp = urlFetchService.fetch(req);
|
||||
switch (rsp.getResponseCode()) {
|
||||
case SC_OK:
|
||||
case SC_BAD_REQUEST:
|
||||
break;
|
||||
default:
|
||||
throw new UrlFetchException("PUT failed", req, rsp);
|
||||
}
|
||||
return rsp;
|
||||
}
|
||||
}, SocketTimeoutException.class);
|
||||
HTTPResponse rsp =
|
||||
retrier.callWithRetry(
|
||||
() -> {
|
||||
HTTPResponse rsp1 = urlFetchService.fetch(req);
|
||||
switch (rsp1.getResponseCode()) {
|
||||
case SC_OK:
|
||||
case SC_BAD_REQUEST:
|
||||
break;
|
||||
default:
|
||||
throw new UrlFetchException("PUT failed", req, rsp1);
|
||||
}
|
||||
return rsp1;
|
||||
},
|
||||
SocketTimeoutException.class);
|
||||
|
||||
// Ensure the XML response is valid.
|
||||
XjcIirdeaResult result = parseResult(rsp);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue