Reduce branching depth
Signed-off-by: Emmanuel Bigeon <emmanuel@bigeon.fr>
This commit is contained in:
parent
6b2a25674d
commit
0cef23e17b
@ -194,15 +194,9 @@ public final class ConnectingConsoleInput implements ConsoleInput {
|
|||||||
prompting = true;
|
prompting = true;
|
||||||
}
|
}
|
||||||
while (true) {
|
while (true) {
|
||||||
synchronized (promptLock) {
|
if (!checkPrompt()) {
|
||||||
if (!prompting) {
|
|
||||||
if (interrupting) {
|
|
||||||
interrupting = false;
|
|
||||||
throw new InterruptedIOException("Prompt was interrupted");
|
|
||||||
}
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
getConnection(0);
|
getConnection(0);
|
||||||
boolean connect;
|
boolean connect;
|
||||||
ConsoleInput actualConnected;
|
ConsoleInput actualConnected;
|
||||||
@ -210,7 +204,9 @@ public final class ConnectingConsoleInput implements ConsoleInput {
|
|||||||
connect = connected != null;
|
connect = connected != null;
|
||||||
actualConnected = connected;
|
actualConnected = connected;
|
||||||
}
|
}
|
||||||
if (connect) {
|
if (!connect) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
final String res = actualConnected.prompt(message);
|
final String res = actualConnected.prompt(message);
|
||||||
synchronized (promptLock) {
|
synchronized (promptLock) {
|
||||||
@ -231,7 +227,6 @@ public final class ConnectingConsoleInput implements ConsoleInput {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
* @see fr.bigeon.gclc.manager.ConsoleInput#prompt(java.lang.String, long) */
|
* @see fr.bigeon.gclc.manager.ConsoleInput#prompt(java.lang.String, long) */
|
||||||
@ -245,15 +240,9 @@ public final class ConnectingConsoleInput implements ConsoleInput {
|
|||||||
}
|
}
|
||||||
final long end = System.currentTimeMillis() + timeout;
|
final long end = System.currentTimeMillis() + timeout;
|
||||||
do {
|
do {
|
||||||
synchronized (promptLock) {
|
if (!checkPrompt()) {
|
||||||
if (!prompting) {
|
|
||||||
if (interrupting) {
|
|
||||||
interrupting = false;
|
|
||||||
throw new InterruptedIOException("Prompt was interrupted");
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
getConnection(timeout);
|
getConnection(timeout);
|
||||||
boolean connect;
|
boolean connect;
|
||||||
ConsoleInput actualConnected;
|
ConsoleInput actualConnected;
|
||||||
@ -261,7 +250,9 @@ public final class ConnectingConsoleInput implements ConsoleInput {
|
|||||||
connect = connected != null;
|
connect = connected != null;
|
||||||
actualConnected = connected;
|
actualConnected = connected;
|
||||||
}
|
}
|
||||||
if (connect) {
|
if (!connect) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
final String res = actualConnected.prompt(message,
|
final String res = actualConnected.prompt(message,
|
||||||
end - System.currentTimeMillis());
|
end - System.currentTimeMillis());
|
||||||
@ -281,11 +272,26 @@ public final class ConnectingConsoleInput implements ConsoleInput {
|
|||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
} while (System.currentTimeMillis() < end);
|
} while (System.currentTimeMillis() < end);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Test if we are in prompting state.
|
||||||
|
*
|
||||||
|
* @return if the process is currently in prompting state.
|
||||||
|
* @throws InterruptedIOException if the prompting state has been interrupted */
|
||||||
|
private boolean checkPrompt() throws InterruptedIOException {
|
||||||
|
synchronized (promptLock) {
|
||||||
|
if (!prompting) {
|
||||||
|
if (interrupting) {
|
||||||
|
interrupting = false;
|
||||||
|
throw new InterruptedIOException("Prompt was interrupted");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return prompting;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void getConnection(final long timeout) throws InterruptedIOException {
|
private void getConnection(final long timeout) throws InterruptedIOException {
|
||||||
boolean connect;
|
boolean connect;
|
||||||
synchronized (connectionLock) {
|
synchronized (connectionLock) {
|
||||||
|
Loading…
Reference in New Issue
Block a user