| | |
| | | if (taskNo == null || taskNo <= 0 || stationId == null) { |
| | | return RerouteExecutionResult.skip("invalid-station-task"); |
| | | } |
| | | boolean runBlockReroute = context.sceneType() == RerouteSceneType.RUN_BLOCK_REROUTE; |
| | | if (runBlockReroute) { |
| | | // 站点进入堵塞后,设备侧可能已经把之前预下发的分段命令清掉了。 |
| | | // 先作废本地 session/segment 状态,再按新路线重发,避免被旧状态反向卡住。 |
| | | if (context.cancelSessionBeforeDispatch() && stationMoveCoordinator != null) { |
| | | stationMoveCoordinator.cancelSession(taskNo); |
| | | } |
| | | if (context.resetSegmentCommandsBeforeDispatch()) { |
| | | resetSegmentMoveCommandsBeforeReroute(taskNo); |
| | | } |
| | | if (stationMoveCoordinator != null) { |
| | | return stationMoveCoordinator.withTaskDispatchLock(taskNo, |
| | | () -> executeReroutePlanWithTaskLock(context, plan, stationProtocol, taskNo, stationId)); |
| | | } |
| | | return executeReroutePlanWithTaskLock(context, plan, stationProtocol, taskNo, stationId); |
| | | } |
| | | |
| | | private RerouteExecutionResult executeReroutePlanWithTaskLock(RerouteContext context, |
| | | RerouteCommandPlan plan, |
| | | StationProtocol stationProtocol, |
| | | Integer taskNo, |
| | | Integer stationId) { |
| | | boolean runBlockReroute = context.sceneType() == RerouteSceneType.RUN_BLOCK_REROUTE; |
| | | if (context.checkRecentDispatch() |
| | | && shouldSkipIdleRecoverForRecentDispatch(taskNo, stationId)) { |
| | | return RerouteExecutionResult.skip("recent-dispatch"); |
| | |
| | | return RerouteExecutionResult.skip("out-order-lock"); |
| | | } |
| | | |
| | | if (context.cancelSessionBeforeDispatch() && stationMoveCoordinator != null) { |
| | | // 切路前先把旧 session 置为 CANCEL_PENDING,让已经排队中的旧分段线程在最终发送前停下。 |
| | | stationMoveCoordinator.markCancelPending(taskNo, "reroute_pending"); |
| | | } |
| | | |
| | | if (runBlockReroute) { |
| | | // 站点进入堵塞后,设备侧可能已经把之前预下发的分段命令清掉了。 |
| | | // 先作废本地 session/segment 状态,再按新路线重发,避免被旧状态反向卡住。 |
| | | if (context.cancelSessionBeforeDispatch() && stationMoveCoordinator != null) { |
| | | stationMoveCoordinator.cancelSession(taskNo); |
| | | } |
| | | if (context.resetSegmentCommandsBeforeDispatch()) { |
| | | resetSegmentMoveCommandsBeforeReroute(taskNo); |
| | | } |
| | | } |
| | | |
| | | if (!runBlockReroute |
| | | && context.cancelSessionBeforeDispatch() && stationMoveCoordinator != null) { |
| | | stationMoveCoordinator.cancelSession(taskNo); |