private static long lowMemoryThreshold() { if (lowMemoryThreshold < 0) // not yet initialised lowMemoryThreshold = (long) MaryProperties.getInteger("mary.lowmemory", 10000000); return lowMemoryThreshold; }
public void run() { logger.info("Starting server."); int localPort = MaryProperties.needInteger("socket.port"); HttpParams params = new BasicHttpParams(); params .setIntParameter(CoreConnectionPNames.SO_TIMEOUT, 0) // 0 means no timeout, any positive value means time out in miliseconds (i.e. 50000 for 50 // seconds) .setIntParameter(CoreConnectionPNames.SOCKET_BUFFER_SIZE, 8 * 1024) .setBooleanParameter(CoreConnectionPNames.STALE_CONNECTION_CHECK, false) .setBooleanParameter(CoreConnectionPNames.TCP_NODELAY, true) .setParameter(CoreProtocolPNames.ORIGIN_SERVER, "HttpComponents/1.1"); BasicHttpProcessor httpproc = new BasicHttpProcessor(); httpproc.addInterceptor(new ResponseDate()); httpproc.addInterceptor(new ResponseServer()); httpproc.addInterceptor(new ResponseContent()); httpproc.addInterceptor(new ResponseConnControl()); BufferingHttpServiceHandler handler = new BufferingHttpServiceHandler( httpproc, new DefaultHttpResponseFactory(), new DefaultConnectionReuseStrategy(), params); // Set up request handlers HttpRequestHandlerRegistry registry = new HttpRequestHandlerRegistry(); registry.register("/process", new SynthesisRequestHandler()); InfoRequestHandler infoRH = new InfoRequestHandler(); registry.register("/version", infoRH); registry.register("/datatypes", infoRH); registry.register("/locales", infoRH); registry.register("/voices", infoRH); registry.register("/audioformats", infoRH); registry.register("/exampletext", infoRH); registry.register("/audioeffects", infoRH); registry.register("/audioeffect-default-param", infoRH); registry.register("/audioeffect-full", infoRH); registry.register("/audioeffect-help", infoRH); registry.register("/audioeffect-is-hmm-effect", infoRH); registry.register("/features", infoRH); registry.register("/features-discrete", infoRH); registry.register("/vocalizations", infoRH); registry.register("/styles", infoRH); registry.register("*", new FileRequestHandler()); handler.setHandlerResolver(registry); // Provide an event logger handler.setEventListener(new EventLogger()); IOEventDispatch ioEventDispatch = new DefaultServerIOEventDispatch(handler, params); int numParallelThreads = MaryProperties.getInteger("server.http.parallelthreads", 5); logger.info("Waiting for client to connect on port " + localPort); try { ListeningIOReactor ioReactor = new DefaultListeningIOReactor(numParallelThreads, params); ioReactor.listen(new InetSocketAddress(localPort)); isReady = true; ioReactor.execute(ioEventDispatch); } catch (InterruptedIOException ex) { logger.info("Interrupted", ex); } catch (IOException e) { logger.info("Problem with HTTP connection", e); } logger.debug("Shutdown"); }