[jbosscache-commits] JBoss Cache SVN: r6492 - in core/trunk/src: main/java/org/jboss/cache/config/parsing and 2 other directories.

jbosscache-commits at lists.jboss.org jbosscache-commits at lists.jboss.org
Mon Aug 4 08:49:34 EDT 2008


Author: manik.surtani at jboss.com
Date: 2008-08-04 08:49:34 -0400 (Mon, 04 Aug 2008)
New Revision: 6492

Modified:
   core/trunk/src/main/java/org/jboss/cache/config/Configuration.java
   core/trunk/src/main/java/org/jboss/cache/config/parsing/XmlConfigurationParser.java
   core/trunk/src/test/java/org/jboss/cache/config/parsing/XmlConfigurationParserTest.java
   core/trunk/src/test/java/org/jboss/cache/config/parsing/XmlConfigurationSchemaTest.java
   core/trunk/src/test/resources/configs/parser-test.xml
Log:
Added config elements for JBCACHE-1108 ( Move CacheListeners to their own thread pool, optionally enabled using an attribute on @CacheListener )

Modified: core/trunk/src/main/java/org/jboss/cache/config/Configuration.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/config/Configuration.java	2008-08-04 12:38:14 UTC (rev 6491)
+++ core/trunk/src/main/java/org/jboss/cache/config/Configuration.java	2008-08-04 12:49:34 UTC (rev 6492)
@@ -203,7 +203,8 @@
    private int objectOutputStreamPoolSize = 50;
    private List<CustomInterceptorConfig> customInterceptors = Collections.emptyList();
    private boolean writeSkewCheck = false;
-   private int concurrencyLevel = 50;
+   private int concurrencyLevel = 500;
+   private int listenerAsyncPoolSize = 0;
 
    @Start(priority = 1)
    private void correctIsolationLevels()
@@ -411,6 +412,12 @@
       this.syncRollbackPhase = syncRollbackPhase;
    }
 
+   public void setListenerAsyncPoolSize(int listenerAsyncPoolSize)
+   {
+      testImmutability("asyncListenerPoolSize");
+      this.listenerAsyncPoolSize = listenerAsyncPoolSize;
+   }
+
    public void setBuddyReplicationConfig(BuddyReplicationConfig config)
    {
       testImmutability("buddyReplicationConfig");
@@ -713,6 +720,14 @@
       return syncRollbackPhase;
    }
 
+   /**
+    * @return the size of the async listener thread pool.  If this is < 1, all async listeners should be treated as sync listeners.
+    */
+   public int getListenerAsyncPoolSize()
+   {
+      return listenerAsyncPoolSize;
+   }
+
    public BuddyReplicationConfig getBuddyReplicationConfig()
    {
       return buddyReplicationConfig;
@@ -855,6 +870,7 @@
       if (shutdownHookBehavior != that.shutdownHookBehavior) return false;
       if (transactionManagerLookupClass != null ? !transactionManagerLookupClass.equals(that.transactionManagerLookupClass) : that.transactionManagerLookupClass != null)
          return false;
+      if (listenerAsyncPoolSize != that.listenerAsyncPoolSize) return false;
 
       return true;
    }
@@ -950,6 +966,7 @@
     *
     * @return List of cutom interceptors, never null
     */
+   @SuppressWarnings("unchecked")
    public List<CustomInterceptorConfig> getCustomInterceptors()
    {
       return customInterceptors == null ? Collections.EMPTY_LIST : customInterceptors;

Modified: core/trunk/src/main/java/org/jboss/cache/config/parsing/XmlConfigurationParser.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/config/parsing/XmlConfigurationParser.java	2008-08-04 12:38:14 UTC (rev 6491)
+++ core/trunk/src/main/java/org/jboss/cache/config/parsing/XmlConfigurationParser.java	2008-08-04 12:49:34 UTC (rev 6492)
@@ -167,6 +167,7 @@
          configureEviction(getSingleElement("eviction"));
          configureCacheLoaders(getSingleElement("loaders"));
          configureCustomInterceptors(getSingleElement("customInterceptors"));
+         configureListeners(getSingleElement("listeners"));
       }
       catch (Exception e)
       {
@@ -225,6 +226,23 @@
       config.setCustomInterceptors(interceptorConfigList);
    }
 
