LocalIoHandler Class — netty Architecture
Architecture documentation for the LocalIoHandler class in LocalIoHandler.java from the netty codebase.
Entity Profile
Dependency Diagram
graph TD e3950750_3868_3ca4_8f61_b48a1a74312e["LocalIoHandler"] 88851f73_e942_d811_8305_35c4ce757ab4["LocalIoHandler.java"] e3950750_3868_3ca4_8f61_b48a1a74312e -->|defined in| 88851f73_e942_d811_8305_35c4ce757ab4 87a83bf2_f524_f66c_9609_e724ef8dc396["LocalIoHandler()"] e3950750_3868_3ca4_8f61_b48a1a74312e -->|method| 87a83bf2_f524_f66c_9609_e724ef8dc396 6fe19f5d_7ba1_3ff9_37be_22ea1a8e31c1["IoHandlerFactory()"] e3950750_3868_3ca4_8f61_b48a1a74312e -->|method| 6fe19f5d_7ba1_3ff9_37be_22ea1a8e31c1 20171ee5_dd8a_9b9e_edcb_596f04e0950d["LocalIoHandle()"] e3950750_3868_3ca4_8f61_b48a1a74312e -->|method| 20171ee5_dd8a_9b9e_edcb_596f04e0950d 1b80a13a_54d9_f16b_15cf_d9600d573185["run()"] e3950750_3868_3ca4_8f61_b48a1a74312e -->|method| 1b80a13a_54d9_f16b_15cf_d9600d573185 93a37c09_c389_c6e8_8557_99810c78bd4a["wakeup()"] e3950750_3868_3ca4_8f61_b48a1a74312e -->|method| 93a37c09_c389_c6e8_8557_99810c78bd4a 2d3bde50_404b_94fb_fad2_63b874c195f9["prepareToDestroy()"] e3950750_3868_3ca4_8f61_b48a1a74312e -->|method| 2d3bde50_404b_94fb_fad2_63b874c195f9 617569ff_f708_f3d7_9e55_25fc6cbc1ef0["destroy()"] e3950750_3868_3ca4_8f61_b48a1a74312e -->|method| 617569ff_f708_f3d7_9e55_25fc6cbc1ef0 be283ae1_8160_70d8_850c_2986cc62068f["IoRegistration()"] e3950750_3868_3ca4_8f61_b48a1a74312e -->|method| be283ae1_8160_70d8_850c_2986cc62068f c333fe0e_e715_614e_fa6b_e0887da8a00f["isCompatible()"] e3950750_3868_3ca4_8f61_b48a1a74312e -->|method| c333fe0e_e715_614e_fa6b_e0887da8a00f
Relationship Graph
Source Code
transport/src/main/java/io/netty/channel/local/LocalIoHandler.java lines 33–155
public final class LocalIoHandler implements IoHandler {
private final Set<LocalIoHandle> registeredChannels = new HashSet<LocalIoHandle>(64);
private final ThreadAwareExecutor executor;
private volatile Thread executionThread;
private LocalIoHandler(ThreadAwareExecutor executor) {
this.executor = Objects.requireNonNull(executor, "executor");
}
/**
* Returns a new {@link IoHandlerFactory} that creates {@link LocalIoHandler} instances.
*/
public static IoHandlerFactory newFactory() {
return LocalIoHandler::new;
}
private static LocalIoHandle cast(IoHandle handle) {
if (handle instanceof LocalIoHandle) {
return (LocalIoHandle) handle;
}
throw new IllegalArgumentException("IoHandle of type " + StringUtil.simpleClassName(handle) + " not supported");
}
@Override
public int run(IoHandlerContext context) {
if (executionThread == null) {
executionThread = Thread.currentThread();
}
if (context.canBlock()) {
// Just block until there is a task ready to process or wakeup(...) is called.
LockSupport.parkNanos(this, context.delayNanos(System.nanoTime()));
}
if (context.shouldReportActiveIoTime()) {
context.reportActiveIoTime(0);
}
return 0;
}
@Override
public void wakeup() {
if (!executor.isExecutorThread(Thread.currentThread())) {
Thread thread = executionThread;
if (thread != null) {
// Wakeup if we block at the moment.
LockSupport.unpark(thread);
}
}
}
@Override
public void prepareToDestroy() {
for (LocalIoHandle handle : registeredChannels) {
handle.closeNow();
}
registeredChannels.clear();
}
@Override
public void destroy() {
}
@Override
public IoRegistration register(IoHandle handle) {
LocalIoHandle localHandle = cast(handle);
if (registeredChannels.add(localHandle)) {
LocalIoRegistration registration = new LocalIoRegistration(executor, localHandle);
localHandle.registered();
return registration;
}
throw new IllegalStateException();
}
@Override
public boolean isCompatible(Class<? extends IoHandle> handleType) {
return LocalIoHandle.class.isAssignableFrom(handleType);
}
private final class LocalIoRegistration implements IoRegistration {
private final AtomicBoolean canceled = new AtomicBoolean();
private final ThreadAwareExecutor executor;
Source
Frequently Asked Questions
What is the LocalIoHandler class?
LocalIoHandler is a class in the netty codebase, defined in transport/src/main/java/io/netty/channel/local/LocalIoHandler.java.
Where is LocalIoHandler defined?
LocalIoHandler is defined in transport/src/main/java/io/netty/channel/local/LocalIoHandler.java at line 33.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free