sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jsedd...@apache.org
Subject svn commit: r1718272 - in /sling/trunk/bundles/commons/threads/src: main/java/org/apache/sling/commons/threads/impl/ExtendedThreadFactory.java test/java/org/apache/sling/commons/threads/impl/ExtendedThreadFactoryTest.java
Date Mon, 07 Dec 2015 09:53:29 GMT
Author: jsedding
Date: Mon Dec  7 09:53:29 2015
New Revision: 1718272

URL: http://svn.apache.org/viewvc?rev=1718272&view=rev
Log:
SLING-5343 - Meaningful thread names

- change thread name format due to mailing list discussions

Modified:
    sling/trunk/bundles/commons/threads/src/main/java/org/apache/sling/commons/threads/impl/ExtendedThreadFactory.java
    sling/trunk/bundles/commons/threads/src/test/java/org/apache/sling/commons/threads/impl/ExtendedThreadFactoryTest.java

Modified: sling/trunk/bundles/commons/threads/src/main/java/org/apache/sling/commons/threads/impl/ExtendedThreadFactory.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/commons/threads/src/main/java/org/apache/sling/commons/threads/impl/ExtendedThreadFactory.java?rev=1718272&r1=1718271&r2=1718272&view=diff
==============================================================================
--- sling/trunk/bundles/commons/threads/src/main/java/org/apache/sling/commons/threads/impl/ExtendedThreadFactory.java
(original)
+++ sling/trunk/bundles/commons/threads/src/main/java/org/apache/sling/commons/threads/impl/ExtendedThreadFactory.java
Mon Dec  7 09:53:29 2015
@@ -16,6 +16,7 @@
  */
 package org.apache.sling.commons.threads.impl;
 
+import java.util.Locale;
 import java.util.concurrent.ThreadFactory;
 import java.util.concurrent.atomic.AtomicInteger;
 
@@ -30,7 +31,7 @@ import org.apache.sling.commons.threads.
 public final class ExtendedThreadFactory implements ThreadFactory {
 
     /** Template for thread names, for use with String#format() */
-    private static final String THREAD_NAME_TEMPLATE = "Sling - %s #%d";
+    private static final String THREAD_NAME_TEMPLATE = "sling-%s-%d";
 
     /** The real factory. */
     private final ThreadFactory factory;
@@ -59,12 +60,17 @@ public final class ExtendedThreadFactory
                                  final ThreadPoolConfig.ThreadPriority priority,
                                  final boolean isDaemon) {
         this.factory = factory;
-        this.name = stripPrefixes(name, "Apache Sling ", "Sling ");
+        this.name = normalizeName(name);
         this.priority = convertPriority(priority);
         this.isDaemon = isDaemon;
         this.threadCounter = new AtomicInteger(1);
     }
 
+    private String normalizeName(final String name) {
+        final String n = name.toLowerCase(Locale.ENGLISH).replaceAll("\\s+", "-");
+        return stripPrefixes(n, "apache-sling-", "sling-");
+    }
+
     private int convertPriority(final ThreadPoolConfig.ThreadPriority priority) {
         if (priority == null) {
             throw new IllegalStateException("Prioriy must not be null.");

Modified: sling/trunk/bundles/commons/threads/src/test/java/org/apache/sling/commons/threads/impl/ExtendedThreadFactoryTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/commons/threads/src/test/java/org/apache/sling/commons/threads/impl/ExtendedThreadFactoryTest.java?rev=1718272&r1=1718271&r2=1718272&view=diff
==============================================================================
--- sling/trunk/bundles/commons/threads/src/test/java/org/apache/sling/commons/threads/impl/ExtendedThreadFactoryTest.java
(original)
+++ sling/trunk/bundles/commons/threads/src/test/java/org/apache/sling/commons/threads/impl/ExtendedThreadFactoryTest.java
Mon Dec  7 09:53:29 2015
@@ -33,20 +33,20 @@ public class ExtendedThreadFactoryTest {
     @Test
     public void informativeThreadNames() {
         final ExtendedThreadFactory tf = factory("Test Pool");
-        assertEquals("Thread name", "Sling - Test Pool #1", tf.newThread(null).getName());
-        assertEquals("Thread name", "Sling - Test Pool #2", tf.newThread(null).getName());
+        assertEquals("Thread name", "sling-test-pool-1", tf.newThread(null).getName());
+        assertEquals("Thread name", "sling-test-pool-2", tf.newThread(null).getName());
     }
 
     @Test
     public void shouldStripSlingPrefixFromThreadNames() {
         final Thread thread = thread("Sling Test Pool");
-        assertEquals("Thread name", "Sling - Test Pool #1", thread.getName());
+        assertEquals("Thread name", "sling-test-pool-1", thread.getName());
     }
 
     @Test
     public void shouldStripApacheSlingPrefixFromThreadNames() {
         final Thread thread = thread("Apache Sling Test Pool");
-        assertEquals("Thread name", "Sling - Test Pool #1", thread.getName());
+        assertEquals("Thread name", "sling-test-pool-1", thread.getName());
     }
 
     @Test



Mime
View raw message