internal static void OnResponse(ResponseInfo ri) { // maybe this blows up if return type is void or maybe it returns null? object rv = Json.FromJson(ri.ReturnValue, ri.ReturnType); InvokeMethod(ri.Callback, "OnSuccess", ri.ReturnType, rv); }
internal static void OnChunkedResponse(ResponseInfo ri) { if(ri.IsFirstChunk) { InvokeMethod(ri.Callback, "OnStart", typeof(int), ri.TotalItemCount); } OnResponse(ri); if(ri.IsResponseComplete) { InvokeMethod(ri.Callback, "OnFinish", typeof(void), null); } }
internal static void OnException(ResponseInfo ri) { Exception e = new Exception(ri.ReturnValue); InvokeMethod(ri.Callback, "OnException", e.GetType(), e); }
/// <summary> /// Unpack the message /// </summary> private ResponseInfo Unpack(IMapMessage m) { ResponseInfo ri = new ResponseInfo(); ri.CorrelationId = m.NMSCorrelationID; ri.SessionId = m.Body.GetString(ProtocolParams.SessionId); ri.IsBroadcast = m.Body.GetBool(ProtocolParams.IsBroadcast); ri.ReturnValue = m.Body.GetString(ProtocolParams.ReturnValue); ri.IsException = m.Body.GetBool(ProtocolParams.IsException); ri.IsChunked = m.Body.GetBool(ProtocolParams.IsChunked); ri.IsResponseComplete = m.Body.GetBool(ProtocolParams.IsResponseComplete); if(ri.IsChunked) { ri.IsFirstChunk = m.Body.GetBool(ProtocolParams.IsFirstChunk); } if(ri.IsFirstChunk) { ri.TotalItemCount = m.Body.GetInt(ProtocolParams.TotalItemCount); } return ri; }
/// <summary> /// Discard the response if it's not a broadcast msg and sessionId is not ours. /// </summary> private bool ShouldDiscardResponse(ResponseInfo ri) { if(ri.IsBroadcast) { return false; } Preconditions.NotNull(ri.SessionId,"Reply msg did not have sessionId"); return ri.SessionId != this.SessionId; }
private void RmCallback(ResponseInfo ri) { if(!callbackDict.ContainsKey(ri.CorrelationId)) { return; } callbackDict.Remove(ri.CorrelationId); }
private void HandleResponse(ResponseInfo ri) { ResponseDelegate del = ResponseHandler.OnResponse; this.ThreadStrategy.Exec(del, ri); }
/// <summary> /// Invoke the callback's OnException /// </summary> private void HandleException(ResponseInfo ri) { ExceptionDelegate del = ResponseHandler.OnException; this.ThreadStrategy.Exec(del, ri); }