MCPcopy Create free account
hub / github.com/e2wugui/zeze / schedule

Method schedule

ZezeJava/ZezeJava/src/main/java/Zeze/Net/Rpc.java:89–113  ·  view source on GitHub ↗
(@NotNull Service service, long sessionId, int millisecondsTimeout)

Source from the content-addressed store, hash-verified

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 中设置的参数发送。

Callers 2

SendMethod · 0.95
SendReturnVoidMethod · 0.95

Calls 8

scheduleMethod · 0.95
getInstanceMethod · 0.95
removeRpcContextMethod · 0.80
getTypeIdMethod · 0.65
setResultCodeMethod · 0.45
setExceptionMethod · 0.45
dispatchRpcResponseMethod · 0.45

Tested by

no test coverage detected