diff options
author | Benoit Foucher <benoit@zeroc.com> | 2007-08-31 17:01:34 +0200 |
---|---|---|
committer | Benoit Foucher <benoit@zeroc.com> | 2007-08-31 17:01:34 +0200 |
commit | 31efb365dfed25a2fdbe2e38178f7989cbfe00f4 (patch) | |
tree | acf3bb92d51ae74ab897119d9334283db08c66aa /java/src/IceInternal/ConnectionMonitor.java | |
parent | bug 2441 - Do not require IceBoc.ServiceManager.Endpoints to be set (diff) | |
download | ice-31efb365dfed25a2fdbe2e38178f7989cbfe00f4.tar.bz2 ice-31efb365dfed25a2fdbe2e38178f7989cbfe00f4.tar.xz ice-31efb365dfed25a2fdbe2e38178f7989cbfe00f4.zip |
Squashed commit of the following:
commit 1d43f88b9f7f1651ac367b217b10da3c9c5e7400
Author: Benoit Foucher <benoit@zeroc.com>
Date: Fri Aug 31 16:55:20 2007 +0200
Added C# Timer implementation
commit 52c3f88a429f62ed3564ab65c1af1736c2c1d2ee
Author: Benoit Foucher <benoit@zeroc.com>
Date: Fri Aug 31 14:49:18 2007 +0200
Added Java Timer impl.
Diffstat (limited to 'java/src/IceInternal/ConnectionMonitor.java')
-rw-r--r-- | java/src/IceInternal/ConnectionMonitor.java | 151 |
1 files changed, 53 insertions, 98 deletions
diff --git a/java/src/IceInternal/ConnectionMonitor.java b/java/src/IceInternal/ConnectionMonitor.java index de44f64fe71..7f46d20f19b 100644 --- a/java/src/IceInternal/ConnectionMonitor.java +++ b/java/src/IceInternal/ConnectionMonitor.java @@ -9,39 +9,20 @@ package IceInternal; -public final class ConnectionMonitor extends Thread +public final class ConnectionMonitor implements IceInternal.TimerTask { // // Renamed from destroy to _destroy to avoid a deprecation warning caused // by the destroy method inherited from Thread. // - public void - _destroy() + synchronized public void + destroy() { - synchronized(this) - { - assert(_instance != null); - - _instance = null; - _connections = null; - - notify(); - } - - while(true) - { - try - { - join(); - break; - } - catch(java.lang.InterruptedException ex) - { - continue; - } - } + assert(_instance != null); + _instance = null; + _connections = null; } - + public synchronized void add(Ice.ConnectionI connection) { @@ -61,18 +42,10 @@ public final class ConnectionMonitor extends Thread // ConnectionMonitor(Instance instance, int interval) { + assert(interval > 0); _instance = instance; - _interval = interval; - String threadName = _instance.initializationData().properties.getProperty("Ice.ProgramName"); - if(threadName.length() > 0) - { - threadName += "-"; - } - setName(threadName + "Ice.ConnectionMonitor"); - - assert(_interval > 0); - start(); + _instance.timer().scheduleRepeated(this, interval * 1000); } protected synchronized void @@ -90,85 +63,67 @@ public final class ConnectionMonitor extends Thread { java.util.HashSet connections = new java.util.HashSet(); - while(true) + synchronized(this) { - synchronized(this) + if(_instance == null) { - if(_instance != null) - { - try - { - wait(_interval * 1000); - } - catch(InterruptedException ex) - { - continue; - } - } - - if(_instance == null) - { - return; - } - - connections.clear(); - connections.addAll(_connections); + return; } + + connections.clear(); + connections.addAll(_connections); + } - // - // Monitor connections outside the thread synchronization, - // so that connections can be added or removed during - // monitoring. - // - java.util.Iterator iter = connections.iterator(); - while(iter.hasNext()) + // + // Monitor connections outside the thread synchronization, + // so that connections can be added or removed during + // monitoring. + // + java.util.Iterator iter = connections.iterator(); + while(iter.hasNext()) + { + Ice.ConnectionI connection = (Ice.ConnectionI)iter.next(); + + try + { + connection.monitor(); + } + catch(Ice.LocalException ex) { - Ice.ConnectionI connection = (Ice.ConnectionI)iter.next(); - - try - { - connection.monitor(); - } - catch(Ice.LocalException ex) + synchronized(this) { - synchronized(this) + if(_instance == null) { - if(_instance == null) - { - return; - } - - java.io.StringWriter sw = new java.io.StringWriter(); - java.io.PrintWriter pw = new java.io.PrintWriter(sw); - ex.printStackTrace(pw); - pw.flush(); - String s = "exception in connection monitor thread " + getName() + ":\n" + - sw.toString(); - _instance.initializationData().logger.error(s); + return; } + + java.io.StringWriter sw = new java.io.StringWriter(); + java.io.PrintWriter pw = new java.io.PrintWriter(sw); + ex.printStackTrace(pw); + pw.flush(); + String s = "exception in connection monitor:\n" + sw.toString(); + _instance.initializationData().logger.error(s); } - catch(java.lang.Exception ex) + } + catch(java.lang.Exception ex) + { + synchronized(this) { - synchronized(this) + if(_instance == null) { - if(_instance == null) - { - return; - } - java.io.StringWriter sw = new java.io.StringWriter(); - java.io.PrintWriter pw = new java.io.PrintWriter(sw); - ex.printStackTrace(pw); - pw.flush(); - String s = "unknown exception in connection monitor thread " + getName() + ":\n" + - sw.toString(); - _instance.initializationData().logger.error(s); + return; } + java.io.StringWriter sw = new java.io.StringWriter(); + java.io.PrintWriter pw = new java.io.PrintWriter(sw); + ex.printStackTrace(pw); + pw.flush(); + String s = "unknown exception in connection monitor:\n" + sw.toString(); + _instance.initializationData().logger.error(s); } } } } private Instance _instance; - private final int _interval; private java.util.HashSet _connections = new java.util.HashSet(); } |