mirror of https://github.com/M66B/FairEmail.git
Interrupt keep alive only
This commit is contained in:
parent
e2f58970e7
commit
dcf0499f0a
|
@ -4055,6 +4055,7 @@ class Core {
|
||||||
|
|
||||||
static class State {
|
static class State {
|
||||||
private int backoff;
|
private int backoff;
|
||||||
|
private boolean keepalive = false;
|
||||||
private ConnectionHelper.NetworkState networkState;
|
private ConnectionHelper.NetworkState networkState;
|
||||||
private Thread thread = new Thread();
|
private Thread thread = new Thread();
|
||||||
private Semaphore semaphore = new Semaphore(0);
|
private Semaphore semaphore = new Semaphore(0);
|
||||||
|
@ -4099,8 +4100,13 @@ class Core {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean acquire(long milliseconds) throws InterruptedException {
|
boolean acquire(long milliseconds, boolean keepalive) throws InterruptedException {
|
||||||
return semaphore.tryAcquire(milliseconds, TimeUnit.MILLISECONDS);
|
try {
|
||||||
|
this.keepalive = keepalive;
|
||||||
|
return semaphore.tryAcquire(milliseconds, TimeUnit.MILLISECONDS);
|
||||||
|
} finally {
|
||||||
|
this.keepalive = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void error(Throwable ex) {
|
void error(Throwable ex) {
|
||||||
|
@ -4130,8 +4136,10 @@ class Core {
|
||||||
if (ex instanceof OperationCanceledException)
|
if (ex instanceof OperationCanceledException)
|
||||||
recoverable = false;
|
recoverable = false;
|
||||||
|
|
||||||
thread.interrupt();
|
if (keepalive) {
|
||||||
yield();
|
thread.interrupt();
|
||||||
|
yield();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void reset() {
|
void reset() {
|
||||||
|
|
|
@ -899,7 +899,7 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
|
||||||
try {
|
try {
|
||||||
long backoff = RECONNECT_BACKOFF - ago;
|
long backoff = RECONNECT_BACKOFF - ago;
|
||||||
EntityLog.log(ServiceSynchronize.this, account.name + " reconnect backoff=" + (backoff / 1000));
|
EntityLog.log(ServiceSynchronize.this, account.name + " reconnect backoff=" + (backoff / 1000));
|
||||||
state.acquire(backoff);
|
state.acquire(backoff, false);
|
||||||
} catch (InterruptedException ex) {
|
} catch (InterruptedException ex) {
|
||||||
Log.w(account.name + " backoff " + ex.toString());
|
Log.w(account.name + " backoff " + ex.toString());
|
||||||
}
|
}
|
||||||
|
@ -1523,7 +1523,7 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
|
||||||
|
|
||||||
try {
|
try {
|
||||||
wlAccount.release();
|
wlAccount.release();
|
||||||
state.acquire(2 * duration);
|
state.acquire(2 * duration, true);
|
||||||
Log.i("### " + account.name + " keeping alive");
|
Log.i("### " + account.name + " keeping alive");
|
||||||
} catch (InterruptedException ex) {
|
} catch (InterruptedException ex) {
|
||||||
EntityLog.log(this, account.name + " waited state=" + state);
|
EntityLog.log(this, account.name + " waited state=" + state);
|
||||||
|
@ -1638,7 +1638,7 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
|
||||||
if (cbackoff > backoff) {
|
if (cbackoff > backoff) {
|
||||||
try {
|
try {
|
||||||
EntityLog.log(this, account.name + " reconnect backoff=" + cbackoff);
|
EntityLog.log(this, account.name + " reconnect backoff=" + cbackoff);
|
||||||
state.acquire(cbackoff * 1000L);
|
state.acquire(cbackoff * 1000L, false);
|
||||||
} catch (InterruptedException ex) {
|
} catch (InterruptedException ex) {
|
||||||
Log.w(account.name + " cbackoff " + ex.toString());
|
Log.w(account.name + " cbackoff " + ex.toString());
|
||||||
}
|
}
|
||||||
|
@ -1648,7 +1648,7 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
|
||||||
if (backoff <= CONNECT_BACKOFF_MAX) {
|
if (backoff <= CONNECT_BACKOFF_MAX) {
|
||||||
// Short back-off period, keep device awake
|
// Short back-off period, keep device awake
|
||||||
try {
|
try {
|
||||||
state.acquire(backoff * 1000L);
|
state.acquire(backoff * 1000L, false);
|
||||||
} catch (InterruptedException ex) {
|
} catch (InterruptedException ex) {
|
||||||
Log.w(account.name + " backoff " + ex.toString());
|
Log.w(account.name + " backoff " + ex.toString());
|
||||||
}
|
}
|
||||||
|
@ -1681,7 +1681,7 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
|
||||||
|
|
||||||
try {
|
try {
|
||||||
wlAccount.release();
|
wlAccount.release();
|
||||||
state.acquire(2 * backoff * 1000L);
|
state.acquire(2 * backoff * 1000L, false);
|
||||||
Log.i("### " + account.name + " backoff done");
|
Log.i("### " + account.name + " backoff done");
|
||||||
} catch (InterruptedException ex) {
|
} catch (InterruptedException ex) {
|
||||||
Log.w(account.name + " backoff " + ex.toString());
|
Log.w(account.name + " backoff " + ex.toString());
|
||||||
|
|
Loading…
Reference in New Issue