pzampino commented on a change in pull request #257: KNOX-2214 - Periodic job
to evict expired tokens
URL: https://github.com/apache/knox/pull/257#discussion_r377892313
##########
File path:
gateway-server/src/main/java/org/apache/knox/gateway/services/token/impl/DefaultTokenStateService.java
##########
@@ -278,18 +281,34 @@ protected String getTimestampDisplay(long timestamp) {
* Method that deletes expired tokens based on the token timestamp.
*/
protected void evictExpiredTokens() {
- try {
- for (final String token : getTokens()) {
- if (isExpired(token)) {
+ for (final String token : getTokens()) {
+ try {
+ if (needsEviction(token)) {
log.evictToken(getTokenDisplayText(token));
removeToken(token);
}
+ } catch (final Exception e) {
+ log.failedExpiredTokenEviction(getTokenDisplayText(token), e);
}
- } catch(final Exception e) {
- log.failedExpiredTokenEviction(e);
}
}
+ /**
+ * Method that checks if an expired token is ready to be evicted
+ * by adding configured grace period to the expiry time.
+ * @param token
+ * @return
+ */
+ protected boolean needsEviction(final String token) {
+ boolean needsEviction;
+ needsEviction = isUnknown(token); // Check if the token exist
+ if (!needsEviction) {
+ /* If it not unknown, check if it is expired and within grace period
before evicting */
+ needsEviction = (getTokenExpiration(token) +
TimeUnit.SECONDS.toMillis(tokenEvictionGracePeriod)) <=
System.currentTimeMillis();
Review comment:
I think this whole method could be simply this single statement:
return ((getTokenExpiration(token) +
TimeUnit.SECONDS.toMillis(tokenEvictionGracePeriod)) <=
System.currentTimeMillis());
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services