summaryrefslogtreecommitdiff
path: root/java/src/IceInternal/ThreadPool.java
diff options
context:
space:
mode:
authorMark Spruiell <mes@zeroc.com>2002-04-02 21:04:58 +0000
committerMark Spruiell <mes@zeroc.com>2002-04-02 21:04:58 +0000
commit4ac95bb09e676a6a2c9d880b111aa936343d157b (patch)
treea72b9adacc9ea8b9de4d08b464d8fec8ec487c6a /java/src/IceInternal/ThreadPool.java
parentFixed incorrect Ice.Ssl property - made it Ice.SSL - in all config files. (diff)
downloadice-4ac95bb09e676a6a2c9d880b111aa936343d157b.tar.bz2
ice-4ac95bb09e676a6a2c9d880b111aa936343d157b.tar.xz
ice-4ac95bb09e676a6a2c9d880b111aa936343d157b.zip
align with C++ fixes for finished()
Diffstat (limited to 'java/src/IceInternal/ThreadPool.java')
-rw-r--r--java/src/IceInternal/ThreadPool.java188
1 files changed, 100 insertions, 88 deletions
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
}
}
}