DefaultEventExecutorChooserFactory Class — netty Architecture
Architecture documentation for the DefaultEventExecutorChooserFactory class in DefaultEventExecutorChooserFactory.java from the netty codebase.
Entity Profile
Dependency Diagram
graph TD 4324ff8a_5f85_b180_7755_99e262ae1a02["DefaultEventExecutorChooserFactory"] e9573f02_fa38_a523_6328_d0056df7c09f["DefaultEventExecutorChooserFactory.java"] 4324ff8a_5f85_b180_7755_99e262ae1a02 -->|defined in| e9573f02_fa38_a523_6328_d0056df7c09f e86b9959_640d_3733_c8ef_7598940ac06e["DefaultEventExecutorChooserFactory()"] 4324ff8a_5f85_b180_7755_99e262ae1a02 -->|method| e86b9959_640d_3733_c8ef_7598940ac06e 06b91eee_f662_862f_1811_05cf3cd21aa6["EventExecutorChooser()"] 4324ff8a_5f85_b180_7755_99e262ae1a02 -->|method| 06b91eee_f662_862f_1811_05cf3cd21aa6 91790bfd_f1e9_a4ee_d5b2_8cd97e2b14a1["isPowerOfTwo()"] 4324ff8a_5f85_b180_7755_99e262ae1a02 -->|method| 91790bfd_f1e9_a4ee_d5b2_8cd97e2b14a1
Relationship Graph
Source Code
common/src/main/java/io/netty/util/concurrent/DefaultEventExecutorChooserFactory.java lines 24–73
public final class DefaultEventExecutorChooserFactory implements EventExecutorChooserFactory {
public static final DefaultEventExecutorChooserFactory INSTANCE = new DefaultEventExecutorChooserFactory();
private DefaultEventExecutorChooserFactory() { }
@Override
public EventExecutorChooser newChooser(EventExecutor[] executors) {
if (isPowerOfTwo(executors.length)) {
return new PowerOfTwoEventExecutorChooser(executors);
} else {
return new GenericEventExecutorChooser(executors);
}
}
private static boolean isPowerOfTwo(int val) {
return (val & -val) == val;
}
private static final class PowerOfTwoEventExecutorChooser implements EventExecutorChooser {
private final AtomicInteger idx = new AtomicInteger();
private final EventExecutor[] executors;
PowerOfTwoEventExecutorChooser(EventExecutor[] executors) {
this.executors = executors;
}
@Override
public EventExecutor next() {
return executors[idx.getAndIncrement() & executors.length - 1];
}
}
private static final class GenericEventExecutorChooser implements EventExecutorChooser {
// Use a 'long' counter to avoid non-round-robin behaviour at the 32-bit overflow boundary.
// The 64-bit long solves this by placing the overflow so far into the future, that no system
// will encounter this in practice.
private final AtomicLong idx = new AtomicLong();
private final EventExecutor[] executors;
GenericEventExecutorChooser(EventExecutor[] executors) {
this.executors = executors;
}
@Override
public EventExecutor next() {
return executors[(int) Math.abs(idx.getAndIncrement() % executors.length)];
}
}
}
Source
Frequently Asked Questions
What is the DefaultEventExecutorChooserFactory class?
DefaultEventExecutorChooserFactory is a class in the netty codebase, defined in common/src/main/java/io/netty/util/concurrent/DefaultEventExecutorChooserFactory.java.
Where is DefaultEventExecutorChooserFactory defined?
DefaultEventExecutorChooserFactory is defined in common/src/main/java/io/netty/util/concurrent/DefaultEventExecutorChooserFactory.java at line 24.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free