11package com .talex .talexframe .frame .core .modules .controller ;
22
3- import com .google . common . util . concurrent . RateLimiter ;
3+ import com .talex . talexframe . frame . core . modules . network . connection . RequestAnalyser ;
44import com .talex .talexframe .frame .core .modules .network .interfaces .IUnRegisterHandler ;
55import com .talex .talexframe .frame .core .modules .plugins .core .WebPlugin ;
66import com .talex .talexframe .frame .core .modules .repository .TRepository ;
77import com .talex .talexframe .frame .core .modules .repository .TRepositoryManager ;
88import com .talex .talexframe .frame .core .pojo .annotations .TRepoInject ;
9- import com .talex .talexframe .frame .core .pojo .annotations .TRequestLimit ;
109import com .talex .talexframe .frame .core .talex .TFrame ;
1110import lombok .Getter ;
1211import lombok .SneakyThrows ;
1312
1413import java .lang .reflect .Field ;
15- import java .lang .reflect .Method ;
1614import java .util .concurrent .ConcurrentHashMap ;
1715import java .util .concurrent .ConcurrentMap ;
1816
1917/**
20- * <br /> {@link com.talex.talexframe.frame.function.repository Package }
18+ * <br /> {@link com.talex.talexframe.frame.core.modules.controller Package }
2119 *
2220 * @author TalexDreamSoul
2321 * @date 2022/1/20 18:49 <br /> Project: TalexFrame <br />
@@ -65,40 +63,14 @@ public boolean registerController(WebPlugin plugin, TController controller) {
6563 this .controllers .put (controller .getClass (), controller );
6664 this .controllerPluginMap .put (controller , plugin .getName ());
6765
68- Class <?> clz = controller .getClass ();
69-
70- TRequestLimit clzLimit = clz .getAnnotation (TRequestLimit .class );
71-
72- if ( clzLimit != null ) {
73-
74- RateLimiter limiter = RateLimiter .create (clzLimit .QPS (), clzLimit .timeout (), clzLimit .timeUnit ());
75-
76- TFrame .tframe .getRateLimiterManager ().getClassLimiterMapper ().put (clz , limiter );
77-
78- }
79-
80- for ( Method method : clz .getMethods () ) {
81-
82- TRequestLimit methodLimit = method .getAnnotation (TRequestLimit .class );
83-
84- if ( methodLimit != null ) {
85-
86- RateLimiter limiter = RateLimiter .create (methodLimit .QPS (), methodLimit .timeout (), methodLimit .timeUnit ());
87-
88- TFrame .tframe .getRateLimiterManager ().getMethodLimiterMapper ().put (method , limiter );
89-
90- }
91-
92- }
93-
9466 TRepositoryManager repoManager = TFrame .tframe .getRepositoryManager ();
9567
9668 /*
9769
9870 扫描类中所有字段 带有 TRepInject 的字段,自动从 TRepositoryManager 中根据字段类型注入
9971
10072 */
101- for ( Field field : clz .getDeclaredFields () ) {
73+ for ( Field field : controller . getClass () .getDeclaredFields () ) {
10274
10375 TRepoInject repoInject = field .getAnnotation (TRepoInject .class );
10476
@@ -122,6 +94,13 @@ public boolean registerController(WebPlugin plugin, TController controller) {
12294
12395 }
12496
97+ /**
98+ *
99+ * 让 NetworkMananager 扫一下这个类
100+ *
101+ */
102+ RequestAnalyser .scanRequests ( controller );
103+
125104 return true ;
126105
127106 }
@@ -149,19 +128,11 @@ public boolean unRegisterController(WebPlugin plugin, TController controller) {
149128
150129 }
151130
131+ RequestAnalyser .removeRequests ( controller );
132+
152133 this .controllers .remove (controller .getClass (), controller );
153134 this .controllerPluginMap .remove (controller , plugin .getName ());
154135
155- Class <?> clz = controller .getClass ();
156-
157- TFrame .tframe .getRateLimiterManager ().getClassLimiterMapper ().remove (clz );
158-
159- for ( Method method : clz .getMethods () ) {
160-
161- TFrame .tframe .getRateLimiterManager ().getMethodLimiterMapper ().remove (method );
162-
163- }
164-
165136 return true ;
166137
167138 }
0 commit comments