protected void MapHandler(object chan, EventArgs args) {
//Get the Map result:
if (LogEnabled) {
ProtocolLog.Write(ProtocolLog.MapReduce,
String.Format("MapReduce: {0}, in MapHandler", _node.Address));
}
object map_res;
Channel map_chan = (Channel)chan;
if( map_chan.Count == 0 ) {
//We must have timed out trying to get the Map result
map_res = new AdrException(-32000, "no map result");
}
else {
map_res = map_chan.Dequeue();
}
if (LogEnabled) {
ProtocolLog.Write(ProtocolLog.MapReduce,
String.Format("MapReduce: {0}, got map result: {1}.", _node.Address, map_res));
}
//The usual transactional bit:
State state = _state;
State old_state;
State new_state;
do {
old_state = state;
new_state = old_state.UpdateMap(map_res);
state = Interlocked.CompareExchange<State>(ref _state, new_state, old_state);
}
while( state != old_state);
//Do the first reduction:
TryNextReduce(new_state, old_state, new RpcResult(null, map_res), false);
}