internal void SetHandleValue(DataWaitHandle value) { handle = value; if (wrapper == null) { return; } SetHandle(); }
public bool RegisterWaitHandle(Guid uuid, DataWaitHandle handle, ResponseStyle responseStyle) { lock (requests) { if (requests.ContainsKey(uuid)) { requests[uuid].SetHandleValue(handle); requests[uuid].ResponseStyle = responseStyle; } else { requests[uuid] = new RequestData(uuid, handle, responseStyle); } if (!requests[uuid].Set) { return(false); } ProcessRemovals(); return(true); } }
public RequestData(Guid uuid, DataWaitHandle handle, ResponseStyle responseStyle) { Uuid = uuid; SetHandleValue(handle); ResponseStyle = responseStyle; }
public JsonBusResponse PublishAndWaitForResponse <TNeed, TSolution>(Message <TNeed, TSolution> message, ResponseStyle responseStyle = ResponseStyle.WholeSolution, Func <string, bool> solutionMatchFunction = null) { Guid requestId = CreateUniqueId.Invoke(); if (message.Uuid == Guid.Empty) { message.Uuid = requestId; } message.LastModifiedBy = ServiceInfo.Name; message.LastModifiedTime = dateTimeProvider.UtcNow; if (!Methods.Contains(message.Method)) { Methods.Add(message.Method); backplane.Send(new RequestMethodRegistration { Method = message.Method }); } logger.Trace($"{nameof(RequestStore)}.{nameof(PublishAndWaitForTypedResponse)}", new LogItem("Event", "Preparing to publish message"), new LogItem("MessageId", message.Uuid.ToString), new LogItem("MessageMethod", message.Method)); var response = new JsonBusResponse(); using (DataWaitHandle dataWaitHandle = new DataWaitHandle(false, EventResetMode.AutoReset, solutionMatchFunction)) { requestMatcher.RegisterWaitHandle(message.Uuid, dataWaitHandle, responseStyle); queueWrapper.PublishMessage(message, message.Uuid); if (dataWaitHandle.WaitOne(busTimeoutMilliseconds)) { List <ResponseError> errors = null; if (dataWaitHandle.Errors != null) { errors = JsonConvert.DeserializeObject <List <ResponseError> >(dataWaitHandle.Errors); } logger.Trace($"{nameof(RequestStore)}.{nameof(PublishAndWaitForTypedResponse)}", new LogItem("Event", "Published message and received response"), new LogItem("MessageId", message.Uuid.ToString), new LogItem("MessageMethod", message.Method)); if (errors != null && errors.Any()) { response.Errors = dataWaitHandle.Errors; } response.Solution = dataWaitHandle.Solution; } if (string.IsNullOrEmpty(response.Errors) && string.IsNullOrEmpty(response.Solution)) { logger.Trace($"{nameof(RequestStore)}.{nameof(PublishAndWaitForTypedResponse)}", new LogItem("Event", "Published message and received no response"), new LogItem("MessageId", message.Uuid.ToString), new LogItem("MessageMethod", message.Method)); } return(response); } }