private ServerConnector createHttpChannelConnector( Server server, HttpConfiguration httpConfig) { ServerConnector conn = new ServerConnector(server, conf.getInt(HTTP_ACCEPTOR_COUNT_KEY, HTTP_ACCEPTOR_COUNT_DEFAULT), conf.getInt(HTTP_SELECTOR_COUNT_KEY, HTTP_SELECTOR_COUNT_DEFAULT)); ConnectionFactory connFactory = new HttpConnectionFactory(httpConfig); conn.addConnectionFactory(connFactory); if(Shell.WINDOWS) { // result of setting the SO_REUSEADDR flag is different on Windows // http://msdn.microsoft.com/en-us/library/ms740621(v=vs.85).aspx // without this 2 NN's can start on the same machine and listen on // the same port with indeterminate routing of incoming requests to them conn.setReuseAddress(false); } return conn; }
@Override public void start() { jettyServer = new Server(); //We can use Contexts etc if we have many urls to handle. For one url, //specifying a handler directly is the most efficient. HttpConfiguration httpConfiguration = new HttpConfiguration(); ServerConnector connector = new ServerConnector(jettyServer, new HttpConnectionFactory(httpConfiguration)); connector.setReuseAddress(true); connector.setPort(port); jettyServer.addConnector(connector); jettyServer.setHandler(new HTTPMetricsHandler()); try { jettyServer.start(); while (!jettyServer.isStarted()) { Thread.sleep(500); } } catch (Exception ex) { LOG.error("Error starting Jetty. JSON Metrics may not be available.", ex); } }
/** * Create a channel connector for "http/https" requests */ Connector createChannelConnector(int queueSize, Builder b) { ServerConnector connector; final HttpConfiguration conf = new HttpConfiguration(); conf.setRequestHeaderSize(1024*64); final HttpConnectionFactory http = new HttpConnectionFactory(conf); if (!b.useSSL) { connector = new ServerConnector(webServer, http); } else { SslContextFactory sslContextFactory = new SslContextFactory(); sslContextFactory.setKeyStorePath(b.keyStorePath); Set<String> excludedSSLProtocols = Sets.newHashSet( Splitter.on(",").trimResults().omitEmptyStrings().split( Strings.nullToEmpty(b.conf.getVar(ConfVars.HIVE_SSL_PROTOCOL_BLACKLIST)))); sslContextFactory.addExcludeProtocols(excludedSSLProtocols.toArray( new String[excludedSSLProtocols.size()])); sslContextFactory.setKeyStorePassword(b.keyStorePassword); connector = new ServerConnector(webServer, sslContextFactory, http); } connector.setAcceptQueueSize(queueSize); connector.setReuseAddress(true); connector.setHost(b.host); connector.setPort(b.port); return connector; }
connector.setReuseAddress(reuseAddress); connector.setIdleTimeout(idleTimeout.toMilliseconds()); connector.setName(name);
listener.setReuseAddress(false);
connector.setReuseAddress(true);
srvConn.setPort(srvPort); srvConn.setIdleTimeout(30000L); srvConn.setReuseAddress(true);
connector.setReuseAddress(true); int maxIdleTime = (int) hiveConf.getTimeVar(ConfVars.HIVE_SERVER2_THRIFT_HTTP_MAX_IDLE_TIME, TimeUnit.MILLISECONDS);
private void setupServerConnector(Server server, String host, int port) { @SuppressWarnings("resource") ServerConnector connector = new ServerConnector(server); connector.setHost(host); connector.setPort(port); connector.setIdleTimeout(TimeUnit.MINUTES.toMillis(2)); connector.setReuseAddress(true); connector.setName(valueOf(port)); server.addConnector(connector); }
@Override public void start() { jettyServer = new Server(); //We can use Contexts etc if we have many urls to handle. For one url, //specifying a handler directly is the most efficient. HttpConfiguration httpConfiguration = new HttpConfiguration(); ServerConnector connector = new ServerConnector(jettyServer, new HttpConnectionFactory(httpConfiguration)); connector.setReuseAddress(true); connector.setPort(port); jettyServer.addConnector(connector); jettyServer.setHandler(new HTTPMetricsHandler()); try { jettyServer.start(); while (!jettyServer.isStarted()) { Thread.sleep(500); } } catch (Exception ex) { LOG.error("Error starting Jetty. JSON Metrics may not be available.", ex); } }
Server s = new Server(PORT); ServerConnector connector = new ServerConnector(s); connector.setReuseAddress(true); // avoid bind errors s.setHandler(new ContextHandlerCollection()); s.setConnectors(new Connector[] { connector }); System.setProperty("com.sun.net.httpserver.HttpServerProvider", "org.eclipse.jetty.http.spi.JettyHttpServerProvider"); Endpoint.publish(HOST + ":" + PORT + PATH, new MyServiceImpl());
private static void installListeners(Server server, Collection<? extends InetSocketAddress> addresses) { final List<Connector> connectors = new ArrayList<>(addresses.size()); for (InetSocketAddress address : addresses) { final ServerConnector server_connector = new ServerConnector(server); server_connector.setReuseAddress(true); if (address.getAddress() != null) { if (!address.getAddress().isAnyLocalAddress()) { LOG.log(Level.INFO, "Binding API server address: {0}", address.getAddress().getHostAddress()); server_connector.setHost(address.getAddress().getHostAddress()); } } else if (address.getHostString() != null) { LOG.log(Level.INFO, "Binding API server address name: {0}", address.getHostString()); server_connector.setHost(address.getHostString()); } LOG.log(Level.INFO, "Binding API server port: {0}", address.getPort()); server_connector.setPort(address.getPort()); connectors.add(server_connector); } server.setConnectors(connectors.toArray(new Connector[connectors.size()])); } }
public static Server createServer(int port) throws MalformedURLException, URISyntaxException { Server server = new Server(); server.setStopAtShutdown(true); ServerConnector connector = new ServerConnector(server); connector.setPort(port); connector.setReuseAddress(true); server.setConnectors(new Connector[]{connector}); WebAppContext webContext = new WebAppContext("webapp", CONTEXT); webContext.setBaseResource(Resource.newResource(new URL(ApiWebSite.class.getResource("/webapp/WEB-INF"), "."))); webContext.setClassLoader(ApiWebSite.class.getClassLoader()); server.setHandler(webContext); return server; }
public static Server createServer(int port) throws MalformedURLException, URISyntaxException { Server server = new Server(); server.setStopAtShutdown(true); ServerConnector connector = new ServerConnector(server); connector.setPort(port); connector.setReuseAddress(true); server.setConnectors(new Connector[]{connector}); WebAppContext webContext = new WebAppContext("webapp", CONTEXT); webContext.setBaseResource(Resource.newResource(new URL(ApiWebSite.class.getResource("/webapp/WEB-INF"), "."))); webContext.setClassLoader(ApiWebSite.class.getClassLoader()); server.setHandler(webContext); return server; }
public static Server createServer(int port) throws MalformedURLException, URISyntaxException { Server server = new Server(); server.setStopAtShutdown(true); ServerConnector connector = new ServerConnector(server); connector.setPort(port); connector.setReuseAddress(false); server.setConnectors(new Connector[]{connector}); WebAppContext webContext = new WebAppContext("webapp", CONTEXT); webContext.setBaseResource(Resource.newResource(new URL(ApiWebSite.class.getResource("/webapp/WEB-INF"), "."))); webContext.setClassLoader(ApiWebSite.class.getClassLoader()); server.setHandler(webContext); return server; }
void start(final TreeLogger logger) throws UnableToCompleteException { Server newServer = new Server(); ServerConnector connector = new ServerConnector(newServer); connector.setHost(bindAddress); connector.setPort(port); connector.setReuseAddress(false); connector.setSoLingerTime(0); newServer.addConnector(connector); ServletContextHandler newHandler = new ServletContextHandler(ServletContextHandler.SESSIONS); newHandler.setContextPath("/"); newHandler.addServlet(new ServletHolder(new HttpServlet() { @Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { handleRequest(request.getPathInfo(), request, response, logger); } }), "/*"); newHandler.addFilter(GzipFilter.class, "/*", EnumSet.allOf(DispatcherType.class)); newServer.setHandler(newHandler); try { newServer.start(); } catch (Exception e) { logger.log(TreeLogger.ERROR, "cannot start web server", e); throw new UnableToCompleteException(); } this.server = newServer; }
/** * Create a channel connector for "http/https" requests */ Connector createChannelConnector(int queueSize, Builder b) { ServerConnector connector; final HttpConfiguration conf = new HttpConfiguration(); conf.setRequestHeaderSize(1024*64); final HttpConnectionFactory http = new HttpConnectionFactory(conf); if (!b.useSSL) { connector = new ServerConnector(webServer, http); } else { SslContextFactory sslContextFactory = new SslContextFactory(); sslContextFactory.setKeyStorePath(b.keyStorePath); Set<String> excludedSSLProtocols = Sets.newHashSet( Splitter.on(",").trimResults().omitEmptyStrings().split( Strings.nullToEmpty(b.conf.getVar(ConfVars.HIVE_SSL_PROTOCOL_BLACKLIST)))); sslContextFactory.addExcludeProtocols(excludedSSLProtocols.toArray( new String[excludedSSLProtocols.size()])); sslContextFactory.setKeyStorePassword(b.keyStorePassword); connector = new ServerConnector(webServer, sslContextFactory, http); } connector.setAcceptQueueSize(queueSize); connector.setReuseAddress(true); connector.setHost(b.host); connector.setPort(b.port); return connector; }
protected ServerConnector createConnector() throws Exception { ServerConnector connector = new ServerConnector(server, null, null, null, AppInfo.getInt("http.connector.acceptors", 0), AppInfo.getInt("http.connector.selectors", 5), getConnectionFactorys()); connector.setReuseAddress(AppInfo.getBoolean("http.reuseAddr", false)); int backlog = AppInfo.getInt("http.backlog", 0); if (backlog > 0) { connector.setAcceptQueueSize(backlog); } return connector; }
connector.setReuseAddress(reuseAddress); if (soLingerTime != null) { connector.setSoLingerTime((int) soLingerTime.toMilliseconds());
public ServerConnector createConnector(final Metric metric, final Server server, final ServerSocketChannel ch) { ServerConnector connector; if (connectorConfig.ssl().enabled()) { connector = new JDiscServerConnector(connectorConfig, metric, server, ch, newSslConnectionFactory(), newHttpConnectionFactory()); } else { connector = new JDiscServerConnector(connectorConfig, metric, server, ch, newHttpConnectionFactory()); } connector.setPort(connectorConfig.listenPort()); connector.setName(connectorConfig.name()); connector.setAcceptQueueSize(connectorConfig.acceptQueueSize()); connector.setReuseAddress(connectorConfig.reuseAddress()); connector.setIdleTimeout((long)(connectorConfig.idleTimeout() * 1000.0)); connector.setStopTimeout((long)(connectorConfig.stopTimeout() * 1000.0)); return connector; }