(@NotNull Service service, long sessionId, int millisecondsTimeout)
| 87 | } |
| 88 | |
| 89 | public void schedule(@NotNull Service service, long sessionId, int millisecondsTimeout) { |
| 90 | long timeout = Math.max(millisecondsTimeout, 0); |
| 91 | if (Reflect.inDebugMode) |
| 92 | timeout += 10 * 60 * 1000; // 调试状态下RPC超时放宽到至少10分钟,方便调试时不容易超时 |
| 93 | |
| 94 | Task.schedule(timeout, () -> { |
| 95 | Rpc<TArgument, TResult> context = service.removeRpcContext(sessionId); |
| 96 | if (context == null) // 一般来说,此时结果已经返回。 |
| 97 | return; |
| 98 | |
| 99 | context.isTimeout = true; |
| 100 | context.setResultCode(Procedure.Timeout); |
| 101 | |
| 102 | if (context.future != null) |
| 103 | context.future.setException(RpcTimeoutException.getInstance()); |
| 104 | else if (context.responseHandle != null) { |
| 105 | // 本来Schedule已经在Task中执行了,这里又派发一次。 |
| 106 | // 主要是为了让应用能拦截修改Response的处理方式。 |
| 107 | // Timeout 应该是少的,先这样了。 |
| 108 | var factoryHandle = service.findProtocolFactoryHandle(context.getTypeId()); |
| 109 | if (factoryHandle != null) |
| 110 | service.dispatchRpcResponse(context, context.responseHandle, factoryHandle); |
| 111 | } |
| 112 | }); |
| 113 | } |
| 114 | |
| 115 | /** |
| 116 | * 使用当前 rpc 中设置的参数发送。 |
no test coverage detected