aboutsummaryrefslogtreecommitdiff
path: root/src/Probe.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/Probe.java')
-rw-r--r--src/Probe.java34
1 files changed, 18 insertions, 16 deletions
diff --git a/src/Probe.java b/src/Probe.java
index f362b38..a3816f6 100644
--- a/src/Probe.java
+++ b/src/Probe.java
@@ -9,6 +9,8 @@
* Changelog:
* 1.2.16
* - now uses the synchronized wrappers of the Java API for all collections
+ * - gets read of Thread mumbo jumbo, and no more System.exit() on die, we
+ * prefer System.in.close() !
* 1.2.14
* - uses the "new" for: loop construct of Java5
* - throws RuntimeException instead of System.exit(), allows code reuse
@@ -67,7 +69,7 @@ import java.util.*;
import gnu.getopt.Getopt;
import java.util.regex.*;
-public class Probe implements IvyApplicationListener, IvyMessageListener, IvyBindListener, Runnable {
+public class Probe implements IvyApplicationListener, IvyMessageListener, IvyBindListener {
public static final String helpCommands = "Available commands:\n"+
".die CLIENT\t\t\t* sends a die message\n"+
@@ -146,7 +148,6 @@ public class Probe implements IvyApplicationListener, IvyMessageListener, IvyBin
}
private BufferedReader in;
- private volatile Thread looperThread;
private Ivy bus;
private boolean timestamp,quiet,debug,exitOnDie=false, encore=true;
private static Pattern directMsgRE, timeCountRE;
@@ -169,25 +170,18 @@ public class Probe implements IvyApplicationListener, IvyMessageListener, IvyBin
this.debug = debug;
}
- public void start(Ivy bus) throws IvyException {
- if (looperThread!=null) throw new IvyException("Probe already started");
- this.bus=bus;
- bus.addApplicationListener(this);
- looperThread=new Thread(this);
- looperThread.setName("Ivy Probe looper thread on readline");
- looperThread.start();
- }
public void setExitOnDie(boolean b) { exitOnDie=b; }
- public void run() {
- traceDebug("Probe Thread started");
- Thread thisThread=Thread.currentThread();
+ public void start(Ivy bus) throws IvyException {
+ this.bus=bus;
+ bus.addApplicationListener(this);
+ traceDebug("Probe Loop started");
String s;
SelfIvyClient sic = bus.getSelfIvyClient();
println(sic.getApplicationName()+ " ready, type .help and return to get help");
// "infinite" loop on keyboard input
- while (encore && looperThread==thisThread) {
+ while ( encore ) {
try {
s=in.readLine();
if (s==null) break;
@@ -202,7 +196,7 @@ public class Probe implements IvyApplicationListener, IvyMessageListener, IvyBin
}
println("End of input. Good bye !");
bus.stop();
- traceDebug("Probe Thread stopped");
+ traceDebug("Probe Loop stopped");
}
boolean parseCommand(String s) throws IOException {
@@ -351,7 +345,15 @@ public class Probe implements IvyApplicationListener, IvyMessageListener, IvyBin
public void die(IvyClient client, int id,String msgarg) {
println("received die msg from " + client.getApplicationName() +" with the message: "+msgarg+", good bye");
/* I cannot stop the readLine(), because it is native code ?! */
- if (exitOnDie) System.exit(0);
+ if (exitOnDie) {
+ encore = false;
+ try {
+ System.in.close();
+ } catch (IOException ie) {
+ // perfect !
+ }
+ //System.exit(0);
+ }
}
public void directMessage(IvyClient client, int id, String arg) {