More strict thread naming rule
This commit is contained in:
parent
4680cd0bb3
commit
3659847859
@ -196,7 +196,7 @@ class NioClientSocketPipelineSink extends AbstractChannelSink {
|
||||
try {
|
||||
bossExecutor.execute(
|
||||
new IoWorkerRunnable(new ThreadRenamingRunnable(
|
||||
this, "New I/O", "client boss", String.valueOf(id), null)));
|
||||
this, "NewIO", "ClientBoss", String.valueOf(id), null)));
|
||||
success = true;
|
||||
} finally {
|
||||
if (!success) {
|
||||
|
@ -169,7 +169,7 @@ class NioDatagramWorker implements Runnable {
|
||||
try {
|
||||
// Start the main selector loop. See run() for details.
|
||||
executor.execute(new ThreadRenamingRunnable(
|
||||
this, "New I/O", "datagram worker", bossId + "-" + id, null));
|
||||
this, "NewIO", "DatagramWorker", bossId + "-" + id, null));
|
||||
success = true;
|
||||
} finally {
|
||||
if (!success) {
|
||||
|
@ -156,7 +156,7 @@ class NioServerSocketPipelineSink extends AbstractChannelSink {
|
||||
bossExecutor.execute(
|
||||
new IoWorkerRunnable(new ThreadRenamingRunnable(
|
||||
new Boss(channel),
|
||||
"New I/O", "server boss", String.valueOf(id),
|
||||
"NewIO", "ServerBoss", String.valueOf(id),
|
||||
channel.toString())));
|
||||
bossStarted = true;
|
||||
} catch (Throwable t) {
|
||||
|
@ -110,8 +110,8 @@ class NioWorker implements Runnable {
|
||||
try {
|
||||
executor.execute(
|
||||
new IoWorkerRunnable(new ThreadRenamingRunnable(
|
||||
this, "New I/O",
|
||||
server? "server worker" : "client worker",
|
||||
this, "NewIO",
|
||||
server? "ServerWorker" : "ClientWorker",
|
||||
bossId + "-" + id, null)));
|
||||
success = true;
|
||||
} finally {
|
||||
|
@ -135,7 +135,7 @@ class OioClientSocketPipelineSink extends AbstractChannelSink {
|
||||
new IoWorkerRunnable(
|
||||
new ThreadRenamingRunnable(
|
||||
new OioWorker(channel),
|
||||
"Old I/O", "client worker",
|
||||
"OldIO", "ClientWorker",
|
||||
id + "-" + channel.getId(),
|
||||
channel.toString())));
|
||||
workerStarted = true;
|
||||
|
@ -106,8 +106,8 @@ class OioDatagramPipelineSink extends AbstractChannelSink {
|
||||
new IoWorkerRunnable(
|
||||
new ThreadRenamingRunnable(
|
||||
new OioDatagramWorker(channel),
|
||||
"Old I/O",
|
||||
"datagram worker",
|
||||
"OldIO",
|
||||
"DatagramWorker",
|
||||
id + "-" + channel.getId(),
|
||||
channel.toString())));
|
||||
workerStarted = true;
|
||||
@ -146,8 +146,8 @@ class OioDatagramPipelineSink extends AbstractChannelSink {
|
||||
}
|
||||
fireChannelConnected(channel, channel.getRemoteAddress());
|
||||
|
||||
final String service = "Old I/O";
|
||||
final String category = "datagram worker";
|
||||
final String service = "OldIO";
|
||||
final String category = "DatagramWorker";
|
||||
final String comment = channel.toString();
|
||||
|
||||
if (!bound) {
|
||||
|
@ -176,7 +176,7 @@ class OioDatagramWorker implements Runnable {
|
||||
Thread workerThread = channel.workerThread;
|
||||
if (workerThread != null) {
|
||||
ThreadRenamingRunnable.renameThread(
|
||||
workerThread, "Old I/O", "datagram worker",
|
||||
workerThread, "OldIO", "DatagramWorker",
|
||||
((OioDatagramChannelFactory) channel.getFactory()).id + "-" + channel.getId(),
|
||||
channel.toString());
|
||||
}
|
||||
|
@ -151,7 +151,7 @@ class OioServerSocketPipelineSink extends AbstractChannelSink {
|
||||
new IoWorkerRunnable(
|
||||
new ThreadRenamingRunnable(
|
||||
new Boss(channel),
|
||||
"Old I/O", "server boss", String.valueOf(id),
|
||||
"OldIO", "ServerBoss", String.valueOf(id),
|
||||
channel.toString())));
|
||||
bossStarted = true;
|
||||
} catch (Throwable t) {
|
||||
@ -218,7 +218,7 @@ class OioServerSocketPipelineSink extends AbstractChannelSink {
|
||||
new IoWorkerRunnable(
|
||||
new ThreadRenamingRunnable(
|
||||
new OioWorker(acceptedChannel),
|
||||
"Old I/O", "server worker", id + "-" + acceptedChannel.getId(),
|
||||
"OldIO", "ServerWorker", id + "-" + acceptedChannel.getId(),
|
||||
acceptedChannel.toString())));
|
||||
} catch (Exception e) {
|
||||
logger.warn(
|
||||
|
@ -24,7 +24,9 @@ import org.jboss.netty.channel.ChannelPipelineFactory;
|
||||
import org.jboss.netty.example.securechat.SecureChatSslContextFactory;
|
||||
import org.jboss.netty.handler.codec.http.HttpClientCodec;
|
||||
import org.jboss.netty.handler.codec.http.HttpContentDecompressor;
|
||||
import org.jboss.netty.handler.logging.LoggingHandler;
|
||||
import org.jboss.netty.handler.ssl.SslHandler;
|
||||
import org.jboss.netty.logging.InternalLogLevel;
|
||||
|
||||
/**
|
||||
* @author <a href="http://www.jboss.org/netty/">The Netty Project</a>
|
||||
@ -45,6 +47,7 @@ public class HttpClientPipelineFactory implements ChannelPipelineFactory {
|
||||
// Create a default pipeline implementation.
|
||||
ChannelPipeline pipeline = pipeline();
|
||||
|
||||
pipeline.addLast("log", new LoggingHandler(InternalLogLevel.INFO));
|
||||
// Enable HTTPS if necessary.
|
||||
if (ssl) {
|
||||
SSLEngine engine =
|
||||
|
@ -22,6 +22,8 @@ import org.jboss.netty.channel.ChannelPipelineFactory;
|
||||
import org.jboss.netty.handler.codec.http.HttpContentCompressor;
|
||||
import org.jboss.netty.handler.codec.http.HttpRequestDecoder;
|
||||
import org.jboss.netty.handler.codec.http.HttpResponseEncoder;
|
||||
import org.jboss.netty.handler.logging.LoggingHandler;
|
||||
import org.jboss.netty.logging.InternalLogLevel;
|
||||
|
||||
/**
|
||||
* @author <a href="http://www.jboss.org/netty/">The Netty Project</a>
|
||||
@ -34,6 +36,7 @@ public class HttpServerPipelineFactory implements ChannelPipelineFactory {
|
||||
public ChannelPipeline getPipeline() throws Exception {
|
||||
// Create a default pipeline implementation.
|
||||
ChannelPipeline pipeline = pipeline();
|
||||
pipeline.addLast("log", new LoggingHandler(InternalLogLevel.INFO));
|
||||
|
||||
// Uncomment the following line if you want HTTPS
|
||||
//SSLEngine engine = SecureChatSslContextFactory.getServerContext().createSSLEngine();
|
||||
|
@ -211,7 +211,7 @@ public class HashedWheelTimer implements Timer {
|
||||
|
||||
workerThread = threadFactory.newThread(new ThreadRenamingRunnable(
|
||||
worker,
|
||||
"Hashed wheel timer", null,
|
||||
"HashedWheelTimer", null,
|
||||
String.valueOf(id.incrementAndGet()), null));
|
||||
|
||||
// Misuse check
|
||||
|
@ -15,6 +15,8 @@
|
||||
*/
|
||||
package org.jboss.netty.util;
|
||||
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.jboss.netty.logging.InternalLogger;
|
||||
import org.jboss.netty.logging.InternalLoggerFactory;
|
||||
|
||||
@ -38,6 +40,11 @@ public class ThreadRenamingRunnable implements Runnable {
|
||||
private static final InternalLogger logger =
|
||||
InternalLoggerFactory.getInstance(ThreadRenamingRunnable.class);
|
||||
|
||||
private static final Pattern SERVICE_PATTERN = Pattern.compile("[a-zA-Z0-9]*");
|
||||
private static final Pattern CATEGORY_PATTERN = SERVICE_PATTERN;
|
||||
private static final Pattern ID_PATTERN = Pattern.compile("^[-_a-zA-Z0-9]*$");
|
||||
|
||||
|
||||
private static volatile ThreadNameDeterminer threadNameDeterminer =
|
||||
ThreadNameDeterminer.PROPOSED;
|
||||
|
||||
@ -76,6 +83,8 @@ public class ThreadRenamingRunnable implements Runnable {
|
||||
throw new NullPointerException("thread");
|
||||
}
|
||||
|
||||
validateNameComponents(service, category, id);
|
||||
|
||||
// Normalize the parameters.
|
||||
service = service != null? service : "";
|
||||
category = category != null? category : "";
|
||||
@ -112,6 +121,26 @@ public class ThreadRenamingRunnable implements Runnable {
|
||||
return renamed;
|
||||
}
|
||||
|
||||
private static void validateNameComponents(String service, String category, String id) {
|
||||
if (service != null && !SERVICE_PATTERN.matcher(service).matches()) {
|
||||
throw new IllegalArgumentException(
|
||||
"service: " + service +
|
||||
" (expected: " + SERVICE_PATTERN.pattern() + ')');
|
||||
}
|
||||
|
||||
if (category != null && !CATEGORY_PATTERN.matcher(category).matches()) {
|
||||
throw new IllegalArgumentException(
|
||||
"category: " + category +
|
||||
" (expected: " + CATEGORY_PATTERN.pattern() + ')');
|
||||
}
|
||||
|
||||
if (id != null && !ID_PATTERN.matcher(id).matches()) {
|
||||
throw new IllegalArgumentException(
|
||||
"id: " + id +
|
||||
" (expected: " + ID_PATTERN.pattern() + ')');
|
||||
}
|
||||
}
|
||||
|
||||
private final Runnable runnable;
|
||||
private final String service;
|
||||
private final String category;
|
||||
@ -130,6 +159,7 @@ public class ThreadRenamingRunnable implements Runnable {
|
||||
throw new NullPointerException("runnable");
|
||||
}
|
||||
|
||||
validateNameComponents(service, category, id);
|
||||
this.runnable = runnable;
|
||||
this.service = service;
|
||||
this.category = category;
|
||||
|
Loading…
Reference in New Issue
Block a user