MrtnBalazs commented on code in PR #620:
URL: https://github.com/apache/knox/pull/620#discussion_r951131695


##########
gateway-server/src/main/java/org/apache/knox/gateway/session/control/InMemoryConcurrentSessionVerifier.java:
##########
@@ -122,17 +129,34 @@ public void init(GatewayConfig config, Map<String, 
String> options) throws Servi
     this.nonPrivilegedUsers = config.getNonPrivilegedUsers();
     this.privilegedUserConcurrentSessionLimit = 
config.getPrivilegedUsersConcurrentSessionLimit();
     this.nonPrivilegedUserConcurrentSessionLimit = 
config.getNonPrivilegedUsersConcurrentSessionLimit();
+    this.cleaningPeriod = 
config.getConcurrentSessionVerifierExpiredTokensCleaningPeriod();
     this.concurrentSessionCounter = new ConcurrentHashMap<>();
   }
 
   @Override
   public void start() throws ServiceLifecycleException {
-
+    expiredTokenRemover.scheduleAtFixedRate(this::removeExpiredTokens, 
cleaningPeriod, cleaningPeriod, TimeUnit.SECONDS);
   }
 
   @Override
   public void stop() throws ServiceLifecycleException {
+    expiredTokenRemover.shutdown();
+  }
 
+  private void removeExpiredTokens() {
+    sessionCountModifyLock.lock();
+    try {
+      Iterator<Map.Entry<String, Set<SessionJWT>>> 
concurrentSessionCounterIterator = 
concurrentSessionCounter.entrySet().iterator();
+      while (concurrentSessionCounterIterator.hasNext()) {
+        Map.Entry<String, Set<SessionJWT>> concurrentSessionCounterMapEntry = 
concurrentSessionCounterIterator.next();
+        
concurrentSessionCounterMapEntry.setValue(concurrentSessionCounterMapEntry.getValue().stream().filter(sessionJWT
 -> !sessionJWT.hasExpired()).collect(Collectors.toSet()));

Review Comment:
   Yes, thats an easier way. Thank you.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to