[infinispan-commits] Infinispan SVN: r930 - in trunk/core/src/main/java/org/infinispan: factories and 1 other directory.

infinispan-commits at lists.jboss.org infinispan-commits at lists.jboss.org
Fri Oct 9 06:45:04 EDT 2009


Author: manik.surtani at jboss.com
Date: 2009-10-09 06:45:04 -0400 (Fri, 09 Oct 2009)
New Revision: 930

Modified:
   trunk/core/src/main/java/org/infinispan/executors/DefaultExecutorFactory.java
   trunk/core/src/main/java/org/infinispan/executors/DefaultScheduledExecutorFactory.java
   trunk/core/src/main/java/org/infinispan/factories/NamedExecutorsFactory.java
Log:
Better thread naming for executors

Modified: trunk/core/src/main/java/org/infinispan/executors/DefaultExecutorFactory.java
===================================================================
--- trunk/core/src/main/java/org/infinispan/executors/DefaultExecutorFactory.java	2009-10-09 10:43:39 UTC (rev 929)
+++ trunk/core/src/main/java/org/infinispan/executors/DefaultExecutorFactory.java	2009-10-09 10:45:04 UTC (rev 930)
@@ -23,8 +23,7 @@
       TypedProperties tp = TypedProperties.toTypedProperties(p);
       int maxThreads = tp.getIntProperty("maxThreads", 1);
       int queueSize = tp.getIntProperty("queueSize", 100000);
-      final String threadNamePrefix = tp.getProperty("threadNamePrefix", "Thread");
-
+      final String threadNamePrefix = tp.getProperty("threadNamePrefix", tp.getProperty("componentName", "Thread"));
       ThreadFactory tf = new ThreadFactory() {
          public Thread newThread(Runnable r) {
             Thread th = new Thread(r, threadNamePrefix + "-" + counter.getAndIncrement());

Modified: trunk/core/src/main/java/org/infinispan/executors/DefaultScheduledExecutorFactory.java
===================================================================
--- trunk/core/src/main/java/org/infinispan/executors/DefaultScheduledExecutorFactory.java	2009-10-09 10:43:39 UTC (rev 929)
+++ trunk/core/src/main/java/org/infinispan/executors/DefaultScheduledExecutorFactory.java	2009-10-09 10:45:04 UTC (rev 930)
@@ -16,7 +16,7 @@
    final static AtomicInteger counter = new AtomicInteger(0);
 
    public ScheduledExecutorService getScheduledExecutor(Properties p) {
-      final String threadNamePrefix = p.getProperty("threadNamePrefix", "ScheduledThread");
+      final String threadNamePrefix = p.getProperty("threadNamePrefix", p.getProperty("componentName", "Thread"));
       return Executors.newSingleThreadScheduledExecutor(new ThreadFactory() {
          public Thread newThread(Runnable r) {
             Thread th = new Thread(r, "Scheduled-" + threadNamePrefix + "-" + counter.getAndIncrement());

Modified: trunk/core/src/main/java/org/infinispan/factories/NamedExecutorsFactory.java
===================================================================
--- trunk/core/src/main/java/org/infinispan/factories/NamedExecutorsFactory.java	2009-10-09 10:43:39 UTC (rev 929)
+++ trunk/core/src/main/java/org/infinispan/factories/NamedExecutorsFactory.java	2009-10-09 10:45:04 UTC (rev 930)
@@ -25,16 +25,16 @@
       try {
          if (componentName.equals(KnownComponentNames.ASYNC_NOTIFICATION_EXECUTOR)) {
             return (T) buildAndConfigureExecutorService(globalConfiguration.getAsyncListenerExecutorFactoryClass(),
-                                                        globalConfiguration.getAsyncListenerExecutorProperties());
+                                                        globalConfiguration.getAsyncListenerExecutorProperties(), componentName);
          } else if (componentName.equals(KnownComponentNames.ASYNC_TRANSPORT_EXECUTOR)) {
             return (T) buildAndConfigureExecutorService(globalConfiguration.getAsyncTransportExecutorFactoryClass(),
-                                                        globalConfiguration.getAsyncTransportExecutorProperties());
+                                                        globalConfiguration.getAsyncTransportExecutorProperties(), componentName);
          } else if (componentName.equals(KnownComponentNames.EVICTION_SCHEDULED_EXECUTOR)) {
             return (T) buildAndConfigureScheduledExecutorService(globalConfiguration.getEvictionScheduledExecutorFactoryClass(),
-                                                                 globalConfiguration.getEvictionScheduledExecutorProperties());
+                                                                 globalConfiguration.getEvictionScheduledExecutorProperties(), componentName);
          } else if (componentName.equals(KnownComponentNames.ASYNC_REPLICATION_QUEUE_EXECUTOR)) {
             return (T) buildAndConfigureScheduledExecutorService(globalConfiguration.getReplicationQueueScheduledExecutorFactoryClass(),
-                                                                 globalConfiguration.getReplicationQueueScheduledExecutorProperties());
+                                                                 globalConfiguration.getReplicationQueueScheduledExecutorProperties(), componentName);
          } else {
             throw new ConfigurationException("Unknown named executor " + componentName);
          }
@@ -45,13 +45,34 @@
       }
    }
 
-   private ExecutorService buildAndConfigureExecutorService(String factoryName, Properties props) throws Exception {
+   private ExecutorService buildAndConfigureExecutorService(String factoryName, Properties props, String componentName) throws Exception {
       ExecutorFactory f = (ExecutorFactory) Util.getInstance(factoryName);
+      setComponentName(componentName, props);
       return f.getExecutor(props);
    }
 
-   private ScheduledExecutorService buildAndConfigureScheduledExecutorService(String factoryName, Properties props) throws Exception {
+   private ScheduledExecutorService buildAndConfigureScheduledExecutorService(String factoryName, Properties props, String componentName) throws Exception {
       ScheduledExecutorFactory f = (ScheduledExecutorFactory) Util.getInstance(factoryName);
+      setComponentName(componentName, props);
       return f.getScheduledExecutor(props);
    }
+
+   private void setComponentName(String cn, Properties p) {
+      if (cn != null) p.setProperty("componentName", format(cn));
+   }
+
+   private String format(String cn) {
+      int dotIndex = cn.lastIndexOf(".");
+      int dotIndexPlusOne = dotIndex + 1;
+      String cname = cn;
+      if (dotIndexPlusOne == cn.length())
+         cname = format(cn.substring(0, cn.length() - 1));
+      else {
+         if (dotIndex > -1 && cn.length() > dotIndexPlusOne) {
+            cname = cn.substring(dotIndexPlusOne);
+         }
+         cname += "-thread";
+      }
+      return cname;
+   }
 }



More information about the infinispan-commits mailing list