I haven't slept all night but I got some preliminary thinking about how
nio will affect everything. In a nutshell, there's no way to confine
the changes to a single layer. Here's how I see it rolling out:
1. use a single selector for all network reads and have a single thread
do a blocking select() on a single selector.
2. once we have channels available, start a thread for each channel,
deliver the event to the appropriate state (states have to be registered
as event listeners) and process the event in the same thread. do that
in a big do{}while(no new events flag) loop to avoid unnecessary threads.
If a thread is already working on an event for the channel, just set its
no_new_events_flag to false.
3. the main thread should wait for all workers to finish, but not more
than some small timeout, perhaps 5-20 ms. Then repeat.
With this scheme we have only one thread blocked for network reads and
only as many threads active as there are active channels during any
given time-slice. Also, select() is supposed to be thread safe, however
the resulting sets are not thread safe _and_ select() itself locks on
the selector and on the sets (the docs don't say it, but I"m assuming
its a nested lock) so the best bet is to have single thread do the
demultiplexing.
Again, this is all a late-hours speculation, I'm going to purchase Java
NIO (O'Reilly) from the local bookstore today and they may have better
ideas. Or if anyone on the list knows nio very well and can convince me
that this is all B.S., please write to me promptly (before I spend my
money! ;))
_______________________________________________
devl mailing list
devl at freenetproject.org
http://hawk.freenetproject.org:8080/cgi-bin/mailman/listinfo/devl