Clean up
Signed-off-by: Emmanuel Bigeon <emmanuel@bigeon.fr>
This commit is contained in:
parent
31ad72567a
commit
d7ecd75678
@ -94,6 +94,7 @@ import net.bigeon.gclc.manager.ConsoleOutput;
|
||||
* @author Emmanuel Bigeon */
|
||||
public class CommandForeground extends ParametrizedCommand {
|
||||
|
||||
private static final int MILLIS_IN_A_SEC = 1000;
|
||||
/** The class logger. */
|
||||
private static final Logger LOGGER = Logger
|
||||
.getLogger(CommandForeground.class.getName());
|
||||
@ -145,7 +146,7 @@ public class CommandForeground extends ParametrizedCommand {
|
||||
long delai = 0;
|
||||
final String delaiOpt = parameters.get("delai");
|
||||
if (delaiOpt != null) {
|
||||
delai = Long.parseLong(delaiOpt) * 1000;
|
||||
delai = Long.parseLong(delaiOpt) * MILLIS_IN_A_SEC;
|
||||
}
|
||||
if (delai < 0) {
|
||||
throw new CommandRunException("Join delai cannot be negative");
|
||||
|
@ -71,6 +71,7 @@ package net.bigeon.gclc.process;
|
||||
/** A listener for interruption.
|
||||
*
|
||||
* @author Emmanuel Bigeon */
|
||||
@FunctionalInterface
|
||||
public interface InterruptionListener {
|
||||
/** Notification of an interuption of a listened object */
|
||||
void interrupted();
|
||||
|
@ -69,7 +69,6 @@ package net.bigeon.gclc.process;
|
||||
* #L%
|
||||
*/
|
||||
import net.bigeon.gclc.command.Command;
|
||||
import net.bigeon.gclc.exception.CommandRunException;
|
||||
import net.bigeon.gclc.manager.ConsoleInput;
|
||||
import net.bigeon.gclc.manager.ConsoleOutput;
|
||||
|
||||
@ -98,12 +97,10 @@ public final class ProcessClear extends Command {
|
||||
pool.remove(id);
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see fr.bigeon.gclc.command.ICommand#tip() */
|
||||
@SuppressWarnings("nls")
|
||||
@Override
|
||||
public String tip() {
|
||||
return "Request a process to stop (softly)";
|
||||
|
@ -69,7 +69,6 @@ package net.bigeon.gclc.process;
|
||||
* #L%
|
||||
*/
|
||||
import net.bigeon.gclc.command.Command;
|
||||
import net.bigeon.gclc.exception.CommandRunException;
|
||||
import net.bigeon.gclc.manager.ConsoleInput;
|
||||
import net.bigeon.gclc.manager.ConsoleOutput;
|
||||
|
||||
@ -98,7 +97,6 @@ public final class ProcessKill extends Command {
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see fr.bigeon.gclc.command.ICommand#tip() */
|
||||
@SuppressWarnings("nls")
|
||||
@Override
|
||||
public String tip() {
|
||||
return "Request a process to stop (softly)";
|
||||
|
@ -115,7 +115,6 @@ public final class ProcessList extends Command {
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see fr.bigeon.gclc.command.ICommand#tip() */
|
||||
@SuppressWarnings("nls")
|
||||
@Override
|
||||
public String tip() {
|
||||
return "List all processes";
|
||||
|
@ -91,7 +91,7 @@ public final class TaskPool {
|
||||
}
|
||||
|
||||
/** Default constructor. */
|
||||
public TaskPool(boolean autoClear) {
|
||||
public TaskPool(final boolean autoClear) {
|
||||
this.autoClear = autoClear;
|
||||
}
|
||||
|
||||
@ -110,12 +110,9 @@ public final class TaskPool {
|
||||
}
|
||||
if (autoClear) {
|
||||
cmd.addInterruptionListener(new InterruptionListener() {
|
||||
@SuppressWarnings("synthetic-access")
|
||||
@Override
|
||||
public void interrupted() {
|
||||
synchronized (lock) {
|
||||
remove(pid);
|
||||
}
|
||||
remove(pid);
|
||||
cmd.rmInterruptionListener(this);
|
||||
}
|
||||
});
|
||||
@ -161,7 +158,7 @@ public final class TaskPool {
|
||||
/** Remove a task from the pool
|
||||
*
|
||||
* @param pid the task id */
|
||||
public void remove(String pid) {
|
||||
public void remove(final String pid) {
|
||||
synchronized (lock) {
|
||||
running.remove(pid);
|
||||
count = Math.min(count, Integer.parseInt(pid));
|
||||
|
@ -86,7 +86,7 @@ public abstract class TaskSpawner extends Command {
|
||||
/** @param name the command name
|
||||
* @param pool the pool */
|
||||
public TaskSpawner(final String name, final TaskPool pool,
|
||||
ExecutorService threadPool) {
|
||||
final ExecutorService threadPool) {
|
||||
super(name);
|
||||
this.pool = pool;
|
||||
this.threadPool = threadPool;
|
||||
@ -107,8 +107,7 @@ public abstract class TaskSpawner extends Command {
|
||||
public final void execute(final ConsoleOutput out, final ConsoleInput in,
|
||||
final String... args) throws CommandRunException {
|
||||
final Task task = createTask(out, in, args);
|
||||
final Thread th = new Thread(task);
|
||||
pool.add(task);
|
||||
threadPool.execute(th);
|
||||
threadPool.execute(task);
|
||||
}
|
||||
}
|
||||
|
@ -72,20 +72,23 @@ import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import net.bigeon.gclc.manager.ConsoleInput;
|
||||
import net.bigeon.gclc.tools.ConstantString;
|
||||
import net.bigeon.gclc.tools.StringProvider;
|
||||
|
||||
/** @author Emmanuel Bigeon */
|
||||
public final class ConnectingConsoleInput implements ConsoleInput {
|
||||
|
||||
private static final Logger LOGGER = Logger
|
||||
private static final ConstantString EMPTY_STRING = new ConstantString("");
|
||||
private static final Logger LOGGER = Logger
|
||||
.getLogger(ConnectingConsoleInput.class.getName());
|
||||
private boolean close = false;
|
||||
private StringProvider prompt;
|
||||
private boolean prompting;
|
||||
private final Object promptLock = new Object();
|
||||
private final Object connectionLock = new Object();
|
||||
private ConsoleInput connected;
|
||||
private boolean disconnection;
|
||||
|
||||
private boolean close = false;
|
||||
private StringProvider prompt = EMPTY_STRING;
|
||||
private boolean prompting = false;
|
||||
private final Object promptLock = new Object();
|
||||
private final Object connectionLock = new Object();
|
||||
private ConsoleInput connected = null;
|
||||
private boolean disconnection = false;
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see fr.bigeon.gclc.manager.ConsoleInput#close() */
|
||||
@ -94,7 +97,7 @@ public final class ConnectingConsoleInput implements ConsoleInput {
|
||||
close = true;
|
||||
}
|
||||
|
||||
public void connect(ConsoleInput input) {
|
||||
public void connect(final ConsoleInput input) {
|
||||
disconnect();
|
||||
synchronized (promptLock) {
|
||||
connected = input;
|
||||
@ -151,19 +154,22 @@ public final class ConnectingConsoleInput implements ConsoleInput {
|
||||
/* (non-Javadoc)
|
||||
* @see fr.bigeon.gclc.manager.ConsoleInput#prompt(long) */
|
||||
@Override
|
||||
public String prompt(long timeout) throws IOException {
|
||||
public String prompt(final long timeout) throws IOException {
|
||||
return prompt(prompt.apply(), timeout);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see fr.bigeon.gclc.manager.ConsoleInput#prompt(java.lang.String) */
|
||||
@Override
|
||||
public String prompt(String message) throws IOException {
|
||||
public String prompt(final String message) throws IOException {
|
||||
synchronized (promptLock) {
|
||||
prompting = true;
|
||||
}
|
||||
while (prompting) {
|
||||
while (true) {
|
||||
synchronized (promptLock) {
|
||||
if (!prompting) {
|
||||
return null;
|
||||
}
|
||||
if (connected == null) {
|
||||
try {
|
||||
promptLock.wait();
|
||||
@ -178,18 +184,19 @@ public final class ConnectingConsoleInput implements ConsoleInput {
|
||||
disconnection = false;
|
||||
} else if (prompting) {
|
||||
return res;
|
||||
} else {
|
||||
// prompt interrupted, lose the result.
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see fr.bigeon.gclc.manager.ConsoleInput#prompt(java.lang.String, long) */
|
||||
@Override
|
||||
public String prompt(String message, long timeout) throws IOException {
|
||||
public String prompt(final String message, final long timeout) throws IOException {
|
||||
if (timeout <= 0) {
|
||||
return prompt(message);
|
||||
}
|
||||
@ -197,8 +204,11 @@ public final class ConnectingConsoleInput implements ConsoleInput {
|
||||
synchronized (promptLock) {
|
||||
prompting = true;
|
||||
}
|
||||
while (prompting) {
|
||||
while (true) {
|
||||
synchronized (promptLock) {
|
||||
if (!prompting) {
|
||||
return null;
|
||||
}
|
||||
if (connected == null) {
|
||||
try {
|
||||
promptLock.wait();
|
||||
@ -214,12 +224,13 @@ public final class ConnectingConsoleInput implements ConsoleInput {
|
||||
disconnection = false;
|
||||
} else if (prompting) {
|
||||
return res;
|
||||
} else {
|
||||
// prompt interrupted, lose the result.
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
@ -238,7 +249,7 @@ public final class ConnectingConsoleInput implements ConsoleInput {
|
||||
* @see fr.bigeon.gclc.manager.ConsoleInput#setPrompt(fr.bigeon.gclc.tools.
|
||||
* StringProvider) */
|
||||
@Override
|
||||
public void setPrompt(StringProvider string) {
|
||||
public void setPrompt(final StringProvider string) {
|
||||
prompt = string;
|
||||
}
|
||||
}
|
||||
|
@ -132,8 +132,10 @@ public final class HistoryTextKeyListener extends KeyAdapter {
|
||||
// Lower arrow retrieves next commands
|
||||
if (keyCode == SWT.ARROW_DOWN) {
|
||||
if (currentIndex <= 0) {
|
||||
currentIndex=-1;
|
||||
console.setInput(EMPTY);
|
||||
if (currentIndex == 0) {
|
||||
console.setInput(EMPTY);
|
||||
}
|
||||
currentIndex = -1;
|
||||
} else {
|
||||
final String cmd = commands.get(commands.size() - (--currentIndex) - 1);
|
||||
console.setInput(cmd);
|
||||
|
Loading…
Reference in New Issue
Block a user