NettyRuntime Class — netty Architecture
Architecture documentation for the NettyRuntime class in NettyRuntime.java from the netty codebase.
Entity Profile
Dependency Diagram
graph TD 69a957f6_adc0_0d4a_cf58_333f00b7d245["NettyRuntime"] 883e532e_3203_7d89_be8d_632292f3409b["NettyRuntime.java"] 69a957f6_adc0_0d4a_cf58_333f00b7d245 -->|defined in| 883e532e_3203_7d89_be8d_632292f3409b 094d9bde_be28_f3ef_01ca_27676083ed4a["setAvailableProcessors()"] 69a957f6_adc0_0d4a_cf58_333f00b7d245 -->|method| 094d9bde_be28_f3ef_01ca_27676083ed4a 5ef0f8aa_5a52_2687_4947_172c9d591e53["availableProcessors()"] 69a957f6_adc0_0d4a_cf58_333f00b7d245 -->|method| 5ef0f8aa_5a52_2687_4947_172c9d591e53 ead40c07_54ba_0f72_d907_c34209a8f70e["NettyRuntime()"] 69a957f6_adc0_0d4a_cf58_333f00b7d245 -->|method| ead40c07_54ba_0f72_d907_c34209a8f70e
Relationship Graph
Source Code
common/src/main/java/io/netty/util/NettyRuntime.java lines 27–106
public final class NettyRuntime {
/**
* Holder class for available processors to enable testing.
*/
static class AvailableProcessorsHolder {
private int availableProcessors;
/**
* Set the number of available processors.
*
* @param availableProcessors the number of available processors
* @throws IllegalArgumentException if the specified number of available processors is non-positive
* @throws IllegalStateException if the number of available processors is already configured
*/
synchronized void setAvailableProcessors(final int availableProcessors) {
ObjectUtil.checkPositive(availableProcessors, "availableProcessors");
if (this.availableProcessors != 0) {
final String message = String.format(
Locale.ROOT,
"availableProcessors is already set to [%d], rejecting [%d]",
this.availableProcessors,
availableProcessors);
throw new IllegalStateException(message);
}
this.availableProcessors = availableProcessors;
}
/**
* Get the configured number of available processors. The default is {@link Runtime#availableProcessors()}.
* This can be overridden by setting the system property "io.netty.availableProcessors" or by invoking
* {@link #setAvailableProcessors(int)} before any calls to this method.
*
* @return the configured number of available processors
*/
@SuppressForbidden(reason = "to obtain default number of available processors")
synchronized int availableProcessors() {
if (this.availableProcessors == 0) {
final int availableProcessors =
SystemPropertyUtil.getInt(
"io.netty.availableProcessors",
Runtime.getRuntime().availableProcessors());
setAvailableProcessors(availableProcessors);
}
return this.availableProcessors;
}
}
private static final AvailableProcessorsHolder holder = new AvailableProcessorsHolder();
/**
* Set the number of available processors.
*
* @param availableProcessors the number of available processors
* @throws IllegalArgumentException if the specified number of available processors is non-positive
* @throws IllegalStateException if the number of available processors is already configured
*/
@SuppressWarnings("unused,WeakerAccess") // this method is part of the public API
public static void setAvailableProcessors(final int availableProcessors) {
holder.setAvailableProcessors(availableProcessors);
}
/**
* Get the configured number of available processors. The default is {@link Runtime#availableProcessors()}. This
* can be overridden by setting the system property "io.netty.availableProcessors" or by invoking
* {@link #setAvailableProcessors(int)} before any calls to this method.
*
* @return the configured number of available processors
*/
public static int availableProcessors() {
return holder.availableProcessors();
}
/**
* No public constructor to prevent instances from being created.
*/
private NettyRuntime() {
}
}
Source
Frequently Asked Questions
What is the NettyRuntime class?
NettyRuntime is a class in the netty codebase, defined in common/src/main/java/io/netty/util/NettyRuntime.java.
Where is NettyRuntime defined?
NettyRuntime is defined in common/src/main/java/io/netty/util/NettyRuntime.java at line 27.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free