[freebox] Fix handling of InterruptedException (Thread.sleep) (#10462)

Signed-off-by: Laurent Garnier <lg.hc@free.fr>
This commit is contained in:
lolodomo 2021-04-05 15:13:38 +02:00 committed by GitHub
parent 80ffaeec7b
commit fbea2f3535
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 4 deletions

View File

@ -121,7 +121,8 @@ public class FreeboxApiManager {
} }
} }
public boolean authorize(boolean useHttps, String fqdn, String apiBaseUrl, String apiVersion, String appToken) { public boolean authorize(boolean useHttps, String fqdn, String apiBaseUrl, String apiVersion, String appToken)
throws InterruptedException {
String[] versionSplit = apiVersion.split("\\."); String[] versionSplit = apiVersion.split("\\.");
String majorVersion = "5"; String majorVersion = "5";
if (versionSplit.length > 0) { if (versionSplit.length > 0) {
@ -155,7 +156,7 @@ public class FreeboxApiManager {
this.appToken = token; this.appToken = token;
openSession(); openSession();
return true; return true;
} catch (FreeboxException | InterruptedException e) { } catch (FreeboxException e) {
logger.debug("Error while opening a session", e); logger.debug("Error while opening a session", e);
return false; return false;
} }

View File

@ -158,7 +158,13 @@ public class FreeboxHandler extends BaseBridgeHandler {
logger.debug("Binding will schedule a job to establish a connection..."); logger.debug("Binding will schedule a job to establish a connection...");
if (authorizeJob == null || authorizeJob.isCancelled()) { if (authorizeJob == null || authorizeJob.isCancelled()) {
authorizeJob = scheduler.schedule(this::authorize, 1, TimeUnit.SECONDS); authorizeJob = scheduler.schedule(() -> {
try {
authorize();
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
}, 1, TimeUnit.SECONDS);
} }
} else { } else {
updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR, updateStatus(ThingStatus.OFFLINE, ThingStatusDetail.CONFIGURATION_ERROR,
@ -196,7 +202,7 @@ public class FreeboxHandler extends BaseBridgeHandler {
} }
} }
private void authorize() { private void authorize() throws InterruptedException {
logger.debug("Authorize job..."); logger.debug("Authorize job...");
String fqdn = configuration.fqdn; String fqdn = configuration.fqdn;