|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectedu.upc.dama.dex.shell.CommandShell
public class CommandShell
Implementantion of the Shell using a new thread. For non interactive usage.
The communication method with the new shell is with pipes executing the commands
one by one using the method runCommand. All the results are writen on the Writer
parameter given when the CommandShell is constructed.
Check the method workToDo to know if the shell is still running any command.
Basic sample:
DEX dex = new DEX();
GraphPool gp = dex.open("pathToDexImage");
Session s = gp.newSession();
DbGraph g = s.getDbGraph();
//Pipes used to get the result of the executions
PipedReader resultsPipeRead = new PipedReader();
PipedWriter resultsPipeWrite = new PipedWriter(resultsPipeRead);
CommandShell shell = new CommandShell(g, resultsPipeWrite);
//New Thread
Thread t = new Thread(shell);
t.start();
//Used to print the results
char[] text = new char[50];
int count;
//Execute command
shell.runCommand("print attributes\n");
//Waiting while the shell is not finished and the result is not printed
while (shell.workToDo() || resultsPipeRead.ready()){
count = resultsPipeRead.read(text);
for (int i = 0; i < count; i++)
System.out.print(text[i]);
}
//To finish the thread of the shell is important end it closing the shell.
shell.close();
| Constructor Summary | |
|---|---|
CommandShell(DbGraph graph,
java.io.Writer writer)
Constructor of the new command shell implemented with a new thread. |
|
| Method Summary | |
|---|---|
void |
close()
Close the shell |
void |
run()
Abstract method for the Runnable interface. |
void |
runCommand(java.lang.String command)
Put a new command to execute on the shell. |
void |
stopCommand()
Stop the execution of the current command. |
boolean |
workToDo()
Getter to know if the shell is busy. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public CommandShell(DbGraph graph,
java.io.Writer writer)
throws java.io.IOException
graph - Graph used for the shell
to execute the commands.writer - Writer used for the shell to write the commands results.
java.io.IOException - If bad things happen during the construction
of the communication with the shell.| Method Detail |
|---|
public boolean workToDo()
True if ther shell is busy executing any command.
public void runCommand(java.lang.String command)
throws java.io.IOException
command - Command to execute
java.io.IOException - If bad things happen writing the command on
the shell reader.public void stopCommand()
public void run()
run in interface java.lang.Runnable
public void close()
throws java.io.IOException
java.io.IOException - If bad things happen during close
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||