Skip to content

Commit

Permalink
[innogysmarthome] Reconnect fix (openhab#8186)
Browse files Browse the repository at this point in the history
* Reconnect fix (isDone was never true, because the scheduled task is every time currently running when the scheduleRestartClient method is executed)

Closes openhab#8182 

Signed-off-by: Sven Strohschein <[email protected]>
  • Loading branch information
Novanic authored and andrewfg committed Aug 31, 2020
1 parent 4b87f43 commit e3fbc5a
Showing 1 changed file with 11 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -288,9 +288,9 @@ public void onAccessTokenResponse(final AccessTokenResponse credential) {
* @param seconds
*/
private synchronized void scheduleRestartClient(final long seconds) {
final ScheduledFuture<?> localReinitJob = reinitJob;
@Nullable final ScheduledFuture<?> localReinitJob = reinitJob;

if (localReinitJob != null && !localReinitJob.isDone()) {
if (localReinitJob != null && isAlreadyScheduled(localReinitJob)) {
logger.debug("Scheduling reinitialize in {} seconds - ignored: already triggered in {} seconds.", seconds,
localReinitJob.getDelay(TimeUnit.SECONDS));
return;
Expand Down Expand Up @@ -951,4 +951,13 @@ private void refreshAccessToken() {
logger.debug("Could not refresh tokens", e);
}
}

/**
* Checks if the job is already (re-)scheduled.
* @param job job to check
* @return true, when the job is already (re-)scheduled, otherwise false
*/
private static boolean isAlreadyScheduled(ScheduledFuture<?> job) {
return job.getDelay(TimeUnit.SECONDS) > 0;
}
}

0 comments on commit e3fbc5a

Please sign in to comment.