/// <summary> /// This method is used to /// keep the context alive. /// </summary> /// <param name="ct"></param> /// <param name="nowUtc"></param> public void KeepContextAliveIfNeeded(CancellationToken ct, DateTime nowUtc) { if (!_serverContextIsOperational) { return; } uint timeDiffInMs = (uint)(nowUtc - _resourceManagementLastCallUtc).TotalMilliseconds + 500; if (timeDiffInMs >= KeepAliveIntervalMs) { try { _resourceManagementClient.ClientKeepAlive(new ClientKeepAliveRequest { ContextId = _serverContextId }, cancellationToken: ct); _resourceManagementLastCallUtc = nowUtc; } catch { _serverContextIsOperational = false; _pendingContextNotificationData = new ClientContextNotificationData(ClientContextNotificationType.ClientKeepAliveException, null); } } }
private void ClientContextOnContextNotifyEvent(object sender, ClientContextNotificationData notificationData) { if (_disposed) { return; } switch (notificationData.ReasonForNotification) { case ClientContextNotificationType.ResourceManagementFail: case ClientContextNotificationType.ClientKeepAliveException: case ClientContextNotificationType.Shutdown: case ClientContextNotificationType.ServerKeepAliveError: case ClientContextNotificationType.GeneralException: case ClientContextNotificationType.PollException: case ClientContextNotificationType.ResourceManagementDisconnected: CloseConnectionInternal(); break; } }
/// <summary> /// <para> Re throws. </para> /// <para> /// This method processes an exception thrown when the client application calls one of the methods on the /// IResourceManagment interface. /// </para> /// <para> /// If the exception is a FaultException, the exception is from the server and is rethrown unless the exception /// indicates that the server has shutdown. In this case the Abort callback is called to notify the client of the /// shutdown. /// </para> /// <para> /// If the exception is a CommunicationException, then the ThrowOnDisconnectedEndpoint() method is called on the /// ResourceManagment endpoint to throw the exception back to the calling client application to notify it of the /// failed endpoint. /// </para> /// <para> For all other exceptions, the exception is rethrown. </para> /// </summary> /// <param name="ex"> The exception that was thrown. </param> private void ProcessRemoteMethodCallException(Exception ex) { if (ex is RpcException) { if (!_serverContextIsOperational) { return; } _serverContextIsOperational = false; // if not a server shutdown, then throw the error message from the server //if (IsServerShutdownOrNoContextServerFault(ex as FaultException<DataGrpcFault>)) return; _pendingContextNotificationData = new ClientContextNotificationData(ClientContextNotificationType.ResourceManagementFail, ex); _logger.LogDebug(ex, "RpcException when server method call. Client reconnecting.."); } _logger.LogDebug(ex, "Exception when server method call."); }