All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.zodiac.sdk.simplenetty.channel.AbstractNioChannel Maven / Gradle / Ivy

There is a newer version: 1.6.8
Show newest version
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();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy