org.eclipse.jetty.util.thread.ExecutorThreadPool Java Examples
The following examples show how to use
org.eclipse.jetty.util.thread.ExecutorThreadPool.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: EmbeddedServer.java From atlas with Apache License 2.0 | 6 votes |
public EmbeddedServer(String host, int port, String path) throws IOException { int queueSize = AtlasConfiguration.WEBSERVER_QUEUE_SIZE.getInt(); LinkedBlockingQueue<Runnable> queue = new LinkedBlockingQueue<>(queueSize); int minThreads = AtlasConfiguration.WEBSERVER_MIN_THREADS.getInt(); int maxThreads = AtlasConfiguration.WEBSERVER_MAX_THREADS.getInt(); long keepAliveTime = AtlasConfiguration.WEBSERVER_KEEPALIVE_SECONDS.getLong(); ExecutorThreadPool pool = new ExecutorThreadPool(minThreads, maxThreads, keepAliveTime, TimeUnit.SECONDS, queue); server = new Server(pool); Connector connector = getConnector(host, port); server.addConnector(connector); WebAppContext application = getWebAppContext(path); server.setHandler(application); }
Example #2
Source File: EmbeddedServer.java From incubator-atlas with Apache License 2.0 | 6 votes |
public EmbeddedServer(int port, String path) throws IOException { int queueSize = AtlasConfiguration.WEBSERVER_QUEUE_SIZE.getInt(); LinkedBlockingQueue<Runnable> queue = new LinkedBlockingQueue<>(queueSize); int minThreads = AtlasConfiguration.WEBSERVER_MIN_THREADS.getInt(); int maxThreads = AtlasConfiguration.WEBSERVER_MAX_THREADS.getInt(); long keepAliveTime = AtlasConfiguration.WEBSERVER_KEEPALIVE_SECONDS.getLong(); ExecutorThreadPool pool = new ExecutorThreadPool(minThreads, maxThreads, keepAliveTime, TimeUnit.SECONDS, queue); server = new Server(pool); Connector connector = getConnector(port); server.addConnector(connector); WebAppContext application = getWebAppContext(path); server.setHandler(application); }
Example #3
Source File: JettyServletContainer.java From TVRemoteIME with GNU General Public License v2.0 | 5 votes |
@Override synchronized public void setExecutorService(ExecutorService executorService) { if (INSTANCE.server.getThreadPool() == null) { INSTANCE.server.setThreadPool(new ExecutorThreadPool(executorService) { @Override protected void doStop() throws Exception { // Do nothing, don't shut down the Cling ExecutorService when Jetty stops! } }); } }
Example #4
Source File: StreamClientImpl.java From TVRemoteIME with GNU General Public License v2.0 | 5 votes |
public StreamClientImpl(StreamClientConfigurationImpl configuration) throws InitializationException { this.configuration = configuration; log.info("Starting Jetty HttpClient..."); client = new HttpClient(); // Jetty client needs threads for its internal expiration routines, which we don't need but // can't disable, so let's abuse the request executor service for this client.setThreadPool( new ExecutorThreadPool(getConfiguration().getRequestExecutorService()) { @Override protected void doStop() throws Exception { // Do nothing, don't shut down the Cling ExecutorService when Jetty stops! } } ); // These are some safety settings, we should never run into these timeouts as we // do our own expiration checking client.setTimeout((configuration.getTimeoutSeconds()+5) * 1000); client.setConnectTimeout((configuration.getTimeoutSeconds()+5) * 1000); client.setMaxRetries(configuration.getRequestRetryCount()); try { client.start(); } catch (Exception ex) { throw new InitializationException( "Could not start Jetty HTTP client: " + ex, ex ); } }
Example #5
Source File: TraderUMainConfiguration.java From java-trader with Apache License 2.0 | 5 votes |
@Bean public ConfigurableServletWebServerFactory webServerFactory() { JettyServletWebServerFactory factory = new JettyServletWebServerFactory(); int port = ConfigUtil.getInt("/BasisService/web.httpPort", 10080); factory.setPort(port); factory.setContextPath(""); factory.addErrorPages(new ErrorPage(HttpStatus.NOT_FOUND, "/notfound.html")); factory.setSelectors(1); factory.setAcceptors(1); factory.setThreadPool(new ExecutorThreadPool(executorService())); return factory; }
Example #6
Source File: TraderMainConfiguration.java From java-trader with Apache License 2.0 | 5 votes |
@Bean public ConfigurableServletWebServerFactory webServerFactory() { JettyServletWebServerFactory factory = new JettyServletWebServerFactory(); int port = ConfigUtil.getInt("/BasisService/web.httpPort", 10080); factory.setPort(port); factory.setContextPath(""); factory.addErrorPages(new ErrorPage(HttpStatus.NOT_FOUND, "/notfound.html")); factory.setSelectors(1); factory.setAcceptors(1); factory.setThreadPool(new ExecutorThreadPool(executorService())); return factory; }
Example #7
Source File: JettyServer.java From sumk with Apache License 2.0 | 5 votes |
protected synchronized void init() { try { buildJettyProperties(); server = new Server(new ExecutorThreadPool(HttpExcutors.getThreadPool())); ServerConnector connector = this.createConnector(); Logs.http().info("listen port: {}", port); String host = StartContext.httpHost(); if (host != null && host.length() > 0) { connector.setHost(host); } connector.setPort(port); server.setConnectors(new Connector[] { connector }); ServletContextHandler context = createServletContextHandler(); context.setContextPath(AppInfo.get("sumk.jetty.web.root", "/")); context.addEventListener(new SumkLoaderListener()); addUserListener(context, Arrays.asList(ServletContextListener.class, ContextScopeListener.class)); String resourcePath = AppInfo.get("sumk.jetty.resource"); if (StringUtil.isNotEmpty(resourcePath)) { ResourceHandler resourceHandler = JettyHandlerSupplier.resourceHandlerSupplier().get(); if (resourceHandler != null) { resourceHandler.setResourceBase(resourcePath); context.insertHandler(resourceHandler); } } if (AppInfo.getBoolean("sumk.jetty.session.enable", false)) { SessionHandler h = JettyHandlerSupplier.sessionHandlerSupplier().get(); if (h != null) { context.insertHandler(h); } } server.setHandler(context); } catch (Throwable e) { Log.printStack("sumk.http", e); System.exit(1); } }
Example #8
Source File: AndroidJettyServletContainer.java From BeyondUPnP with Apache License 2.0 | 5 votes |
@Override synchronized public void setExecutorService(ExecutorService executorService) { if (INSTANCE.server.getThreadPool() == null) { INSTANCE.server.setThreadPool(new ExecutorThreadPool(executorService) { @Override protected void doStop() throws Exception { // Do nothing, don't shut down the Cling ExecutorService when Jetty stops! } }); } }
Example #9
Source File: JettyServletContainer.java From DroidDLNA with GNU General Public License v3.0 | 5 votes |
@Override synchronized public void setExecutorService(ExecutorService executorService) { if (INSTANCE.server.getThreadPool() == null) { INSTANCE.server.setThreadPool(new ExecutorThreadPool(executorService) { @Override protected void doStop() throws Exception { // Do nothing, don't shut down the Cling ExecutorService when Jetty stops! } }); } }
Example #10
Source File: StreamClientImpl.java From DroidDLNA with GNU General Public License v3.0 | 5 votes |
public StreamClientImpl(StreamClientConfigurationImpl configuration) throws InitializationException { this.configuration = configuration; log.info("Starting Jetty HttpClient..."); client = new HttpClient(); // Jetty client needs threads for its internal expiration routines, which we don't need but // can't disable, so let's abuse the request executor service for this client.setThreadPool( new ExecutorThreadPool(getConfiguration().getRequestExecutorService()) { @Override protected void doStop() throws Exception { // Do nothing, don't shut down the Cling ExecutorService when Jetty stops! } } ); // These are some safety settings, we should never run into these timeouts as we // do our own expiration checking client.setTimeout((configuration.getTimeoutSeconds()+5) * 1000); client.setConnectTimeout((configuration.getTimeoutSeconds()+5) * 1000); client.setMaxRetries(configuration.getRequestRetryCount()); try { client.start(); } catch (Exception ex) { throw new InitializationException( "Could not start Jetty HTTP client: " + ex, ex ); } }
Example #11
Source File: JettyServer.java From open-capacity-platform with Apache License 2.0 | 4 votes |
public void start(final int port, final String ip, final String appName) throws Exception { thread = new Thread(new Runnable() { @Override public void run() { // The Server server = new Server(new ExecutorThreadPool()); // 非阻塞 // HTTP connector ServerConnector connector = new ServerConnector(server); if (ip!=null && ip.trim().length()>0) { connector.setHost(ip); // The network interface this connector binds to as an IP address or a hostname. If null or 0.0.0.0, then bind to all interfaces. } connector.setPort(port); server.setConnectors(new Connector[]{connector}); // Set a handler HandlerCollection handlerc =new HandlerCollection(); handlerc.setHandlers(new Handler[]{new JettyServerHandler()}); server.setHandler(handlerc); try { // Start server server.start(); logger.info(">>>>>>>>>>> xxl-job jetty server start success at port:{}.", port); // Start Registry-Server ExecutorRegistryThread.getInstance().start(port, ip, appName); // Start Callback-Server TriggerCallbackThread.getInstance().start(); server.join(); // block until thread stopped logger.info(">>>>>>>>>>> xxl-rpc server join success, netcon={}, port={}", JettyServer.class.getName(), port); } catch (Exception e) { logger.error(e.getMessage(), e); } finally { //destroy(); } } }); thread.setDaemon(true); // daemon, service jvm, user thread leave >>> daemon leave >>> jvm leave thread.start(); }
Example #12
Source File: HttpServer.java From arcusplatform with Apache License 2.0 | 4 votes |
public static void start() { try { DefaultContext main = new DefaultContext(); String base = StorageService.getFile("agent:///www").getPath(); org.eclipse.jetty.servlet.DefaultServlet defServlet = new org.eclipse.jetty.servlet.DefaultServlet(); main.addServlet("/", defServlet, ImmutableMap.<String,String>of( "dirAllowed", "false", "welcomeServlets", "true", "resourceBase", base )); main.context.setWelcomeFiles(new String[] { "index.html" }); main.addServlet("/index.html", new DefaultServlet()); if (SpyService.INSTANCE.isActive()) { main.addServlet("/spy/api", new SpyApiServlet()); main.addServlet("/spy", new SpyServlet()); } main.context.setErrorHandler(new ErrorPage()); ContextHandlerCollection ctxs = new ContextHandlerCollection(); ctxs.addHandler(main.context); ThreadFactory tf = new HttpThreadFactory(); BlockingQueue<Runnable> queue = new SynchronousQueue<>(); ThreadPoolExecutor exec = new ThreadPoolExecutor(4,16,60,TimeUnit.SECONDS,queue,tf); Server srv = new Server(new ExecutorThreadPool(exec)); srv.setHandler(ctxs); srv.setStopAtShutdown(false); srv.setStopTimeout(500); Map<String,Map<Integer,Connector>> conns = new LinkedHashMap<>(); Map<Integer,Connector> dconns = new LinkedHashMap<>(); conns.put("", dconns); DefaultConnector conn = new DefaultConnector(srv,PORT); srv.setConnectors(new ServerConnector[] { conn.connector }); dconns.put(PORT, conn); mainConnector = conn; connectors = conns; mainContext = main; contexts = ctxs; server = srv; srv.start(); } catch (Exception ex) { log.warn("failed to start http server:", ex); } }
Example #13
Source File: JettyServer.java From xmfcn-spring-cloud with Apache License 2.0 | 4 votes |
public void start(final int port, final String ip, final String appName) throws Exception { thread = new Thread(new Runnable() { @Override public void run() { // The Server server = new Server(new ExecutorThreadPool(1000)); // HTTP connector ServerConnector connector = new ServerConnector(server); if (ip!=null && ip.trim().length()>0) { //connector.setHost(ip); // The network interface this connector binds to as an IP address or a hostname. If null or 0.0.0.0, then bind to all interfaces. } connector.setPort(port); server.setConnectors(new Connector[]{connector}); // Set a handler HandlerCollection handlerc =new HandlerCollection(); handlerc.setHandlers(new Handler[]{new JettyServerHandler()}); server.setHandler(handlerc); try { // Start server server.start(); logger.info(">>>>>>>>>>> xxl-job jetty server start success at port:{}.", port); // Start Registry-Server ExecutorRegistryThread.getInstance().start(port, ip, appName); // Start Callback-Server TriggerCallbackThread.getInstance().start(); server.join(); // block until thread stopped logger.info(">>>>>>>>>>> xxl-rpc server join success, netcon={}, port={}", JettyServer.class.getName(), port); } catch (Exception e) { logger.error(e.getMessage(), e); } finally { //destroy(); } } }); thread.setDaemon(true); // daemon, service jvm, user thread leave >>> daemon leave >>> jvm leave thread.start(); }
Example #14
Source File: HttpManagement.java From qpid-broker-j with Apache License 2.0 | 4 votes |
private Server createServer(Collection<HttpPort<?>> ports) { LOGGER.debug("Starting up web server on {}", ports); _jettyServerExecutor = new ScheduledThreadPoolExecutor(1, new DaemonThreadFactory("Jetty-Server-Thread")); Server server = new Server(new ExecutorThreadPool(_jettyServerExecutor)); int lastPort = -1; for (HttpPort<?> port : ports) { ServerConnector connector = createConnector(port, server); connector.addBean(new ConnectionTrackingListener()); server.addConnector(connector); _portConnectorMap.put(port, connector); lastPort = port.getPort(); } ServletContextHandler root = new ServletContextHandler(ServletContextHandler.SESSIONS); root.setContextPath("/"); root.setCompactPath(true); server.setHandler(root); final ErrorHandler errorHandler = new ErrorHandler() { @Override protected void writeErrorPageBody(HttpServletRequest request, Writer writer, int code, String message, boolean showStacks) throws IOException { String uri= request.getRequestURI(); writeErrorPageMessage(request,writer,code,message,uri); for (int i= 0; i < 20; i++) writer.write("<br/> \n"); } }; root.setErrorHandler(errorHandler); // set servlet context attributes for broker and configuration root.getServletContext().setAttribute(HttpManagementUtil.ATTR_BROKER, getBroker()); root.getServletContext().setAttribute(HttpManagementUtil.ATTR_MANAGEMENT_CONFIGURATION, this); root.addFilter(new FilterHolder(new ExceptionHandlingFilter()), "/*", EnumSet.allOf(DispatcherType.class)); FilterHolder corsFilter = new FilterHolder(new CrossOriginFilter()); corsFilter.setInitParameter(CrossOriginFilter.ALLOWED_ORIGINS_PARAM, getCorsAllowOrigins()); corsFilter.setInitParameter(CrossOriginFilter.ALLOWED_METHODS_PARAM, Joiner.on(",").join(getCorsAllowMethods())); corsFilter.setInitParameter(CrossOriginFilter.ALLOWED_HEADERS_PARAM, getCorsAllowHeaders()); corsFilter.setInitParameter(CrossOriginFilter.ALLOW_CREDENTIALS_PARAM, String.valueOf(getCorsAllowCredentials())); root.addFilter(corsFilter, "/*", EnumSet.of(DispatcherType.REQUEST)); root.addFilter(new FilterHolder(new ForbiddingTraceFilter()), "/*", EnumSet.of(DispatcherType.REQUEST)); addFiltersAndServletsForRest(root); if (!Boolean.TRUE.equals(getContextValue(Boolean.class, DISABLE_UI_CONTEXT_NAME))) { addFiltersAndServletsForUserInterfaces(root); } root.getSessionHandler().getSessionCookieConfig().setName(JSESSIONID_COOKIE_PREFIX + lastPort); root.getSessionHandler().getSessionCookieConfig().setHttpOnly(true); root.getSessionHandler().setMaxInactiveInterval(getSessionTimeout()); return server; }
Example #15
Source File: ServerRuntime.java From EDDI with Apache License 2.0 | 4 votes |
private ThreadPool createThreadPool() { return new ExecutorThreadPool(threadPoolExecutor); }
Example #16
Source File: ServerManager.java From pulsar with Apache License 2.0 | 4 votes |
public ServerManager(ServiceConfig config) { this.webServiceExecutor = new ExecutorThreadPool(); this.webServiceExecutor.setName("pulsar-external-web"); this.server = new Server(webServiceExecutor); List<ServerConnector> connectors = Lists.newArrayList(); if (config.getWebServicePort().isPresent()) { connector = new ServerConnector(server, 1, 1); connector.setPort(config.getWebServicePort().get()); connectors.add(connector); } else { connector = null; } if (config.getWebServicePortTls().isPresent()) { try { SslContextFactory sslCtxFactory; if (config.isTlsEnabledWithKeyStore()) { sslCtxFactory = KeyStoreSSLContext.createSslContextFactory( config.getTlsProvider(), config.getTlsKeyStoreType(), config.getTlsKeyStore(), config.getTlsKeyStorePassword(), config.isTlsAllowInsecureConnection(), config.getTlsTrustStoreType(), config.getTlsTrustStore(), config.getTlsTrustStorePassword(), config.isTlsRequireTrustedClientCertOnConnect(), config.getTlsCertRefreshCheckDurationSec() ); } else { sslCtxFactory = SecurityUtility.createSslContextFactory( config.isTlsAllowInsecureConnection(), config.getTlsTrustCertsFilePath(), config.getTlsCertificateFilePath(), config.getTlsKeyFilePath(), config.isTlsRequireTrustedClientCertOnConnect(), true, config.getTlsCertRefreshCheckDurationSec()); } connectorTls = new ServerConnector(server, 1, 1, sslCtxFactory); connectorTls.setPort(config.getWebServicePortTls().get()); connectors.add(connectorTls); } catch (Exception e) { throw new RestException(e); } } else { connectorTls = null; } // Limit number of concurrent HTTP connections to avoid getting out of file descriptors connectors.stream().forEach(c -> c.setAcceptQueueSize(1024 / connectors.size())); server.setConnectors(connectors.toArray(new ServerConnector[connectors.size()])); }