Details
-
Type:
Improvement
-
Status:
Closed
-
Priority:
Trivial
-
Resolution: Fixed
-
Affects Version/s: 1.1
-
Fix Version/s: 1.2
-
Labels:None
Description
Andreas Kozma suggests improved logging.
The only modifications I needed to make were (in my humble opinion useful) logging improvements and one bug fix in SimpleExpiryCache.toString. 2 patches are attached. if you like them, pls feel free to incorporate.
OIndex: main/java/org/wamblee/glassfish/auth/cache/impl/SimpleExpiryCache.java
===================================================================
--- main/java/org/wamblee/glassfish/auth/cache/impl/SimpleExpiryCache.java (revision 205)
+++ main/java/org/wamblee/glassfish/auth/cache/impl/SimpleExpiryCache.java (working copy)
@@ -231,7 +231,9 @@
@Override
public String toString() {
- return getClass().getName() + "(expiryTimeMillis = " + expiryTimeMillis + " seconds)";
+
+ String timeout = expiryTimeMillis > 0 ? "(expiryTimeMillis = " + getExpiryTimeSeconds() + " seconds)" : "Timeout disabled";
+ return getClass().getName() + timeout;
}
@Override
Index: main/java/org/wamblee/glassfish/auth/cache/impl/SimpleExpiryCacheManagement.java
===================================================================
--- main/java/org/wamblee/glassfish/auth/cache/impl/SimpleExpiryCacheManagement.java (revision 205)
+++ main/java/org/wamblee/glassfish/auth/cache/impl/SimpleExpiryCacheManagement.java (working copy)
@@ -15,6 +15,9 @@
*/
package org.wamblee.glassfish.auth.cache.impl;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
/**
* MBean implmenetation for {@link SimpleExpiryCache}.
@@ -25,6 +28,8 @@
class SimpleExpiryCacheManagement implements
SimpleExpiryCacheManagementMBean {
+ private static final Logger LOGGER = Logger.getLogger(SimpleExpiryCacheManagement.class.getName());
+
private SimpleExpiryCache cache;
public SimpleExpiryCacheManagement(SimpleExpiryCache aCache) {
@@ -49,7 +54,11 @@
@Override
public void clearUser(String aUsername) {
- cache.getEntries().remove(aUsername);
+ boolean success = cache.getEntries().remove(aUsername) != null;
+
+ if (LOGGER.isLoggable(Level.FINEST)) {
+ LOGGER.finest("Evicted cache for '" + aUsername + "' - success: " + success);
+ }
}
@Override
@@ -60,5 +69,9 @@
@Override
public void clearAll() {
cache.getEntries().clear();
+
+ if (LOGGER.isLoggable(Level.FINEST)) {
+ LOGGER.finest("Cleared entire cache");
+ }
}
}
\ No newline at end of file
The only modifications I needed to make were (in my humble opinion useful) logging improvements and one bug fix in SimpleExpiryCache.toString. 2 patches are attached. if you like them, pls feel free to incorporate.
OIndex: main/java/org/wamblee/glassfish/auth/cache/impl/SimpleExpiryCache.java
===================================================================
--- main/java/org/wamblee/glassfish/auth/cache/impl/SimpleExpiryCache.java (revision 205)
+++ main/java/org/wamblee/glassfish/auth/cache/impl/SimpleExpiryCache.java (working copy)
@@ -231,7 +231,9 @@
@Override
public String toString() {
- return getClass().getName() + "(expiryTimeMillis = " + expiryTimeMillis + " seconds)";
+
+ String timeout = expiryTimeMillis > 0 ? "(expiryTimeMillis = " + getExpiryTimeSeconds() + " seconds)" : "Timeout disabled";
+ return getClass().getName() + timeout;
}
@Override
Index: main/java/org/wamblee/glassfish/auth/cache/impl/SimpleExpiryCacheManagement.java
===================================================================
--- main/java/org/wamblee/glassfish/auth/cache/impl/SimpleExpiryCacheManagement.java (revision 205)
+++ main/java/org/wamblee/glassfish/auth/cache/impl/SimpleExpiryCacheManagement.java (working copy)
@@ -15,6 +15,9 @@
*/
package org.wamblee.glassfish.auth.cache.impl;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
/**
* MBean implmenetation for {@link SimpleExpiryCache}.
@@ -25,6 +28,8 @@
class SimpleExpiryCacheManagement implements
SimpleExpiryCacheManagementMBean {
+ private static final Logger LOGGER = Logger.getLogger(SimpleExpiryCacheManagement.class.getName());
+
private SimpleExpiryCache cache;
public SimpleExpiryCacheManagement(SimpleExpiryCache aCache) {
@@ -49,7 +54,11 @@
@Override
public void clearUser(String aUsername) {
- cache.getEntries().remove(aUsername);
+ boolean success = cache.getEntries().remove(aUsername) != null;
+
+ if (LOGGER.isLoggable(Level.FINEST)) {
+ LOGGER.finest("Evicted cache for '" + aUsername + "' - success: " + success);
+ }
}
@Override
@@ -60,5 +69,9 @@
@Override
public void clearAll() {
cache.getEntries().clear();
+
+ if (LOGGER.isLoggable(Level.FINEST)) {
+ LOGGER.finest("Cleared entire cache");
+ }
}
}
\ No newline at end of file
Using a format string instead of isLoggable().