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

io.github.sinri.keel.web.tcp.KeelBasicSocketWrapper Maven / Gradle / Ivy

Go to download

A website framework with VERT.X for ex-PHP-ers, exactly Ark Framework Users.

There is a newer version: 3.2.20
Show newest version
package io.github.sinri.keel.web.tcp;

import io.vertx.core.Future;
import io.vertx.core.Handler;
import io.vertx.core.buffer.Buffer;
import io.vertx.core.net.NetSocket;

import java.util.function.Consumer;
import java.util.function.Function;

/**
 * @since 2.8
 */
public class KeelBasicSocketWrapper extends KeelAbstractSocketWrapper {
    private Function> incomingBufferProcessor = buffer -> {
        return Future.succeededFuture();
    };
    private Handler readToEndHandler = event -> {
    };
    private Handler drainHandler = event -> {
    };
    private Handler closeHandler = event -> {
    };
    private Consumer exceptionHandler = throwable -> {
    };

    public KeelBasicSocketWrapper(NetSocket socket) {
        super(socket);
    }

    public KeelBasicSocketWrapper(NetSocket socket, String socketID) {
        super(socket, socketID);
    }

    public KeelBasicSocketWrapper setCloseHandler(Handler closeHandler) {
        this.closeHandler = closeHandler;
        return this;
    }

    public KeelBasicSocketWrapper setDrainHandler(Handler drainHandler) {
        this.drainHandler = drainHandler;
        return this;
    }

    public KeelBasicSocketWrapper setExceptionHandler(Consumer exceptionHandler) {
        this.exceptionHandler = exceptionHandler;
        return this;
    }

    public KeelBasicSocketWrapper setIncomingBufferProcessor(Function> incomingBufferProcessor) {
        this.incomingBufferProcessor = incomingBufferProcessor;
        return this;
    }

    public KeelBasicSocketWrapper setReadToEndHandler(Handler readToEndHandler) {
        this.readToEndHandler = readToEndHandler;
        return this;
    }

    @Override
    protected Future whenBufferComes(Buffer incomingBuffer) {
        return incomingBufferProcessor.apply(incomingBuffer);
    }

    @Override
    protected void whenReadToEnd() {
        super.whenReadToEnd();
        readToEndHandler.handle(null);
    }

    @Override
    protected void whenDrain() {
        super.whenDrain();
        drainHandler.handle(null);
    }

    @Override
    protected void whenClose() {
        super.whenClose();
        closeHandler.handle(null);
    }

    @Override
    protected void whenExceptionOccurred(Throwable throwable) {
        super.whenExceptionOccurred(throwable);
        exceptionHandler.accept(throwable);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy