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