aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjestin2016-02-24 20:39:43 +0000
committerjestin2016-02-24 20:39:43 +0000
commit97f906eb738bab2ab4467a59fba09fc6b3454587 (patch)
tree0ab2e7f15d84592d5ae33a26b864f452deca7ce0
parent1e03020739271f2b6a37ca7010d42d1d4499330a (diff)
downloadivy-java-97f906eb738bab2ab4467a59fba09fc6b3454587.zip
ivy-java-97f906eb738bab2ab4467a59fba09fc6b3454587.tar.gz
ivy-java-97f906eb738bab2ab4467a59fba09fc6b3454587.tar.bz2
ivy-java-97f906eb738bab2ab4467a59fba09fc6b3454587.tar.xz
Integrates G. Alliger's fix ! Kudos to him
Add ignore ipv6
-rw-r--r--build.xml6
-rwxr-xr-xsrc/Ivy.java48
-rwxr-xr-xsrc/IvyWatcher.java8
-rw-r--r--src/SelfIvyClient.java12
-rw-r--r--tests/Makefile2
-rw-r--r--tests/Request.java4
6 files changed, 41 insertions, 39 deletions
diff --git a/build.xml b/build.xml
index 908297c..b75b4de 100644
--- a/build.xml
+++ b/build.xml
@@ -1,7 +1,7 @@
<project name="ivy-java" basedir="." default="main">
- <property name="version" value="1.2.17"/>
- <property name="defaultbus" value="-DIVYBUS=224.5.6.7:8910" />
+ <property name="version" value="1.2.18"/>
+ <property name="defaultbus" value="-DIVYBUS=224:2010" />
<property name="src.dir" value="src"/>
<property name="testsrc.dir" value="tests"/>
@@ -78,7 +78,7 @@
<zips><fileset dir="lib" includes="**/java-getopt-1.0.13.jar"/></zips>
</archives>
<fileset dir="." includes="README,COPYING.LIB,BUGS,Changelog"/>
- <fileset dir="src" includes="**/*.java"/>
+ <!-- <fileset dir="src" includes="**/*.java"/> -->
</jar>
</target>
diff --git a/src/Ivy.java b/src/Ivy.java
index 1fa812d..c127449 100755
--- a/src/Ivy.java
+++ b/src/Ivy.java
@@ -15,8 +15,9 @@
*</pre>
*
* CHANGELOG:
- * 1.2.17b
- * - sets the bufferSize for both outbound *and* inbound connexions, fixes performance issues
+ * 1.2.18
+ * - patch G.Alligier, it all passes lotsa tests !
+ * - disable ipv6 (because you know ...)
* 1.2.16
* - uses a ThreadPoolExecutor
* - sendMsg goes synchronized
@@ -133,23 +134,22 @@
*/
package fr.dgac.ivy;
-import gnu.getopt.Getopt;
-import java.io.*;
import java.net.*;
-import java.util.ArrayList;
-import java.util.Collection;
+import java.io.*;
+import gnu.getopt.Getopt;
+import java.util.regex.*;
+import java.util.Vector;
import java.util.Collections;
-import java.util.HashMap;
+import java.util.Collection;
import java.util.List;
import java.util.Map;
+import java.util.HashMap;
+import java.util.ArrayList;
import java.util.Properties;
import java.util.StringTokenizer;
-import java.util.Vector;
-import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
+import java.util.concurrent.ExecutorService;
import java.util.concurrent.RejectedExecutionException;
-import java.util.concurrent.atomic.AtomicLong;
-import java.util.regex.*;
public class Ivy implements Runnable {
@@ -165,7 +165,7 @@ public class Ivy implements Runnable {
* the library version, useful for development purposes only, when java is
* invoked with -DIVY_DEBUG
*/
- private static final String LIBVERSION ="1.2.17b";
+ private static final String LIBVERSION ="1.2.18~pre1";
/*
* private fields
@@ -204,8 +204,8 @@ public class Ivy implements Runnable {
// FIXME should not be static ? (findbugs)
private static int serial = 0;
private int myserial = serial++;
- private static AtomicLong current = new AtomicLong(System.currentTimeMillis());
- private static java.util.Random generator;// = new java.util.Random(current*(serial + 1));
+ private static long current = System.currentTimeMillis();
+ private static java.util.Random generator = new java.util.Random(current*(serial + 1));
private String watcherId = null;
private static Pattern rangeRE; // tcp range min and max
private static Pattern bounded;
@@ -226,7 +226,6 @@ public class Ivy implements Runnable {
* disconnections, (may be null for most agents)
*/
public Ivy(final String name, final String message, final IvyApplicationListener appcb) {
- generator = new java.util.Random(current.get() * (serial + 1));
appName = name;
ready_message = (message == null) ? name + " READY" : message;
debug =
@@ -327,9 +326,11 @@ public class Ivy implements Runnable {
/**
* connects the Ivy bus to a domain or list of domains.
*
+ * <ul>
* <li>One thread (IvyWatcher) for each traffic rendezvous (either UDP broadcast or TCPMulticast)
* <li>One thread (serverThread/Ivy) to accept incoming connexions on server socket
* <li>a thread for each IvyClient when the connexion has been done
+ * </ul>
* @throws IvyException if there is a problem joining the bus
* @param domainbus a domain of the form 10.0.0:1234, A good practice is to
* sick to a null value, so that your agent will honor the IVY_BUS parameter
@@ -346,6 +347,7 @@ public class Ivy implements Runnable {
public final void start(final String domainbus) throws IvyException {
if (!stopped) throw new IvyException("cannot start a bus that's already started");
+ System.setProperty("java.net.preferIPv4Stack" , "true");
pool = Executors.newCachedThreadPool();
stopped=false;
String db = domainbus;
@@ -487,7 +489,7 @@ public class Ivy implements Runnable {
*
* since 1.2.16 goes synchronized to avoid concurrent access
*/
- public final int sendMsg(final String message) throws IvyException {
+ synchronized public final int sendMsg(final String message) throws IvyException {
int count = 0;
waitForRemote("sending");
synchronized (lock) {
@@ -820,7 +822,7 @@ public class Ivy implements Runnable {
return "bus <"+appName+">[port:"+applicationPort+",serial:"+myserial+"]";
}
- private synchronized long nextId() { return current.incrementAndGet(); }
+ private synchronized long nextId() { return current++; }
/////////////////////////////////////////////////////////////////:
//
@@ -832,8 +834,6 @@ public class Ivy implements Runnable {
* @return false if the client has not been created, true otherwise
*/
protected boolean createIvyClient(Socket s , int port, boolean domachin) throws IOException {
- s.setReceiveBufferSize(getBufferSize());
- s.setTcpNoDelay(true);
IvyClient i = new IvyClient(this , s , port , domachin);
try {
pool.execute(i);
@@ -846,7 +846,7 @@ public class Ivy implements Runnable {
}
- protected void removeClient(IvyClient c) {
+ protected synchronized void removeClient(IvyClient c) {
synchronized(lock) {
synchronized (clients) {
clients.remove(c.getClientKey());
@@ -855,7 +855,7 @@ public class Ivy implements Runnable {
}
}
- protected void handShake(IvyClient c) {
+ protected synchronized void handShake(IvyClient c) {
synchronized(lock) {
removeHalf(c);
if (clients == null||c == null) return;
@@ -942,20 +942,20 @@ public class Ivy implements Runnable {
String getReadyMessage() { return ready_message; }
boolean getProtectNewlines() { return doProtectNewlines; }
String getWatcherId() { return watcherId; }
- private int getBufferSize() { return bufferSize; }
+ int getBufferSize() { return bufferSize; }
int getSerial() { return myserial; }
ExecutorService getPool() { return pool; }
protected void pushThread(String reason) {
synchronized(readyToSend) {
- nbThreads++ ;
+ // nbThreads++ ;
//System.out.println("DEBUG PUSH "+this+" -- threads: "+nbThreads + "; reason: "+reason);
}
}
protected void popThread(String reason) {
synchronized(readyToSend) {
- nbThreads-- ;
+ // nbThreads-- ;
//System.out.println("DEBUG POP "+this+" -- threads: "+nbThreads + "reason: "+reason);
}
}
diff --git a/src/IvyWatcher.java b/src/IvyWatcher.java
index b95af97..c9a661f 100755
--- a/src/IvyWatcher.java
+++ b/src/IvyWatcher.java
@@ -190,13 +190,13 @@ class IvyWatcher implements Runnable {
Matcher m = recoucou.matcher(msg);
// is it a correct broadcast packet ?
if (!m.matches()) {
- System.err.println("nomatch - Ignoring bad format broadcast from "+ remotehostname+":"+packet.getPort()+" ["+msg+"]");
+ System.err.println("Ignoring bad format broadcast from "+ remotehostname+":"+packet.getPort());
return true;
}
// is it the correct protocol version ?
int version = Integer.parseInt(m.group(1));
if ( version < Protocol.PROTOCOLMINIMUM ) {
- System.err.println("too old - Ignoring bad format broadcast from "+
+ System.err.println("Ignoring bad format broadcast from "+
remotehostname+":"+packet.getPort()
+" protocol version "+remotehost+" we need "+Protocol.PROTOCOLMINIMUM+" minimum");
return true;
@@ -242,6 +242,8 @@ class IvyWatcher implements Runnable {
traceDebug("no known agent originating from " + remotehost + ":" + remotePort);
try {
Socket s = new Socket(remotehost,remotePort);
+ s.setReceiveBufferSize(bus.getBufferSize());
+ s.setTcpNoDelay(true);
if (!bus.createIvyClient(s,remotePort,false)) return false ;
} catch ( java.net.ConnectException jnc ) {
traceDebug("cannot connect to "+remotehostname+":"+remotePort+", he probably stopped his bus");
@@ -250,7 +252,7 @@ class IvyWatcher implements Runnable {
traceDebug("there is already a request originating from " + remotehost + ":" + remotePort);
}
} catch (NumberFormatException nfe) {
- System.err.println("nfe: Ignoring bad format broadcast from "+remotehostname);
+ System.err.println("Ignoring bad format broadcast from "+remotehostname);
return true;
} catch ( UnknownHostException e ) {
System.err.println("Unkonwn host "+remotehost +","+e.getMessage());
diff --git a/src/SelfIvyClient.java b/src/SelfIvyClient.java
index fbf4927..2751c92 100644
--- a/src/SelfIvyClient.java
+++ b/src/SelfIvyClient.java
@@ -65,7 +65,7 @@ public class SelfIvyClient extends IvyClient {
synchronized (threadedFlag) {
threadedFlag.put(key,type); // use autoboxing of boolean
}
- return key;
+ return key.intValue();
} catch (PatternSyntaxException ree) {
throw new IvyException("Invalid regexp " + sregexp);
}
@@ -73,14 +73,14 @@ public class SelfIvyClient extends IvyClient {
protected synchronized void unBindMsg(int id) throws IvyException {
Integer key = id;
- /*synchronized (regexps) { synchronized (callbacks) { synchronized (threadedFlag) {*/
+ synchronized (regexps) { synchronized (callbacks) { synchronized (threadedFlag) {
if ( ( regexps.remove(key) == null )
|| (regexpsText.remove(key) == null )
|| (callbacks.remove(key) == null )
|| (threadedFlag.remove(key) == null )
)
throw new IvyException("client wants to remove an unexistant regexp "+id);
- /*} } }*/
+ } } }
}
// unbinds to the first regexp
@@ -90,7 +90,7 @@ public class SelfIvyClient extends IvyClient {
for (Map.Entry<Integer,String> me : regexpsText.entrySet()) {
if ( me.getValue().equals(re) ) {
try {
- bus.unBindMsg(me.getKey());
+ bus.unBindMsg(me.getKey().intValue());
} catch (IvyException ie) {
return false;
}
@@ -101,7 +101,7 @@ public class SelfIvyClient extends IvyClient {
return false;
}
- protected synchronized int sendSelfMsg(String message) {
+ protected int sendSelfMsg(String message) {
int count = 0;
traceDebug("trying to send to self the message <"+message+">");
for (Integer key : regexps.keySet() ) {
@@ -128,7 +128,7 @@ public class SelfIvyClient extends IvyClient {
callback=callbacks.get(key);
}
if (callback==null) {
- traceDebug("Not regexp matching id "+key+", it must have been unsubscribed concurrently");
+ traceDebug("Not regexp matching id "+key.intValue()+", it must have been unsubscribed concurrently");
return;
// DONE check that nasty synchro issue, test suite: Request
}
diff --git a/tests/Makefile b/tests/Makefile
index d7dd85b..41218f8 100644
--- a/tests/Makefile
+++ b/tests/Makefile
@@ -4,7 +4,7 @@
include ../java.mk # in this file you can change your java compiler and VM
IVYPATH=../build/jar/ivy-java.jar
-CLASSPATH=-classpath ../build/testclasses:$(IVYPATH):$(GNUPATH)
+CLASSPATH=-classpath classes:$(IVYPATH):$(GNUPATH)
SRC = *.java
# Warning TestNetSwing.java cant build with jdk1.1
diff --git a/tests/Request.java b/tests/Request.java
index 67c3096..73aea54 100644
--- a/tests/Request.java
+++ b/tests/Request.java
@@ -32,13 +32,13 @@ class Request {
id=bus.getWBUId();
bus.bindMsg("^Computer\\d ready",new IvyMessageListener() {
public void receive(IvyClient ic,String[] args) {
- try { bus.sendMsg("computesum id="+id+" a=3 b=4");} catch (IvyException _ ) { }
+ try { bus.sendMsg("computesum id="+id+" a=3 b=4");} catch (IvyException ie ) { }
}
});
bus.bindMsgOnce("^result id="+id+" value=([0-9]+)",new IvyMessageListener() {
public void receive(IvyClient ic,String[] args) {
System.out.println("result received: "+args[0]);
- try {Thread.sleep(1000);} catch (InterruptedException _) { }
+ try {Thread.sleep(1000);} catch (InterruptedException ie) { }
System.exit(0);
}
});