aboutsummaryrefslogtreecommitdiff
path: root/src/IvyClient.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/IvyClient.java')
-rwxr-xr-xsrc/IvyClient.java80
1 files changed, 46 insertions, 34 deletions
diff --git a/src/IvyClient.java b/src/IvyClient.java
index ba30d74..8cd330e 100755
--- a/src/IvyClient.java
+++ b/src/IvyClient.java
@@ -1,15 +1,6 @@
-package fr.dgac.ivy ;
-
-import java.lang.Thread;
-import java.net.*;
-import java.io.*;
-import java.util.*;
-import gnu.regexp.*;
-
/**
* A private Class for the the peers on the bus.
*
- * @author François-Régis Colin
* @author Yannick Jestin
* @author <a href="http://www.tls.cena.fr/products/ivy/">http://www.tls.cena.fr/products/ivy/</a>
*
@@ -19,6 +10,9 @@ import gnu.regexp.*;
* created for each remote client.
*
* CHANGELOG:
+ * 1.2.3:
+ * - direct Messages
+ * - deals with early stops during readline
* 1.2.2:
* - cleared a bug causing the CPU to be eating when a remote client left the
* bus. closes Damien Figarol bug reported on december, 2002. It is handled
@@ -38,6 +32,12 @@ import gnu.regexp.*;
* 1.0.10:
* - removed the timeout bug eating all the CPU resources
*/
+package fr.dgac.ivy ;
+import java.lang.Thread;
+import java.net.*;
+import java.io.*;
+import java.util.*;
+import gnu.regexp.*;
public class IvyClient implements Runnable {
@@ -134,6 +134,27 @@ public class IvyClient implements Runnable {
public void delRegexp(int id) {send( DelRegexp,id,"");}
/**
+ * sends a direct message to the peer
+ * @param id the numeric value provided to the remote client
+ * @param message the string that will be match-tested
+ */
+ public void sendDirectMsg(int id,String message) { send(DirectMsg,id,message); }
+
+ /**
+ * closes the connexion to the peer.
+ * @param notify should I send Bye message ?
+ * the thread managing the socket is stopped
+ */
+ void close(boolean notify) throws IOException {
+ traceDebug("closing connexion to "+appName);
+ if (doping&&(pinger!=null)) { pinger.stopPinging(); }
+ if (notify) sendBye("hasta la vista");
+ stopListening();
+ // bus.clientDisconnect(this);
+ socket.close(); // should I also close in and out ?
+ }
+
+ /**
* sends the substrings of a message to the peer for each matching regexp.
* @param message the string that will be match-tested
* @return the number of messages sent to the peer
@@ -152,20 +173,6 @@ public class IvyClient implements Runnable {
return count;
}
- /**
- * closes the connexion to the peer.
- * @param notify should I send Bye message ?
- * the thread managing the socket is stopped
- */
- void close(boolean notify) throws IOException {
- traceDebug("closing connexion to "+appName);
- if (doping&&(pinger!=null)) { pinger.stopPinging(); }
- if (notify) sendBye("hasta la vista");
- stopListening();
- // bus.clientDisconnect(this);
- socket.close(); // should I also close in and out ?
- }
-
void stopListening() {
Thread t = clientThread;
if (t==null) return; // we can be summoned to quit from two path at a time
@@ -189,12 +196,17 @@ public class IvyClient implements Runnable {
*/
public void run() {
Thread thisThread = Thread.currentThread();
- traceDebug("Connected from "+ socket.getInetAddress().getHostName()+ ":"+socket.getPort());
String msg = null;
- // System.out.println("IvyClient Thread started"); // THREADDEBUG
- while ( clientThread==thisThread ) {
+ try {
+ traceDebug("Connected from "+ socket.getInetAddress().getHostName()+ ":"+socket.getPort());
+ } catch (Exception ie) {
+ traceDebug("Interrupted while resolving remote hostname");
+ }
+ traceDebug("Thread started");
+ while (clientThread==thisThread) {
try {
if ((msg=in.readLine()) != null ) {
+ if (clientThread!=thisThread) break; // early stop during readLine()
if (doping && (pingerThread!=null)) pingerThread.interrupt();
newParseMsg(msg);
} else {
@@ -207,12 +219,12 @@ public class IvyClient implements Runnable {
System.out.println("I have been interrupted. I'm about to leave my thread loop");
if (thisThread!=clientThread) break;
} catch (IOException e) {
- if (clientThread!=thisThread) break;
- System.out.println("abnormally Disconnected from "+ socket.getInetAddress().getHostName()+":"+socket.getPort());
+ traceDebug("abnormally Disconnected from "+ socket.getInetAddress().getHostName()+":"+socket.getPort());
+ break;
}
- } // while
+ }
traceDebug("normally Disconnected from "+ appName);
- // System.out.println("IvyClient Thread stopped"); // THREADDEBUG
+ traceDebug("Thread stopped");
}
private void sendBuffer( String buffer ) throws IvyException {
@@ -420,6 +432,7 @@ public class IvyClient implements Runnable {
public String toString() {
return "IvyClient "+bus.appName+":"+appName;
}
+
private void traceDebug(String s){
if (debug) System.out.println("-->IvyClient "+bus.appName+":"+appName+"<-- "+s);
}
@@ -428,7 +441,7 @@ public class IvyClient implements Runnable {
boolean isPinging = false;
public void run() {
isPinging=true;
- // System.out.println("Pinger Thread started"); // THREADDEBUG
+ traceDebug("Pinger Thread started");
while (isPinging) {
try {
Thread.sleep(PINGTIMEOUT);
@@ -436,10 +449,9 @@ public class IvyClient implements Runnable {
} catch (InterruptedException ie) {
}
}
- // System.out.println("Pinger Thread stopped"); // THREADDEBUG
+ traceDebug("Pinger Thread stopped");
}
public void stopPinging() { isPinging=false; pingerThread.interrupt();}
}
-} // class IvyClient
-/* EOF */
+}