akka/akka — pull request #1406 by sirthias (2013-05-06 15:19:22+00:00)
Title: IO: Remove SelectionKey lookup and reduce IO-layer-internal message volume

This change looks bigger than it is. Most of it is architectural massaging to achieve the following benefits:

1. Remove HashMap-based lookup of SelectionKeys for a connection in the SelectionHandler. Before the selector needed the lookup to be able to act on Interest-setting messages from the connection actors. Due to point 2 this is not required anymore.
Especially for a large number of concurrently open connections this should prove beneficial.

2. Reduce layer-internal message volume: So far the update of the interest-ops on a connection's SelectionKey required 2 schedulings onto a dispatcher: first the actor message to the selector and second the actual update task onto the selector mgmt dispatcher. By having the connection actors schedule the update task directly we can avoid one message dispatch for every interest-op update.

3. Improve architectural cleanliness: So far the SelectionHandler contained two kinds of logic mixed together in one class: It's own actor logic as well as the logic for the selector mgmt. dispatcher. By separating these two it becomes easier to see what is actually going on on the two sides. Smaller additional benefit: it is now impossible for a connection to try to set interest ops before being registered.

(Note: the first commit doesn't change any test logic, it merely structures the test fixture code a bit differently to make it easier to insert the additional required mocks...)