object RequestHandler.handleNHopRequest(Message req, out Address destination, out Message replicationMsg) { destination = null; replicationMsg = null; if (req == null || req.Length == 0) return null; try { bool isLocalReq = LocalAddress.CompareTo(req.Src) == 0; object body = req.getFlatObject(); try { if (body is Byte[]) body = CompactBinaryFormatter.FromByteBuffer((byte[])body, _context.SerializationContext); } catch (Exception e) { return e; } object result = null; if (body is Function) { Function func = (Function)body; func.UserPayload = req.Payload; if (isLocalReq && func.ExcludeSelf) { if (req.HandledAysnc && req.RequestId > 0) SendResponse(req.Src, null, req.RequestId); return null; } if (req.HandledAysnc) { AsyncRequst asyncReq = new AsyncRequst(func, func.SyncKey); asyncReq.Src = req.Src; asyncReq.RequsetId = req.RequestId; _asynHandler.HandleRequest(asyncReq); return null; } else { result = handleFunction(req.Src, func, out destination, out replicationMsg); } } else if (body is AggregateFunction) { AggregateFunction funcs = (AggregateFunction)body; object[] results = new object[funcs.Functions.Length]; for (int i = 0; i < results.Length; i++) { Function func = (Function)funcs.Functions.GetValue(i); if (isLocalReq && func.ExcludeSelf) { if (req.HandledAysnc && req.RequestId > 0) { SendResponse(req.Src, null, req.RequestId); continue; } results[i] = null; } else { if (req.HandledAysnc) { AsyncRequst asyncReq = new AsyncRequst(func, func.SyncKey); asyncReq.Src = req.Src; asyncReq.RequsetId = req.RequestId; _asynHandler.HandleRequest(asyncReq); continue; } results[i] = handleFunction(req.Src, func); } } result = results; } if (result is OperationResponse) { ((OperationResponse)result).SerializablePayload = CompactBinaryFormatter.ToByteBuffer(((OperationResponse)result).SerializablePayload, _context.SerializationContext); } else { result = CompactBinaryFormatter.ToByteBuffer(result, _context.SerializationContext); } return result; } catch (Exception e) { return e; } return null; }
/* ---------------------- Interface RspCollector -------------------------- */ /// <summary> <b>Callback</b> (called by RequestCorrelator or Transport). /// Adds a response to the response table. When all responses have been received, /// <code>execute()</code> returns. /// </summary> public virtual void receiveResponse(Message m) { Address sender = m.Src, mbr; object val = null; if (_done) { NCacheLog.Warn("GroupRequest.receiveResponse()", "command is done; cannot add response !"); return; } if (suspects != null && suspects.Count > 0 && suspects.Contains(sender)) { NCacheLog.Warn("GroupRequest.receiveResponse()", "received response from suspected member " + sender + "; discarding"); return; } if (m.Length > 0) { try { if (m.responseExpected) { OperationResponse opRes = new OperationResponse(); opRes.SerializablePayload = m.getFlatObject(); opRes.UserPayload = m.Payload; val = opRes; } else { val = m.getFlatObject(); } } catch (System.Exception e) { NCacheLog.Error("GroupRequest.receiveResponse()", "exception=" + e.Message); } } lock (rsp_mutex) { bool isMainMember = false; for (int i = 0; i < membership.Length; i++) { mbr = membership[i]; if (mbr.Equals(sender)) { isMainMember = true; if (received[i] == NOT_RECEIVED) { responses[i] = val; received[i] = RECEIVED; if (NCacheLog.IsInfoEnabled) NCacheLog.Info("GroupRequest.receiveResponse()", "received response for request " + req_id + ", sender=" + sender + ", val=" + val); System.Threading.Monitor.PulseAll(rsp_mutex); // wakes up execute() break; } } } if (!isMainMember) { receivedFromNHops[sender] = RECEIVED; System.Threading.Monitor.PulseAll(rsp_mutex); } } }