This commit is contained in:
Trustin Lee 2009-06-17 05:39:19 +00:00
parent 28511fcb9e
commit 8b5a652883
4 changed files with 26 additions and 14 deletions

View File

@ -23,6 +23,9 @@
package org.jboss.netty.util;
/**
* A utility class that provides the convenient shutdown of
* {@link ExternalResourceReleasable}s.
*
* @author The Netty Project (netty-dev@lists.jboss.org)
* @author Trustin Lee (tlee@redhat.com)
* @version $Rev$, $Date$

View File

@ -22,8 +22,6 @@
*/
package org.jboss.netty.util;
import org.jboss.netty.handler.execution.MemoryAwareThreadPoolExecutor;
import org.jboss.netty.handler.execution.OrderedMemoryAwareThreadPoolExecutor;
/**
* Estimates the size of an object in bytes.
@ -32,15 +30,14 @@ import org.jboss.netty.handler.execution.OrderedMemoryAwareThreadPoolExecutor;
* @author Trustin Lee (tlee@redhat.com)
*
* @version $Rev$, $Date$
*
*/
public interface ObjectSizeEstimator {
/**
* Returns the estimated size of the specified object in bytes.
* This method must be implemented to return the same value for the same
* object. {@link MemoryAwareThreadPoolExecutor} and
* {@link OrderedMemoryAwareThreadPoolExecutor} will malfunction otherwise.
*
* @return a positive integer which represents the size of the specified
* object in bytes
*/
int estimateSize(Object o);
}

View File

@ -23,10 +23,22 @@
package org.jboss.netty.util;
/**
* Overrides the thread name proposed by {@link ThreadRenamingRunnable}.
*
* @author The Netty Project (netty-dev@lists.jboss.org)
* @author Trustin Lee (tlee@redhat.com)
* @version $Rev$, $Date$
*/
public interface ThreadNameDeterminer {
String determineThreadName(String oldThreadName, String proposedThreadName) throws Exception;
/**
* Overrides the thread name proposed by {@link ThreadRenamingRunnable}.
*
* @param currentThreadName the current thread name
* @param proposedThreadName the proposed new thread name
* @return the actual new thread name.
* If {@code null} is returned, the proposed thread name is
* discarded (i.e. no rename).
*/
String determineThreadName(String currentThreadName, String proposedThreadName) throws Exception;
}

View File

@ -27,8 +27,8 @@ import org.jboss.netty.logging.InternalLoggerFactory;
/**
* Meta {@link Runnable} that changes the current thread name and reverts it
* back when its execution ends.
* A {@link Runnable} that changes the current thread name and reverts it back
* when its execution ends.
*
* @author The Netty Project (netty-dev@lists.jboss.org)
* @author Trustin Lee (tlee@redhat.com)
@ -50,7 +50,7 @@ public class ThreadRenamingRunnable implements Runnable {
};
/**
* Returns the {@link ThreadNameDeterminer} which is used to determine the
* Returns the {@link ThreadNameDeterminer} which overrides the proposed
* new thread name.
*/
public static ThreadNameDeterminer getThreadNameDeterminer() {
@ -58,7 +58,7 @@ public class ThreadRenamingRunnable implements Runnable {
}
/**
* Sets the {@link ThreadNameDeterminer} which is used to determine the new
* Sets the {@link ThreadNameDeterminer} which overrides the proposed new
* thread name.
*/
public static void setThreadNameDeterminer(ThreadNameDeterminer threadNameDeterminer) {
@ -117,17 +117,17 @@ public class ThreadRenamingRunnable implements Runnable {
}
}
private String getNewThreadName(String oldThreadName) {
private String getNewThreadName(String currentThreadName) {
String newThreadName = null;
try {
newThreadName =
getThreadNameDeterminer().determineThreadName(
oldThreadName, proposedThreadName);
currentThreadName, proposedThreadName);
} catch (Throwable t) {
logger.warn("Failed to determine the thread name", t);
}
return newThreadName == null? oldThreadName : newThreadName;
return newThreadName == null? currentThreadName : newThreadName;
}
}