/// <summary> /// Send requests /// </summary> /// <param name="message">indicating the message</param> void IBrokerFrontend.SendRequest(Message message) { string clientId = FrontEndBase.GetClientId(message, String.Empty); try { ParamCheckUtility.ThrowIfNull(clientId, "clientId"); ParamCheckUtility.ThrowIfTooLong(clientId.Length, "clientId", Constant.MaxClientIdLength, SR.ClientIdTooLong); ParamCheckUtility.ThrowIfNotMatchRegex(ParamCheckUtility.ClientIdValid, clientId, "clientId", SR.InvalidClientId); this.observer.IncomingRequest(); this.GetClient(clientId).RequestReceived(DummyRequestContext.GetInstance(MessageVersion.Default), message, null); } catch (Exception e) { BrokerTracing.TraceEvent(System.Diagnostics.TraceEventType.Error, 0, "[BrokerController] SendRequest {1} Failed: {0}", e, clientId); throw TranslateException(e); } }
/// <summary> /// Check a frontend if throttling is enganged. If so, wait throttling to complete; If it doesn't complete in timeoutThrottlingMs, thow TimeoutException. /// </summary> /// <param name="frontEndBase">the frontend to be checked</param> /// <param name="timeoutThrottlingMs">how long to wait before throttling completes</param> private static void WaitOnThrottling(FrontEndBase frontendBase, int timeoutThrottlingMs) { if (frontendBase == null) { return; } // If throttling is engaged wait for it to complete if (frontendBase.IsThrottlingEngaged) { // First wait on any throttling if it is enabled. Wait for as long as client wants which from .Net clients // is the timeout used when sending requests if (!frontendBase.ThrottlingWaitHandle.WaitOne(TimeSpan.FromMilliseconds(timeoutThrottlingMs), false)) { // If the throttle timeout expires, return a timeout exception throw TranslateException(new TimeoutException(SR.ThrottlingTimeoutExceeded)); } } }
/// <summary> /// Indicate the end of requeusts /// </summary> /// <param name="count">indicating the number of the messages</param> /// <param name="timeoutMs">indicating the timeout in MS</param> /// <param name="clientId">indicating the client id</param> public void EndRequests(int count, string clientId, int batchId, int timeoutThrottlingMs, int timeoutEOMMs) { ParamCheckUtility.ThrowIfOutofRange(count < 0, "count"); ParamCheckUtility.ThrowIfOutofRange(timeoutThrottlingMs <= 0 && timeoutThrottlingMs != Timeout.Infinite, "timeoutThrottlingMs"); ParamCheckUtility.ThrowIfOutofRange(timeoutEOMMs <= 0 && timeoutEOMMs != Timeout.Infinite, "timeoutEOMMs"); ParamCheckUtility.ThrowIfNull(clientId, "clientId"); ParamCheckUtility.ThrowIfTooLong(clientId.Length, "clientId", Constant.MaxClientIdLength, SR.ClientIdTooLong); ParamCheckUtility.ThrowIfNotMatchRegex(ParamCheckUtility.ClientIdValid, clientId, "clientId", SR.InvalidClientId); this.ThrowIfDisposed(); this.CheckAuth(); BrokerTracing.TraceEvent(System.Diagnostics.TraceEventType.Information, 0, "[BrokerController] Receive EOM for Client {0}, Count = {1}", clientId, count); try { #region Debug Failure Test SimulateFailure.FailOperation(1); #endregion BrokerClient brokerClient = this.GetClient(clientId); FrontEndBase frontendBase = brokerClient.GetDuplexFrontEnd(); WaitOnThrottling(frontendBase, timeoutThrottlingMs); // Then handle the EOM which waits until all requests are stored. Use user specified EndRequests timeout for this brokerClient.EndOfMessage(count, batchId, timeoutEOMMs); #region Debug Failure Test SimulateFailure.FailOperation(2); #endregion } catch (Exception e) { BrokerTracing.TraceError("[BrokerController] EOM failed for client {0}: {1}", clientId, e); throw TranslateException(e); } }