From 6b801ed0c43df2fe9db1ff93ea9f11522eb1bc14 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Fri, 24 Feb 2023 16:56:25 +0100 Subject: [server] Add JSON/HTTP listener for thrift --- .../src/main/java/org/openslx/bwlp/sat/App.java | 37 +++++++++++++++------- 1 file changed, 26 insertions(+), 11 deletions(-) (limited to 'dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/App.java') diff --git a/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/App.java b/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/App.java index e98f4d23..3b1a8de6 100644 --- a/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/App.java +++ b/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/App.java @@ -6,6 +6,9 @@ import java.security.NoSuchAlgorithmException; import java.sql.SQLException; import java.util.HashSet; import java.util.Set; +import java.util.concurrent.ArrayBlockingQueue; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.TimeUnit; import javax.net.ssl.SSLContext; @@ -25,6 +28,7 @@ import org.openslx.bwlp.sat.maintenance.DeleteOldUsers; import org.openslx.bwlp.sat.maintenance.MailFlusher; import org.openslx.bwlp.sat.maintenance.SendExpireWarning; import org.openslx.bwlp.sat.thrift.BinaryListener; +import org.openslx.bwlp.sat.thrift.JsonHttpListener; import org.openslx.bwlp.sat.thrift.cache.OperatingSystemList; import org.openslx.bwlp.sat.thrift.cache.OrganizationList; import org.openslx.bwlp.sat.thrift.cache.VirtualizerList; @@ -36,6 +40,8 @@ import org.openslx.sat.thrift.version.Version; import org.openslx.thrifthelper.ThriftManager; import org.openslx.thrifthelper.ThriftManager.ErrorCallback; import org.openslx.util.AppUtil; +import org.openslx.util.GrowingThreadPoolExecutor; +import org.openslx.util.PrioThreadFactory; import org.openslx.util.QuickTimer; public class App { @@ -46,12 +52,13 @@ public class App { private static final Set failFastMethods = new HashSet<>(); - public static void main(String[] args) throws TTransportException, NoSuchAlgorithmException, IOException, - KeyManagementException - { + public static void main(String[] args) + throws TTransportException, NoSuchAlgorithmException, IOException, KeyManagementException { System.setProperty("mariadb.logging.disable", "true"); // setup basic logging appender to log output on console if no external appender (log4j.properties) is configured - if (org.apache.logging.log4j.core.Logger.class.cast(LogManager.getRootLogger()).getAppenders().isEmpty()) { + if (org.apache.logging.log4j.core.Logger.class.cast(LogManager.getRootLogger()) + .getAppenders() + .isEmpty()) { Configurator.initialize(new DefaultConfiguration()); } @@ -100,11 +107,10 @@ public class App { if (t instanceof TInvalidTokenException) return false; if (((TException) t).getCause() == null) { - LOGGER.info("Thrift error " + t.toString() + " for " - + method + ", retrying..."); + LOGGER.info("Thrift error " + t.toString() + " for " + method + ", retrying..."); } else { - LOGGER.info("Thrift error " + ((TException) t).getCause().toString() + " for " - + method + ", retrying..."); + LOGGER.info("Thrift error " + ((TException) t).getCause().toString() + " for " + method + + ", retrying..."); } try { Thread.sleep(failCount * 250); @@ -157,20 +163,29 @@ public class App { DeleteOldLectures.init(); DeleteOldUsers.init(); + // Shared executor for SSL thrift and HTTP thrift + ExecutorService es = new GrowingThreadPoolExecutor(3, 128, 1, TimeUnit.MINUTES, + new ArrayBlockingQueue(4), new PrioThreadFactory("SSL")); + // Start Thrift Server Thread t; // Plain - t = new Thread(new BinaryListener(9090, false)); + t = new Thread(new BinaryListener(9090, false, null)); t.setDaemon(true); t.start(); // SSL - t = new Thread(new BinaryListener(9091, true)); + t = new Thread(new BinaryListener(9091, true, es)); t.start(); - // Start httpd + // Start RPC httpd t = new Thread(new WebServer(9080)); t.setDaemon(true); t.start(); + // Start RPC httpd + t = new Thread(new JsonHttpListener(9081, es)); + t.setDaemon(true); + t.start(); + Runtime.getRuntime().addShutdownHook(new Thread() { @Override public void run() { -- cgit v1.2.3-55-g7522