diff options
Diffstat (limited to 'src')
-rwxr-xr-x | src/Ivy.java | 38 | ||||
-rwxr-xr-x | src/IvyWatcher.java | 8 | ||||
-rw-r--r-- | src/SelfIvyClient.java | 12 |
3 files changed, 31 insertions, 27 deletions
diff --git a/src/Ivy.java b/src/Ivy.java index 4c6f8ff..1fa812d 100755 --- a/src/Ivy.java +++ b/src/Ivy.java @@ -15,6 +15,8 @@ *</pre> * * CHANGELOG: + * 1.2.17b + * - sets the bufferSize for both outbound *and* inbound connexions, fixes performance issues * 1.2.16 * - uses a ThreadPoolExecutor * - sendMsg goes synchronized @@ -131,22 +133,23 @@ */ package fr.dgac.ivy; -import java.net.*; -import java.io.*; import gnu.getopt.Getopt; -import java.util.regex.*; -import java.util.Vector; -import java.util.Collections; +import java.io.*; +import java.net.*; +import java.util.ArrayList; import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; 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.concurrent.Executors; +import java.util.Vector; import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; import java.util.concurrent.RejectedExecutionException; +import java.util.concurrent.atomic.AtomicLong; +import java.util.regex.*; public class Ivy implements Runnable { @@ -162,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.17"; + private static final String LIBVERSION ="1.2.17b"; /* * private fields @@ -201,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 long current = System.currentTimeMillis(); - private static java.util.Random generator = new java.util.Random(current*(serial + 1)); + private static AtomicLong current = new AtomicLong(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; @@ -223,6 +226,7 @@ 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 = @@ -483,7 +487,7 @@ public class Ivy implements Runnable { * * since 1.2.16 goes synchronized to avoid concurrent access */ - synchronized public final int sendMsg(final String message) throws IvyException { + public final int sendMsg(final String message) throws IvyException { int count = 0; waitForRemote("sending"); synchronized (lock) { @@ -816,7 +820,7 @@ public class Ivy implements Runnable { return "bus <"+appName+">[port:"+applicationPort+",serial:"+myserial+"]"; } - private synchronized long nextId() { return current++; } + private synchronized long nextId() { return current.incrementAndGet(); } /////////////////////////////////////////////////////////////////: // @@ -828,6 +832,8 @@ 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); @@ -840,7 +846,7 @@ public class Ivy implements Runnable { } - protected synchronized void removeClient(IvyClient c) { + protected void removeClient(IvyClient c) { synchronized(lock) { synchronized (clients) { clients.remove(c.getClientKey()); @@ -849,7 +855,7 @@ public class Ivy implements Runnable { } } - protected synchronized void handShake(IvyClient c) { + protected void handShake(IvyClient c) { synchronized(lock) { removeHalf(c); if (clients == null||c == null) return; @@ -936,7 +942,7 @@ public class Ivy implements Runnable { String getReadyMessage() { return ready_message; } boolean getProtectNewlines() { return doProtectNewlines; } String getWatcherId() { return watcherId; } - int getBufferSize() { return bufferSize; } + private int getBufferSize() { return bufferSize; } int getSerial() { return myserial; } ExecutorService getPool() { return pool; } diff --git a/src/IvyWatcher.java b/src/IvyWatcher.java index c9a661f..b95af97 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("Ignoring bad format broadcast from "+ remotehostname+":"+packet.getPort()); + System.err.println("nomatch - Ignoring bad format broadcast from "+ remotehostname+":"+packet.getPort()+" ["+msg+"]"); return true; } // is it the correct protocol version ? int version = Integer.parseInt(m.group(1)); if ( version < Protocol.PROTOCOLMINIMUM ) { - System.err.println("Ignoring bad format broadcast from "+ + System.err.println("too old - Ignoring bad format broadcast from "+ remotehostname+":"+packet.getPort() +" protocol version "+remotehost+" we need "+Protocol.PROTOCOLMINIMUM+" minimum"); return true; @@ -242,8 +242,6 @@ 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"); @@ -252,7 +250,7 @@ class IvyWatcher implements Runnable { traceDebug("there is already a request originating from " + remotehost + ":" + remotePort); } } catch (NumberFormatException nfe) { - System.err.println("Ignoring bad format broadcast from "+remotehostname); + System.err.println("nfe: 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 2751c92..fbf4927 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.intValue(); + return key; } 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().intValue()); + bus.unBindMsg(me.getKey()); } catch (IvyException ie) { return false; } @@ -101,7 +101,7 @@ public class SelfIvyClient extends IvyClient { return false; } - protected int sendSelfMsg(String message) { + protected synchronized 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.intValue()+", it must have been unsubscribed concurrently"); + traceDebug("Not regexp matching id "+key+", it must have been unsubscribed concurrently"); return; // DONE check that nasty synchro issue, test suite: Request } |