@Override public void bind(final InetSocketAddress inetSocketAddress, final int i) throws IOException { delegate.bind(inetSocketAddress, i); }
private static void initHttpServer() throws Exception { // Setup default endpoints final HttpServer server = HttpServer.create(); server.createContext("/echo", new EchoHandler()); // Hook to allow for graceful exit final Closeable c = () -> { PollScheduler.getInstance().stop(); server.stop(5); }; server.createContext("/exit", new ExitHandler(c)); // Bind and start server server.bind(new InetSocketAddress(Config.getPort()), 0); server.start(); }
/** * Start a HTTP server serving Prometheus metrics from the given registry. */ public HTTPServer(InetSocketAddress addr, CollectorRegistry registry, boolean daemon) throws IOException { server = HttpServer.create(); server.bind(addr, 3); HttpHandler mHandler = new HTTPMetricHandler(registry); server.createContext("/", mHandler); server.createContext("/metrics", mHandler); executorService = Executors.newFixedThreadPool(5, NamedDaemonThreadFactory.defaultThreadFactory(daemon)); server.setExecutor(executorService); start(daemon); }
@Override public void bind(final InetSocketAddress inetSocketAddress, final int i) throws IOException { delegate.bind(inetSocketAddress, i); }
private static void privilegeBind(HttpServer httpsServer, InetSocketAddress inetSocketAddress, int i) throws IOException { try { AccessController.doPrivileged((PrivilegedExceptionAction<Void>) () -> { httpsServer.bind(inetSocketAddress, i); return null; }); } catch (PrivilegedActionException e) { throw (IOException) e.getCause(); } }
public void start() throws IOException { if (WebConsoleConfiguration.port == 0) { return; } final int useSystemDefaultBacklog = 0; server.bind( new InetSocketAddress(WebConsoleConfiguration.port), useSystemDefaultBacklog); LOG.info("Starting webconsole on port " + WebConsoleConfiguration.port); for (final Widget widget : widgets) { LOG.info("Adding webconsole widget " + widget.getPath()); server.createContext(widget.getPath(), widget.getServlet()); } server.start(); }
/** * Finds free port number and binds a server to it. * @param address address to listen on. * @param startPort lowest allowed port. * @param maxPort highest (inclusive) port. * @return server created. */ public static com.sun.net.httpserver.HttpServer bind(InetAddress address, int startPort, int maxPort) { com.sun.net.httpserver.HttpServer aServer = createServer(); int port = -1; for (int possiblePort = startPort; port == -1 && possiblePort <= maxPort; possiblePort++) { try { InetSocketAddress s = new InetSocketAddress(address, possiblePort); aServer.bind(s, 1); port = possiblePort; } catch (IOException e) { // try next number continue; } } if (aServer.getAddress() == null) { throw new RuntimeException(new BindException("Unable to bind to: " + address.getHostAddress())); } return aServer; }
public void start(Context context) throws LifecycleException { try { // TODO: configure http bind address httpFileServer = HttpServer.create(); httpFileServer.bind( new InetSocketAddress( InetAddress.getByName(configuration.getLocalDeploymentBindAddress()), configuration.getLocalDeploymentBindPort()), -1); httpFileServer.start(); initDeploymentManager(); } catch (Exception e) { throw new LifecycleException("Could not connect to container", e); } }
/** * Start a HTTP server serving Prometheus metrics from the given registry. */ public HTTPServer(InetSocketAddress addr, CollectorRegistry registry, boolean daemon) throws IOException { server = HttpServer.create(); server.bind(addr, 3); HttpHandler mHandler = new HTTPMetricHandler(registry); server.createContext("/", mHandler); server.createContext("/metrics", mHandler); executorService = Executors.newFixedThreadPool(5, DaemonThreadFactory.defaultThreadFactory(daemon)); server.setExecutor(executorService); start(daemon); }
try { HttpServer theHttpServer = HttpServer.create(); theHttpServer.bind( new InetSocketAddress( aPort ), aMaxConnections ); open( theHttpServer );