java – What to use instead of apache.thrift server


In the legacy project it is used org.apache.thrift version 0.11.0. I want to give up the thrift server to some simple http server. This is current implementation of server.

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.thrift.TProcessor;
import org.apache.thrift.server.THsHaServer;
import org.apache.thrift.server.TServer;
import org.apache.thrift.transport.TNonblockingServerSocket;
import org.apache.thrift.transport.TTransportException;

import java.net.InetSocketAddress;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;


public class ThriftServer {
    private static final Logger LOG = LogManager.getLogger(ThriftServer.class);
    private static final int CORE_REQUEST_HANDLERS_COUNT = 100;
    private static final int MAX_REQUEST_HANDLERS_COUNT = 200;

    private final BlockingQueue workQueue = new LinkedBlockingQueue<>(1000);
    private final ThreadPoolExecutor handlersExecutor;
    private final InetSocketAddress address;
    private final TServer server;
    private Thread serverThread;

    public ThriftServer(String host, int port, TProcessor requestsProcessor) throws TTransportException {
        address = new InetSocketAddress(host, port);

        TNonblockingServerSocket serverSocket = new TNonblockingServerSocket(address);
        handlersExecutor = new ThreadPoolExecutor(CORE_REQUEST_HANDLERS_COUNT, MAX_REQUEST_HANDLERS_COUNT, 30, TimeUnit.MILLISECONDS, workQueue);
        THsHaServer.Args serverArgs = new THsHaServer.Args(serverSocket)
                .processor(requestsProcessor)
                .executorService(handlersExecutor);
        server = new THsHaServer(serverArgs);
    }

    public void startUp() {
        serverThread = new Thread(this::serve);
        serverThread.setPriority(Thread.MAX_PRIORITY);
        serverThread.start();
    }

    public void serve() {
        try {
            server.serve();
        } catch (Exception e) {
            LOG.error("Error occurred during serving", e);
        }
    }
}

Can you help me to refactor this class and remove apache.thrift as dependency. What to use instead of :

/**
 * An extension of the TNonblockingServer to a Half-Sync/Half-Async server.
 * Like TNonblockingServer, it relies on the use of TFramedTransport.
 */
public class THsHaServer extends TNonblockingServer {}

As a dependency there is a org.springframework version 5.0.20. Is it possible to use somehow this dependency?



Source link

Related Posts

About The Author

Add Comment