org.zodiac.sdk.simplenetty.channel.AbstractNioChannel Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of zodiac-sdk-nio Show documentation
Show all versions of zodiac-sdk-nio Show documentation
Zodiac SDK NIO2(New Non-Blocking IO)
package org.zodiac.sdk.simplenetty.channel;
import java.nio.channels.SelectionKey;
import org.zodiac.sdk.simplenetty.concurrent.ChannelFuture;
import org.zodiac.sdk.simplenetty.concurrent.DefaultChannelPromise;
import org.zodiac.sdk.simplenetty.core.*;
import org.zodiac.sdk.simplenetty.handler.ChannelHandlerContext;
import org.zodiac.sdk.simplenetty.handler.ChannelPipeline;
public abstract class AbstractNioChannel implements Channel {
AbstractEventLoop eventLoop;
SelectionKey key;
ChannelHandlerContext context;
public AbstractNioChannel(EventLoop loop) {
this.eventLoop = (AbstractEventLoop)loop;
// this.channelConfig = channelConfig;
}
@Override
public EventLoop eventLoop() {
return eventLoop;
}
@Override
public ChannelFuture closeFuture() {
EventExecutor eventExecutor = new EventExecutor();
DefaultChannelPromise promise = new DefaultChannelPromise<>(eventExecutor, this, false);
new Thread(() -> {
eventExecutor.execute(() -> {
while (this.isActive()) {
try {
synchronized (eventLoop.getExecutor()) {
eventLoop.getExecutor().wait();
}
} catch (InterruptedException ignore) {
}
}
promise.success(null);
return promise;
});
}).start();
return promise;
}
@Override
public ChannelPipeline pipeline() {
return context.pipeline();
}
}