private static bool Unref(ThrottlingRpcClient client) { if (client.RemoveRef() == 0) { client.Dispose(); return(true); } return(false); }
private void HandleFailure(long failureTime, ThrottlingRpcClient client) { lock (this.syncRoot) { this.failureCount++; this.lastFailureTime = failureTime; if (client != null && this.rpcClient == client) { ThrottlingRpcClientImpl.Unref(this.rpcClient); this.rpcClient = null; } } }
private bool TryGetRpcClient(out ThrottlingRpcClient client) { client = null; lock (this.syncRoot) { if (this.ShouldBypassRpc()) { return(false); } if (this.rpcClient == null) { this.TryCreateRpcClient(); } if (this.rpcClient != null) { client = this.rpcClient; client.AddRef(); } } return(client != null); }
private bool TryCreateRpcClient() { try { ThrottlingRpcClient throttlingRpcClient = new ThrottlingRpcClient(this.serverName); ThrottlingRpcClientImpl.tracer.TraceDebug <string>(0L, "Successfully created a new RPC client for server {0}", this.serverName); throttlingRpcClient.SetTimeOut(5000); ThrottlingRpcClientImpl.tracer.TraceDebug <string>(0L, "Successfully set RPC timeout for server {0}", this.serverName); this.rpcClient = throttlingRpcClient; } catch (RpcException ex) { this.HandleFailure(Stopwatch.GetTimestamp(), null); ThrottlingRpcClientImpl.EventLogger.LogEvent(ThrottlingClientEventLogConstants.Tuple_CreateRpcClientFailure, this.serverName, new object[] { this.serverName, ex.ErrorCode, ex.Message, (ex.InnerException != null) ? ex.InnerException.ToString() : "none" }); ThrottlingRpcClientImpl.tracer.TraceError <string, RpcException>(0L, "RPC exception when creating an RPC client for server {0}: {1}", this.serverName, ex); } return(this.rpcClient != null); }
private void HandleResult(ThrottlingRpcResult rpcResult, long requestStartTime, long requestCompletionTime, ThrottlingRpcClient client) { long msecInterval = ThrottlingRpcClientImpl.GetMsecInterval(requestStartTime, requestCompletionTime); if (rpcResult != ThrottlingRpcResult.Failed && msecInterval <= 5000L) { this.HandleSuccessfulResponse(); } else if (rpcResult != ThrottlingRpcResult.Failed) { ThrottlingRpcClientImpl.tracer.TraceError <string, long>(0L, "RPC request to mailbox server {0} took {1} milliseconds and treated as failed", this.serverName, msecInterval); ThrottlingRpcClientImpl.EventLogger.LogEvent(ThrottlingClientEventLogConstants.Tuple_RpcRequestTimedout, this.serverName, new object[] { this.serverName, msecInterval }); this.HandleFailure(requestCompletionTime, null); } else { this.HandleFailure(requestCompletionTime, client); } ThrottlingRpcClientImpl.Unref(client); this.perfCounters.AddRequestStatus(rpcResult, msecInterval); }