3
3
import com .google .common .cache .Cache ;
4
4
import com .google .common .cache .CacheBuilder ;
5
5
import com .jhl .pojo .AccountConnectionStat ;
6
- import com .jhl .service .ProxyAccountService ;
7
6
import com .jhl .task .GlobalConnectionStatTask ;
8
7
import com .jhl .task .service .TaskService ;
9
8
import com .jhl .utils .SynchronizedInternerUtils ;
22
21
public class ConnectionStatsCache {
23
22
24
23
private static final Cache <Object , AccountConnectionStat > ACCOUNT_CONNECTION_COUNT_STATS = CacheBuilder .newBuilder ()
25
- .expireAfterAccess (ProxyAccountService . ACCOUNT_EXPIRE_TIME , TimeUnit .MINUTES ).build ();
24
+ .expireAfterAccess (5 , TimeUnit .MINUTES ).build ();
26
25
27
26
public final static long _1HOUR_MS = 3600000 ;
28
27
@@ -107,20 +106,20 @@ public static boolean isFull(String accountId, int maxConnections) {
107
106
return false ;
108
107
}
109
108
110
- public static boolean canReport (String accountId ) {
111
- synchronized (SynchronizedInternerUtils .getInterner ().intern (accountId )){
112
- AccountConnectionStat connectionCounter = ACCOUNT_CONNECTION_COUNT_STATS .getIfPresent (accountId );
113
- if (connectionCounter != null ) {
114
- long interruptionTime = connectionCounter .getInterruptionTime ();
115
- //操作一个小时后,可以继续执行上报
116
- //interruptionTime =0 ok
117
- // interruptionTime !=0 ok
118
- if ((System .currentTimeMillis () - interruptionTime ) > _1HOUR_MS ) {
119
- connectionCounter .setInterruptionTime (System .currentTimeMillis ());
120
- return true ;
109
+ public static boolean canReport (String accountId ) {
110
+ synchronized (SynchronizedInternerUtils .getInterner ().intern (accountId )) {
111
+ AccountConnectionStat connectionCounter = ACCOUNT_CONNECTION_COUNT_STATS .getIfPresent (accountId );
112
+ if (connectionCounter != null ) {
113
+ long interruptionTime = connectionCounter .getInterruptionTime ();
114
+ //操作一个小时后,可以继续执行上报
115
+ //interruptionTime =0 ok
116
+ // interruptionTime !=0 ok
117
+ if ((System .currentTimeMillis () - interruptionTime ) > _1HOUR_MS ) {
118
+ connectionCounter .setInterruptionTime (System .currentTimeMillis ());
119
+ return true ;
120
+ }
121
121
}
122
- }
123
- return false ;
122
+ return false ;
124
123
}
125
124
}
126
125
@@ -136,7 +135,7 @@ public static void updateGlobalConnectionStat(String accountNo, int count, long
136
135
connectionCounter .updateRemoteConnectionNum (count );
137
136
}
138
137
//全局控制
139
- if (interruptionTime > 0 ) connectionCounter .setInterruptionTime (interruptionTime );
138
+ if (interruptionTime > 0 ) connectionCounter .setInterruptionTime (interruptionTime );
140
139
}
141
140
142
141
/**
@@ -152,9 +151,9 @@ public static void updateGlobalConnectionStat(String accountNo, int count, long
152
151
*/
153
152
public static void reportConnectionNum (String accountNo , String proxyIp ) {
154
153
AccountConnectionStat connectionCounter = ACCOUNT_CONNECTION_COUNT_STATS .getIfPresent (accountNo );
155
- int internalConnectionCount = connectionCounter .getByServer ();
156
154
157
155
if (System .currentTimeMillis () - connectionCounter .getLastReportTime () > _30S ) {
156
+ int internalConnectionCount = connectionCounter .getByServer ();
158
157
GlobalConnectionStatTask globalConnectionStatTask =
159
158
new GlobalConnectionStatTask (accountNo , proxyIp , internalConnectionCount );
160
159
TaskService .addTask (globalConnectionStatTask );
0 commit comments