Fix interruption mechanic
Signed-off-by: Emmanuel Bigeon <emmanuel@bigeon.fr>
This commit is contained in:
parent
eec660e089
commit
6b2a25674d
@ -196,6 +196,10 @@ public final class ConnectingConsoleInput implements ConsoleInput {
|
|||||||
while (true) {
|
while (true) {
|
||||||
synchronized (promptLock) {
|
synchronized (promptLock) {
|
||||||
if (!prompting) {
|
if (!prompting) {
|
||||||
|
if (interrupting) {
|
||||||
|
interrupting = false;
|
||||||
|
throw new InterruptedIOException("Prompt was interrupted");
|
||||||
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -211,6 +215,7 @@ public final class ConnectingConsoleInput implements ConsoleInput {
|
|||||||
final String res = actualConnected.prompt(message);
|
final String res = actualConnected.prompt(message);
|
||||||
synchronized (promptLock) {
|
synchronized (promptLock) {
|
||||||
if (prompting) {
|
if (prompting) {
|
||||||
|
prompting = false;
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -235,13 +240,17 @@ public final class ConnectingConsoleInput implements ConsoleInput {
|
|||||||
if (timeout <= 0) {
|
if (timeout <= 0) {
|
||||||
return prompt(message);
|
return prompt(message);
|
||||||
}
|
}
|
||||||
final long end = System.currentTimeMillis() + timeout;
|
|
||||||
synchronized (promptLock) {
|
synchronized (promptLock) {
|
||||||
prompting = true;
|
prompting = true;
|
||||||
}
|
}
|
||||||
|
final long end = System.currentTimeMillis() + timeout;
|
||||||
do {
|
do {
|
||||||
synchronized (promptLock) {
|
synchronized (promptLock) {
|
||||||
if (!prompting) {
|
if (!prompting) {
|
||||||
|
if (interrupting) {
|
||||||
|
interrupting = false;
|
||||||
|
throw new InterruptedIOException("Prompt was interrupted");
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -253,28 +262,28 @@ public final class ConnectingConsoleInput implements ConsoleInput {
|
|||||||
actualConnected = connected;
|
actualConnected = connected;
|
||||||
}
|
}
|
||||||
if (connect) {
|
if (connect) {
|
||||||
synchronized (promptLock) {
|
try {
|
||||||
try {
|
final String res = actualConnected.prompt(message,
|
||||||
final String res = actualConnected.prompt(message,
|
end - System.currentTimeMillis());
|
||||||
end - System.currentTimeMillis());
|
synchronized (promptLock) {
|
||||||
if (prompting) {
|
if (prompting) {
|
||||||
|
prompting = false;
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
} catch (final InterruptedIOException e) {
|
}
|
||||||
// The inner console was interrupted. This can mean we are
|
} catch (final InterruptedIOException e) {
|
||||||
// disconnecting or actually interrupted.
|
// The inner console was interrupted. This can mean we are
|
||||||
if (disconnection) {
|
// disconnecting or actually interrupted.
|
||||||
disconnection = false;
|
if (disconnection) {
|
||||||
} else {
|
disconnection = false;
|
||||||
throw e;
|
} else {
|
||||||
}
|
interrupting = false;
|
||||||
|
throw e;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} while (System.currentTimeMillis() < end);
|
} while (System.currentTimeMillis() < end);
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void getConnection(final long timeout) throws InterruptedIOException {
|
private void getConnection(final long timeout) throws InterruptedIOException {
|
||||||
|
Loading…
Reference in New Issue
Block a user