File tree Expand file tree Collapse file tree
trpc-proto/trpc-proto-standard/src/test/java/com/tencent/trpc/proto/standard/concurrenttest
trpc-spring-boot-starters/trpc-spring-boot-starter/src/main
java/com/tencent/trpc/spring/boot/starters/listener Expand file tree Collapse file tree Original file line number Diff line number Diff line change 3232
3333public class TcpConcurrentTest {
3434
35- private static final int TCP_PORT = 12321 ;
35+ private static final int TCP_PORT = 12421 ;
3636 ProviderConfig <ConcurrentTestService > providerConfig ;
3737 ServiceConfig serviceConfig ;
3838
Original file line number Diff line number Diff line change 1+ /*
2+ * Tencent is pleased to support the open source community by making tRPC available.
3+ *
4+ * Copyright (C) 2023 Tencent.
5+ * All rights reserved.
6+ *
7+ * If you have downloaded a copy of the tRPC source code from Tencent,
8+ * please note that tRPC source code is licensed under the Apache 2.0 License,
9+ * A copy of the Apache 2.0 License can be found in the LICENSE file.
10+ */
11+
12+ package com .tencent .trpc .spring .boot .starters .listener ;
13+
14+ import com .tencent .trpc .core .common .ConfigManager ;
15+ import org .springframework .boot .context .event .ApplicationFailedEvent ;
16+ import org .springframework .context .ApplicationListener ;
17+ import org .springframework .core .annotation .Order ;
18+
19+ import java .util .concurrent .atomic .AtomicBoolean ;
20+
21+ /**
22+ * Handle the application failed event, the reason was TRpcLifecycleManager called before the application failed.
23+ */
24+ @ Order
25+ public class TRpcApplicationFailedListener implements ApplicationListener <ApplicationFailedEvent > {
26+ private static final AtomicBoolean PROCESSED = new AtomicBoolean (false );
27+
28+ @ Override
29+ public void onApplicationEvent (ApplicationFailedEvent event ) {
30+ if (PROCESSED .compareAndSet (false , true )) {
31+ stopTRPC ();
32+ }
33+ }
34+
35+ private void stopTRPC () {
36+ ConfigManager .getInstance ().stop ();
37+ }
38+ }
Original file line number Diff line number Diff line change 11org.springframework.context.ApplicationListener=\
2- com.tencent.trpc.spring.boot.starters.listener.TRpcBannerListener
2+ com.tencent.trpc.spring.boot.starters.listener.TRpcBannerListener,\
3+ com.tencent.trpc.spring.boot.starters.listener.TRpcApplicationFailedListener
34org.springframework.boot.env.EnvironmentPostProcessor=\
45 com.tencent.trpc.spring.boot.starters.env.TRpcConfigurationEnvironmentPostProcessor
56org.springframework.context.ApplicationContextInitializer=\
You can’t perform that action at this time.
0 commit comments