Code factoring
Signed-off-by: Emmanuel Bigeon <emmanuel@bigeon.fr>
This commit is contained in:
parent
bcd0faceef
commit
df688b1a85
@ -68,7 +68,6 @@ package net.bigeon.gclc.process.io;
|
||||
* #L%
|
||||
*/
|
||||
import java.io.IOException;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import net.bigeon.gclc.manager.ConsoleInput;
|
||||
@ -198,19 +197,8 @@ public final class ConnectingConsoleInput implements ConsoleInput {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
getConnection(0);
|
||||
boolean connect;
|
||||
synchronized (connectionLock) {
|
||||
connect = connected != null;
|
||||
if (!connect) {
|
||||
try {
|
||||
connectionLock.wait();
|
||||
} catch (final InterruptedException e) {
|
||||
LOGGER.log(Level.WARNING, "Inerruption of console thread", e);
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ConsoleInput actualConnected;
|
||||
synchronized (connectionLock) {
|
||||
connect = connected != null;
|
||||
@ -245,20 +233,11 @@ public final class ConnectingConsoleInput implements ConsoleInput {
|
||||
do {
|
||||
synchronized (promptLock) {
|
||||
if (!prompting) {
|
||||
return null;
|
||||
break;
|
||||
}
|
||||
}
|
||||
getConnection(timeout);
|
||||
boolean connect;
|
||||
synchronized (connectionLock) {
|
||||
connect = connected != null;
|
||||
if (!connect) {
|
||||
try {
|
||||
connectionLock.wait(timeout);
|
||||
} catch (final InterruptedException e) {
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
}
|
||||
}
|
||||
ConsoleInput actualConnected;
|
||||
synchronized (connectionLock) {
|
||||
connect = connected != null;
|
||||
@ -282,6 +261,20 @@ public final class ConnectingConsoleInput implements ConsoleInput {
|
||||
|
||||
}
|
||||
|
||||
private void getConnection(final long timeout) {
|
||||
boolean connect;
|
||||
synchronized (connectionLock) {
|
||||
connect = connected != null;
|
||||
if (!connect) {
|
||||
try {
|
||||
connectionLock.wait(timeout);
|
||||
} catch (final InterruptedException e) {
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see fr.bigeon.gclc.manager.ConsoleInput#setPrompt(java.lang.String) */
|
||||
@Override
|
||||
|
@ -81,10 +81,10 @@ public class ConnectingConsoleInputTest {
|
||||
|
||||
@Override
|
||||
public void apply() throws Exception {
|
||||
assertNull(in.prompt("m1", -1));
|
||||
assertNull(in.prompt("m2", 5000));
|
||||
assertNull("Interrupted should return null", in.prompt("m1", -1));
|
||||
assertNull("Interrupted should return null", in.prompt("m2", 5000));
|
||||
ended.set(true);
|
||||
assertNull(in.prompt("m3", 200));
|
||||
assertNull("Overtime should return null", in.prompt("m3", 200));
|
||||
}
|
||||
};
|
||||
final ATestRunnable runnable = new FunctionalTestRunnable(one);
|
||||
|
Loading…
Reference in New Issue
Block a user