[jboss-cvs] JBossAS SVN: r107920 - in projects/security/security-xacml/trunk/jboss-xacml/src: test/java/org/jboss/test/security/xacml/core/cache and 1 other directory.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Tue Aug 31 11:32:00 EDT 2010
Author: anil.saldhana at jboss.com
Date: 2010-08-31 11:32:00 -0400 (Tue, 31 Aug 2010)
New Revision: 107920
Modified:
projects/security/security-xacml/trunk/jboss-xacml/src/main/java/org/jboss/security/xacml/locators/cache/DecisionCacheLocator.java
projects/security/security-xacml/trunk/jboss-xacml/src/test/java/org/jboss/test/security/xacml/core/cache/DecisionCacheLocatorUnitTestCase.java
Log:
SECURITY-521: add initialCapacity/loadFactor as options
Modified: projects/security/security-xacml/trunk/jboss-xacml/src/main/java/org/jboss/security/xacml/locators/cache/DecisionCacheLocator.java
===================================================================
--- projects/security/security-xacml/trunk/jboss-xacml/src/main/java/org/jboss/security/xacml/locators/cache/DecisionCacheLocator.java 2010-08-31 14:52:04 UTC (rev 107919)
+++ projects/security/security-xacml/trunk/jboss-xacml/src/main/java/org/jboss/security/xacml/locators/cache/DecisionCacheLocator.java 2010-08-31 15:32:00 UTC (rev 107920)
@@ -61,7 +61,15 @@
public static final String IGNORE_ENVIRONMENT_ID = "ignoreEnvironmentID";
public static final String ENHANCE_SPEED = "enhanceSpeed";
+
+ public static final String INITIAL_CAPACITY = "initialCapacity";
+ public static final String LOAD_FACTOR = "loadFactor";
+ /**
+ * Add a {@code RequestCtx} and a {@code ResponseCtx} to the cache
+ * @param request
+ * @param response
+ */
public void add( RequestCtx request, ResponseCtx response )
{
RequestCtx cacheRequest = preprocessRequest( request );
@@ -77,7 +85,12 @@
this.speedDecisionMap.put( cacheRequest, response );
}
}
-
+
+ /**
+ * Get a {@code ResponseCtx} response that we have cached
+ * for a {@code RequestCtx} request.
+ * @return response object if cached else null
+ */
public ResponseCtx get( RequestCtx request )
{
RequestCtx cacheRequest = preprocessRequest( request );
@@ -109,6 +122,10 @@
return response;
}
+ /**
+ * Specialized version of {@code RequestCtx} that is suited to be cached
+ * @author anil
+ */
public static class DecisionCacheLocatorRequest extends RequestCtx
{
@SuppressWarnings("rawtypes")
@@ -185,6 +202,13 @@
}
+ /**
+ * Transform the XACML request into a request that we can place
+ * in the cache, while considering any of the (subject, resource, action, environment)
+ * attributes that need to be ignored
+ * @param request
+ * @return
+ */
private RequestCtx preprocessRequest( RequestCtx request )
{
List<String> subjectID = new ArrayList<String>();
@@ -206,6 +230,11 @@
subjectID, resourceID, actionID, envID );
}
+ /**
+ * Get a list of token from comma separated string
+ * @param commaSeparatedListOfStrings
+ * @return
+ */
private List<String> getTokenList( String commaSeparatedListOfStrings )
{
List<String> stringList = new ArrayList<String>();
@@ -222,6 +251,10 @@
return stringList;
}
+ /**
+ * Determine whether we need correctness (WeakHashMap) or Speed (LinkedHashMap)
+ * @return
+ */
private boolean needCorrectness()
{
boolean correctness = false;
@@ -232,15 +265,61 @@
return correctness;
}
+ /**
+ * Validate that the WeakHashMap is not null
+ */
private void validateCorrectnessMap()
- {
+ {
if( correctnessDecisionMap == null )
- correctnessDecisionMap = new WeakHashMap<RequestCtx, ResponseCtx>();
+ {
+ int initialCapacity = getInitialCapacity();
+ float loadFactor = getLoadFactor();
+ correctnessDecisionMap = new WeakHashMap<RequestCtx, ResponseCtx>( initialCapacity , loadFactor );
+ }
}
+ /**
+ * Validate that the LRU LinkedHashMap is not null
+ */
private void validateSpeedMap()
{
if( speedDecisionMap == null )
- speedDecisionMap = new LinkedHashMap<RequestCtx, ResponseCtx>( 100, 5, true );
+ {
+ int initialCapacity = getInitialCapacity();
+ float loadFactor = getLoadFactor();
+
+ speedDecisionMap = new LinkedHashMap<RequestCtx, ResponseCtx>( initialCapacity, loadFactor, true );
+ }
}
+
+ /**
+ * Get the configured Initial Capacity
+ * @return
+ */
+ private int getInitialCapacity()
+ {
+ int initialCapacity = 100;
+
+ String initialCapacityStr = (String) optionMap.get( INITIAL_CAPACITY );
+ if( initialCapacityStr != null && initialCapacityStr != "" )
+ {
+ initialCapacity = Integer.parseInt( initialCapacityStr );
+ }
+ return initialCapacity;
+ }
+
+ /**
+ * Get the configured load factor
+ * @return
+ */
+ private float getLoadFactor()
+ {
+ float loadFactor = 0.75F;
+ String loadFactorStr = (String) optionMap.get( LOAD_FACTOR );
+ if( loadFactorStr != null && loadFactorStr != "" )
+ {
+ loadFactor = Float.parseFloat( loadFactorStr );
+ }
+ return loadFactor;
+ }
}
\ No newline at end of file
Modified: projects/security/security-xacml/trunk/jboss-xacml/src/test/java/org/jboss/test/security/xacml/core/cache/DecisionCacheLocatorUnitTestCase.java
===================================================================
--- projects/security/security-xacml/trunk/jboss-xacml/src/test/java/org/jboss/test/security/xacml/core/cache/DecisionCacheLocatorUnitTestCase.java 2010-08-31 14:52:04 UTC (rev 107919)
+++ projects/security/security-xacml/trunk/jboss-xacml/src/test/java/org/jboss/test/security/xacml/core/cache/DecisionCacheLocatorUnitTestCase.java 2010-08-31 15:32:00 UTC (rev 107920)
@@ -43,6 +43,7 @@
/**
+ * Unit Test the {@code DecisionCacheLocator}
* @author Anil.Saldhana at redhat.com
* @since Aug 30, 2010
*/
@@ -144,8 +145,8 @@
@Test
public void testCache() throws Exception
{
- System.out.println( "We are going to run a short performance test that will take under 1 min " );
- int len = 2;
+ System.out.println( "We are going to run a short performance test that will take under 1 min. " );
+ int len = 100;
long start = System.currentTimeMillis();
for( int i = 0 ; i < len; i++ )
@@ -154,7 +155,7 @@
}
long elapsedTimeMillis = System.currentTimeMillis() - start;
System.out.println("Without Decision Caching, time spent for " + len
- + " iterations in = " + elapsedTimeMillis + " ms or " + elapsedTimeMillis/1000F + " secs");
+ + " iterations = " + elapsedTimeMillis + " ms or " + elapsedTimeMillis/1000F + " secs");
@@ -165,7 +166,7 @@
}
elapsedTimeMillis = System.currentTimeMillis() - start;
System.out.println("With Decision Caching, time spent for " + len
- + " iterations in = " + elapsedTimeMillis + " ms or " + elapsedTimeMillis/1000F + " secs");
+ + " iterations= " + elapsedTimeMillis + " ms or " + elapsedTimeMillis/1000F + " secs");
start = System.currentTimeMillis();
for( int i = 0 ; i < len; i++ )
@@ -174,7 +175,7 @@
}
elapsedTimeMillis = System.currentTimeMillis() - start;
System.out.println("With Decision Caching (Enhanced Speed), time spent for " + len
- + " iterations in = " + elapsedTimeMillis + " ms or " + elapsedTimeMillis/1000F + " secs");
+ + " iterations = " + elapsedTimeMillis + " ms or " + elapsedTimeMillis/1000F + " secs");
}
private void runTests( PolicyDecisionPoint pdp) throws Exception
More information about the jboss-cvs-commits
mailing list