+   private void configureListeners(Element element)
+   {
+      if (element == null) return; //this element is optional
+      String asyncPoolSizeStr = getAttributeValue(element, "asyncPoolSize");
+      if (asyncPoolSizeStr != null && !asyncPoolSizeStr.trim().equals(""))
+      {
+         try
+         {
+            config.setListenerAsyncPoolSize(Integer.parseInt(asyncPoolSizeStr));
+         }
+         catch (NumberFormatException nfe)
+         {
+            throw new ConfigurationException("Unable to parse the asyncPoolSize attribute of the listeners element.  Was [" + asyncPoolSizeStr + "]");
+         }
+      }
+   }
+
    private void configureBuddyReplication(Element element)
    {
       if (element == null) return;//buddy config might not exist, expect that

Modified: core/trunk/src/test/java/org/jboss/cache/config/parsing/XmlConfigurationParserTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/config/parsing/XmlConfigurationParserTest.java	2008-08-04 12:38:14 UTC (rev 6491)
+++ core/trunk/src/test/java/org/jboss/cache/config/parsing/XmlConfigurationParserTest.java	2008-08-04 12:49:34 UTC (rev 6492)
@@ -264,4 +264,9 @@
       assert !config.isWriteSkewCheck();
       assert config.getConcurrencyLevel() == 21;
    }
+
+   public void testListenerAsyncThreads()
+   {
+      assert config.getListenerAsyncPoolSize() == 5;
+   }
 }

Modified: core/trunk/src/test/java/org/jboss/cache/config/parsing/XmlConfigurationSchemaTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/config/parsing/XmlConfigurationSchemaTest.java	2008-08-04 12:38:14 UTC (rev 6491)
+++ core/trunk/src/test/java/org/jboss/cache/config/parsing/XmlConfigurationSchemaTest.java	2008-08-04 12:49:34 UTC (rev 6492)
@@ -10,12 +10,12 @@
 import java.util.List;
 
 /**
- * Tests that all the xml file used within tests are correct with respect to the schema definition. 
- *                                                          
+ * Tests that all the xml file used within tests are correct with respect to the schema definition.
+ *
  * @author Mircea.Markus at jboss.com
  * @since 3.0
  */
- at Test (groups = "functional")
+ at Test(groups = "functional")
 public class XmlConfigurationSchemaTest
 {
    public static final String BASE_DIR_FOR_CONFIG = "./configs";
@@ -33,20 +33,21 @@
                "policyPerRegion-eviction.xml",
                "replSync.xml",
                "string-property-replaced.xml"
-         };  
+         };
 
    /**
     * Simple test to prove that validation works.
     */
    public void testSimpleFile()
    {
-      EceptionCountingErrorHanlder handler = new EceptionCountingErrorHanlder();
+      ExceptionCountingErrorHandler handler = new ExceptionCountingErrorHandler();
       XmlConfigurationParser parser = new XmlConfigurationParser(handler);
       for (String file : testFiles)
       {
          System.out.println("file = " + file);
          parser.parseFile(BASE_DIR_FOR_CONFIG + File.separator + file);
-         assert handler.noErrors() : "error during parsing";
+         for (Exception e : handler.exceptionList) e.printStackTrace();
+         assert handler.noErrors() : "error during parsing (file " + file + ")";
       }
    }
 
@@ -67,7 +68,7 @@
       assert parser.isValidating();
    }
 
-   private static class EceptionCountingErrorHanlder implements ErrorHandler
+   private static class ExceptionCountingErrorHandler implements ErrorHandler
    {
       List<SAXParseException> exceptionList = new ArrayList<SAXParseException>();
 
@@ -88,7 +89,7 @@
 
       private void handleDefault(SAXParseException exception)
       {
-         System.out.println("Error :"  + exception.getMessage());
+         System.out.println("Error :" + exception.getMessage());
          exceptionList.add(exception);
       }
 

Modified: core/trunk/src/test/resources/configs/parser-test.xml
===================================================================
--- core/trunk/src/test/resources/configs/parser-test.xml	2008-08-04 12:38:14 UTC (rev 6491)
+++ core/trunk/src/test/resources/configs/parser-test.xml	2008-08-04 12:49:34 UTC (rev 6492)
@@ -110,4 +110,7 @@
       <interceptor after="org.jboss.cache.interceptors.CallInterceptor"
                    class="org.jboss.cache.config.parsing.custominterceptors.AaaCustomInterceptor"/>
    </customInterceptors>
+
+   <!-- the number of threads to use for asynchronous cache listeners - defaults to 1 -->
+   <listeners asyncPoolSize="5"/>
 </jbosscache>




More information about the jbosscache-commits mailing list