diff options
author | Mark Spruiell <mes@zeroc.com> | 2002-04-02 21:04:58 +0000 |
---|---|---|
committer | Mark Spruiell <mes@zeroc.com> | 2002-04-02 21:04:58 +0000 |
commit | 4ac95bb09e676a6a2c9d880b111aa936343d157b (patch) | |
tree | a72b9adacc9ea8b9de4d08b464d8fec8ec487c6a /java/src | |
parent | Fixed incorrect Ice.Ssl property - made it Ice.SSL - in all config files. (diff) | |
download | ice-4ac95bb09e676a6a2c9d880b111aa936343d157b.tar.bz2 ice-4ac95bb09e676a6a2c9d880b111aa936343d157b.tar.xz ice-4ac95bb09e676a6a2c9d880b111aa936343d157b.zip |
align with C++ fixes for finished()
Diffstat (limited to 'java/src')
-rw-r--r-- | java/src/IceInternal/Connection.java | 3 | ||||
-rw-r--r-- | java/src/IceInternal/IncomingConnectionFactory.java | 58 | ||||
-rw-r--r-- | java/src/IceInternal/ThreadPool.java | 188 |
3 files changed, 138 insertions, 111 deletions
diff --git a/java/src/IceInternal/Connection.java b/java/src/IceInternal/Connection.java index 96715d0786a..f8ff8bca835 100644 --- a/java/src/IceInternal/Connection.java +++ b/java/src/IceInternal/Connection.java @@ -611,7 +611,10 @@ public final class Connection extends EventHandler _mutex.lock(); try { + _threadPool.promoteFollower(); + assert(_state == StateClosed); + _transceiver.close(); } finally diff --git a/java/src/IceInternal/IncomingConnectionFactory.java b/java/src/IceInternal/IncomingConnectionFactory.java index b89530a806a..57d03cd283b 100644 --- a/java/src/IceInternal/IncomingConnectionFactory.java +++ b/java/src/IceInternal/IncomingConnectionFactory.java @@ -95,9 +95,10 @@ public class IncomingConnectionFactory extends EventHandler public synchronized void message(BasicStream unused) { + _threadPool.promoteFollower(); + if (_state != StateActive) { - _threadPool.promoteFollower(); Thread.yield(); return; } @@ -149,39 +150,41 @@ public class IncomingConnectionFactory extends EventHandler } setState(StateClosed); } - - _threadPool.promoteFollower(); } public synchronized void finished() { - assert(_state == StateClosed); + _threadPool.promoteFollower(); - java.util.ListIterator iter = _connections.listIterator(); - while (iter.hasNext()) - { - Connection connection = (Connection)iter.next(); - connection.destroy(Connection.ObjectAdapterDeactivated); - } - _connections.clear(); + assert(_state == StateClosed); + assert(_connections.isEmpty()); - // - // Clear listen() backlog properly by accepting all queued - // connections, and then shutting them down. - // - while (true) + try { - try + // + // Clear listen() backlog properly by accepting all queued + // connections, and then shutting them down. + // + while (true) { - Transceiver transceiver = _acceptor.accept(0); - Connection connection = new Connection(_instance, transceiver, _endpoint, _adapter); - connection.exception( - new Ice.ObjectAdapterDeactivatedException()); + try + { + Transceiver transceiver = _acceptor.accept(0); + Connection connection = new Connection(_instance, transceiver, _endpoint, _adapter); + connection.exception(new Ice.ObjectAdapterDeactivatedException()); + } + catch (Ice.TimeoutException ex) + { + break; // Exit loop on timeout. + } } - catch (Exception ex) + } + catch (Ice.LocalException ex) + { + if (_warn) { - break; + warning(ex); } } @@ -337,6 +340,15 @@ public class IncomingConnectionFactory extends EventHandler } _threadPool.unregister(_acceptor.fd(), true); } + + java.util.ListIterator iter = _connections.listIterator(); + while (iter.hasNext()) + { + Connection connection = (Connection)iter.next(); + connection.destroy(Connection.ObjectAdapterDeactivated); + } + _connections.clear(); + break; } } diff --git a/java/src/IceInternal/ThreadPool.java b/java/src/IceInternal/ThreadPool.java index 89912dedbc6..24e6043f586 100644 --- a/java/src/IceInternal/ThreadPool.java +++ b/java/src/IceInternal/ThreadPool.java @@ -449,10 +449,10 @@ catch (RuntimeException ex) nextTimeout = 0; } - else - { +//else +//{ //System.out.println("ThreadPool - still have keys"); - } +//} if (_keysIter == null) { @@ -461,8 +461,9 @@ catch (RuntimeException ex) } EventHandler handler = null; + RemoveInfo remove = null; - synchronized(this) + synchronized (this) { if (_destroyed) { @@ -482,6 +483,7 @@ catch (RuntimeException ex) HandlerInfo info = _adds; while (info != null) { +//System.out.println("ThreadPool - adding fd " + info.fd); int op; if ((info.fd.validOps() & java.nio.channels.SelectionKey.OP_READ) > 0) { @@ -513,122 +515,132 @@ catch (RuntimeException ex) // // Handlers are permanently removed. // - RemoveInfo info = _removes; - while (info != null) + remove = _removes; + _removes = _removes.next; + java.nio.channels.SelectionKey key = remove.fd.keyFor(_selector); + assert(key != null); + HandlerInfo hinfo = (HandlerInfo)key.attachment(); + key.cancel(); + handler = hinfo.handler; +//System.out.println("ThreadPool - remove fd = " + remove.fd); +//if (_removes != null) +// System.out.println("ThreadPool - more fds to be removed"); + } + + if (handler == null) + { + java.nio.channels.SelectionKey key = null; + while (_keysIter.hasNext()) { - java.nio.channels.SelectionKey key = info.fd.keyFor(_selector); - assert(key != null); - HandlerInfo hinfo = (HandlerInfo)key.attachment(); - key.cancel(); - if (info.callFinished) // Call finished() on the handler? - { - hinfo.handler.finished(); - hinfo.handler._stream.destroy(); - } - if (hinfo.handler.server()) + // + // Ignore selection keys that have been cancelled + // + java.nio.channels.SelectionKey k = (java.nio.channels.SelectionKey)_keysIter.next(); + _keysIter.remove(); + if (k.isValid()) { - --_servers; +//System.out.println("ThreadPool - found a key"); + key = k; + break; } - _handlers--; - info = info.next; -//System.out.println("ThreadPool - _handlers = " + _handlers + ", _servers = " + _servers); } - _removes = null; - if (_handlers == 0 || _servers == 0) + if (!_keysIter.hasNext()) { - notifyAll(); // For waitUntil...Finished() methods. + _keysIter = null; +//System.out.println("ThreadPool - reset iterator"); } - // - // Selected filedescriptors may have changed, I - // therefore need to repeat the select(). - // - shutdown = clearInterrupt(); - continue repeatSelect; - } + if (key == null) + { +//System.out.println("ThreadPool - didn't find a valid key"); + continue repeatSelect; + } - java.nio.channels.SelectionKey key = null; - while (_keysIter.hasNext()) - { - // - // Ignore selection keys that have been cancelled - // - java.nio.channels.SelectionKey k = (java.nio.channels.SelectionKey)_keysIter.next(); - _keysIter.remove(); - if (k.isValid()) + if (key.channel() == _fdIntrRead) { -//System.out.println("ThreadPool - found a key"); - key = k; - break; +//System.out.println("ThreadPool - input ready on the interrupt pipe"); + shutdown = clearInterrupt(); + continue repeatSelect; } - } - if (!_keysIter.hasNext()) - { - _keysIter = null; -//System.out.println("ThreadPool - reset iterator"); + HandlerInfo info = (HandlerInfo)key.attachment(); + assert(info != null); + handler = info.handler; } + } - if (key == null) + assert(handler != null); + + if (remove != null) + { + // + // Call finished() on the handler if necessary. + // + if (remove.callFinished) { -//System.out.println("ThreadPool - didn't find a valid key"); - continue repeatSelect; + handler.finished(); + handler._stream.destroy(); } - if (key.channel() == _fdIntrRead) + synchronized (this) { -//System.out.println("ThreadPool - input ready on the interrupt pipe"); - shutdown = clearInterrupt(); - continue repeatSelect; + _handlers--; + if (handler.server()) + { + --_servers; + } +//System.out.println("ThreadPool - _handlers = " + _handlers + ", _servers = " + _servers); + if (_handlers == 0 || _servers == 0) + { + notifyAll(); // For waitUntil...Finished() methods. + } } - - HandlerInfo info = (HandlerInfo)key.attachment(); - assert(info != null); - handler = info.handler; } - - // - // If the handler is "readable", try to read a message. - // - // NOTE: On Win32 platforms, select may report a channel - // as readable although nothing can be read. We want to - // ignore the event in this case. - // - try + else { - if (handler.readable()) + // + // If the handler is "readable", try to read a message. + // + // NOTE: On Win32 platforms, select may report a channel + // as readable although nothing can be read. We want to + // ignore the event in this case. + // + try { - try + if (handler.readable()) { - if (!read(handler)) // No data available. + try { + if (!read(handler)) // No data available. + { //System.out.println("ThreadPool - no input"); + continue repeatSelect; + } + } + catch (Ice.TimeoutException ex) // Expected + { continue repeatSelect; } - } - catch (Ice.TimeoutException ex) // Expected - { - continue repeatSelect; - } - catch (Ice.LocalException ex) - { - handler.exception(ex); - continue repeatSelect; + catch (Ice.LocalException ex) + { + handler.exception(ex); + continue repeatSelect; + } + + stream.swap(handler._stream); + assert(stream.pos() == stream.size()); } - stream.swap(handler._stream); - assert(stream.pos() == stream.size()); + handler.message(stream); + } + finally + { + stream.reset(); } - - handler.message(stream); - } - finally - { - stream.reset(); } - break; + break; // inner while loop } } } |