/** * Server shutdown. * * @throws Exception error */ public void stop() throws Exception { log.info("stopping thrift server {}", getServerName()); if (stopping.compareAndSet(false, true) && server != null) { log.debug("stopping serving"); server.stop(); log.debug("stopped serving"); } } }
private void startServing(final ExecutorService executorService, final TServerTransport serverTransport) { if (!stopping.get()) { final TThreadPoolServer.Args serverArgs = new TThreadPoolServer.Args(serverTransport) .processor(getProcessor()) .executorService(executorService); server = new TThreadPoolServer(serverArgs); if (hasServerEventHandler()) { server.setServerEventHandler(getServerEventHandler()); final String threadName = getServerName() + "-thread-#" + serverThreadCount.incrementAndGet(); new Thread(threadName) { @Override
/** * Server initialization. * * @throws Exception error */ public void start() throws Exception { log.info("initializing thrift server {}", getServerName()); final ThreadFactory threadFactory = new ThreadFactoryBuilder() .setNameFormat(threadPoolNameFormat) .setUncaughtExceptionHandler((t, e) -> log.error("Uncaught exception in thread: {}", t.getName(), e)) .build(); final ExecutorService executorService = new ThreadPoolExecutor( Math.min(2, config.getThriftServerMaxWorkerThreads()), config.getThriftServerMaxWorkerThreads(), 60L, TimeUnit.SECONDS, new SynchronousQueue<>(), threadFactory ); RegistryUtil.registerThreadPool(registry, threadPoolNameFormat, (ThreadPoolExecutor) executorService); final int timeout = config.getThriftServerSocketClientTimeoutInSeconds() * 1000; final TServerTransport serverTransport = new TServerSocket(portNumber, timeout); startServing(executorService, serverTransport); }
private void startServing(final ExecutorService executorService, final TServerTransport serverTransport) { if (!stopping.get()) { final TThreadPoolServer.Args serverArgs = new TThreadPoolServer.Args(serverTransport) .processor(getProcessor()) .executorService(executorService); server = new TThreadPoolServer(serverArgs); if (hasServerEventHandler()) { server.setServerEventHandler(getServerEventHandler()); final String threadName = getServerName() + "-thread-#" + serverThreadCount.incrementAndGet(); new Thread(threadName) { @Override
/** * Server initialization. * * @throws Exception error */ public void start() throws Exception { log.info("initializing thrift server {}", getServerName()); final ThreadFactory threadFactory = new ThreadFactoryBuilder() .setNameFormat(threadPoolNameFormat) .setUncaughtExceptionHandler((t, e) -> log.error("Uncaught exception in thread: {}", t.getName(), e)) .build(); final ExecutorService executorService = new ThreadPoolExecutor( Math.min(2, config.getThriftServerMaxWorkerThreads()), config.getThriftServerMaxWorkerThreads(), 60L, TimeUnit.SECONDS, new SynchronousQueue<>(), threadFactory ); RegistryUtil.registerThreadPool(registry, threadPoolNameFormat, (ThreadPoolExecutor) executorService); final int timeout = config.getThriftServerSocketClientTimeoutInSeconds() * 1000; final TServerTransport serverTransport = new TServerSocket(portNumber, timeout); startServing(executorService, serverTransport); }
/** * Server shutdown. * * @throws Exception error */ public void stop() throws Exception { log.info("stopping thrift server {}", getServerName()); if (stopping.compareAndSet(false, true) && server != null) { log.debug("stopping serving"); server.stop(); log.debug("stopped serving"); } } }
@Override public void run() { log.debug("starting serving"); try { server.serve(); } catch (Throwable t) { if (!stopping.get()) { log.error("Unexpected exception in {}. This probably " + "means that the worker pool was exhausted. " + "Increase 'metacat.thrift.server_max_worker_threads' " + "from {} or throttle the number of requests. " + "This server thread is not in a bad state so starting a new one.", getServerName(), config.getThriftServerMaxWorkerThreads(), t); startServing(executorService, serverTransport); } else { log.debug("stopping serving"); } } log.debug("started serving"); } }.start();
@Override public void run() { log.debug("starting serving"); try { server.serve(); } catch (Throwable t) { if (!stopping.get()) { log.error("Unexpected exception in {}. This probably " + "means that the worker pool was exhausted. " + "Increase 'metacat.thrift.server_max_worker_threads' " + "from {} or throttle the number of requests. " + "This server thread is not in a bad state so starting a new one.", getServerName(), config.getThriftServerMaxWorkerThreads(), t); startServing(executorService, serverTransport); } else { log.debug("stopping serving"); } } log.debug("started serving"); } }.start();