package com.its.pis.xnettcp;

import com.its.pis.config.SystemInfo;
import io.netty.bootstrap.ServerBootstrap;
import io.netty.channel.ChannelFuture;
import io.netty.channel.EventLoopGroup;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;

@Slf4j
@Getter
@Setter
@ToString
public abstract class TcpServerAbstract {

    @Autowired
    SystemInfo systemInfo;

    protected EventLoopGroup workerGroups = null;
    protected EventLoopGroup acceptGroups = null;
    protected ServerBootstrap serverBootstrap = null;
    protected ChannelFuture channelFuture = null;

    protected int getWorkerThreads() {
        return this.systemInfo.getCpuCores() * 2;
    }

    protected int getAcceptThreads() {
        int acceptThreads = getWorkerThreads() / 4;
        if (acceptThreads == 0) acceptThreads = 1;
        return acceptThreads;
    }
}
