Thomas Vachuska
Committed by Gerrit Code Review

Added thread-group name as a prefix to the thread-group pattern.

Change-Id: Id804ba00f2391d18a1bc4ea06cd39934208d6c18
...@@ -43,6 +43,9 @@ import static java.nio.file.Files.walkFileTree; ...@@ -43,6 +43,9 @@ import static java.nio.file.Files.walkFileTree;
43 import static org.onlab.util.GroupedThreadFactory.groupedThreadFactory; 43 import static org.onlab.util.GroupedThreadFactory.groupedThreadFactory;
44 import static org.slf4j.LoggerFactory.getLogger; 44 import static org.slf4j.LoggerFactory.getLogger;
45 45
46 +/**
47 + * Miscellaneous utility methods.
48 + */
46 public abstract class Tools { 49 public abstract class Tools {
47 50
48 private Tools() { 51 private Tools() {
...@@ -68,7 +71,9 @@ public abstract class Tools { ...@@ -68,7 +71,9 @@ public abstract class Tools {
68 * Returns a thread factory that produces threads named according to the 71 * Returns a thread factory that produces threads named according to the
69 * supplied name pattern and from the specified thread-group. The thread 72 * supplied name pattern and from the specified thread-group. The thread
70 * group name is expected to be specified in slash-delimited format, e.g. 73 * group name is expected to be specified in slash-delimited format, e.g.
71 - * {@code onos/intent}. 74 + * {@code onos/intent}. The thread names will be produced by converting
75 + * the thread group name into dash-delimited format and pre-pended to the
76 + * specified pattern.
72 * 77 *
73 * @param groupName group name in slash-delimited format to indicate hierarchy 78 * @param groupName group name in slash-delimited format to indicate hierarchy
74 * @param pattern name pattern 79 * @param pattern name pattern
...@@ -77,7 +82,7 @@ public abstract class Tools { ...@@ -77,7 +82,7 @@ public abstract class Tools {
77 public static ThreadFactory groupedThreads(String groupName, String pattern) { 82 public static ThreadFactory groupedThreads(String groupName, String pattern) {
78 return new ThreadFactoryBuilder() 83 return new ThreadFactoryBuilder()
79 .setThreadFactory(groupedThreadFactory(groupName)) 84 .setThreadFactory(groupedThreadFactory(groupName))
80 - .setNameFormat(pattern) 85 + .setNameFormat(groupName.replace(GroupedThreadFactory.DELIMITER, "-") + "-" + pattern)
81 // FIXME remove UncaughtExceptionHandler before release 86 // FIXME remove UncaughtExceptionHandler before release
82 .setUncaughtExceptionHandler((t, e) -> log.error("Uncaught exception on {}", t.getName(), e)).build(); 87 .setUncaughtExceptionHandler((t, e) -> log.error("Uncaught exception on {}", t.getName(), e)).build();
83 } 88 }
......
...@@ -55,10 +55,10 @@ public class ToolsTest { ...@@ -55,10 +55,10 @@ public class ToolsTest {
55 55
56 @Test 56 @Test
57 public void groupedThreads() { 57 public void groupedThreads() {
58 - ThreadFactory f = Tools.groupedThreads("foo/bar", "foo-%d"); 58 + ThreadFactory f = Tools.groupedThreads("foo/bar-me", "foo-%d");
59 Thread t = f.newThread(() -> TestTools.print("yo")); 59 Thread t = f.newThread(() -> TestTools.print("yo"));
60 - assertTrue("wrong pattern", t.getName().startsWith("foo-")); 60 + assertTrue("wrong pattern", t.getName().startsWith("foo-bar-me-foo-"));
61 - assertTrue("wrong group", t.getThreadGroup().getName().equals("foo/bar")); 61 + assertTrue("wrong group", t.getThreadGroup().getName().equals("foo/bar-me"));
62 } 62 }
63 63
64 } 64 }
......