List of usage examples for java.net InetSocketAddress getPort
public final int getPort()
From source file:async.nio2.Main.java
public static void main(String[] args) throws IOException, InterruptedException, ExecutionException { if (args.length == 3) { PORT = Integer.valueOf(args[0]); NO_CLIENTS = Integer.valueOf(args[1]); NO_SAMPLES = Integer.valueOf(args[2]); }/* w w w . j a va2 s .co m*/ if (PORT < 0) { System.err.println("Error: port < 0"); System.exit(1); } if (NO_CLIENTS < 1) { System.err.println("Error: #clients < 1"); System.exit(1); } if (NO_SAMPLES < 1) { System.err.println("Error: #samples < 1"); System.exit(1); } AsynchronousChannelGroup groupServer = AsynchronousChannelGroup .withThreadPool(Executors.newFixedThreadPool(1)); AsynchronousChannelGroup groupClient = AsynchronousChannelGroup .withThreadPool(Executors.newFixedThreadPool(1)); Server server = Server.newInstance(new InetSocketAddress("localhost", PORT), groupServer); InetSocketAddress localAddress = server.getLocalAddress(); String hostname = localAddress.getHostName(); int port = localAddress.getPort(); ExecutorService es = Executors.newFixedThreadPool(2); System.out.printf("%03d clients on %s:%d, %03d runs each. All times in s.%n", NO_CLIENTS, hostname, port, NO_SAMPLES); range(0, NO_CLIENTS).unordered().parallel() .mapToObj(i -> CompletableFuture.supplyAsync(newClient(localAddress, groupClient), es).join()) .map(array -> Arrays.stream(array).reduce(new DescriptiveStatistics(), Main::accumulate, Main::combine)) .map(Main::toEvaluationString).forEach(System.out::println); es.shutdown(); es.awaitTermination(5, TimeUnit.SECONDS); groupClient.shutdown(); groupClient.awaitTermination(5, TimeUnit.SECONDS); server.close(); groupServer.shutdown(); groupServer.awaitTermination(5, TimeUnit.SECONDS); }
From source file:Main.java
public static void main(String[] args) throws Exception { System.setProperty("java.net.useSystemProxies", "true"); List l = ProxySelector.getDefault().select(new URI("http://www.yahoo.com/")); for (Iterator iter = l.iterator(); iter.hasNext();) { Proxy proxy = (Proxy) iter.next(); System.out.println("proxy hostname : " + proxy.type()); InetSocketAddress addr = (InetSocketAddress) proxy.address(); if (addr == null) { System.out.println("No Proxy"); } else {/* w w w .j av a2 s. c o m*/ System.out.println("proxy hostname : " + addr.getHostName()); System.out.println("proxy port : " + addr.getPort()); } } }
From source file:com.trendmicro.hdfs.webdav.Main.java
public static void main(String[] args) { HDFSWebDAVServlet servlet = HDFSWebDAVServlet.getServlet(); Configuration conf = servlet.getConfiguration(); // Process command line Options options = new Options(); options.addOption("d", "debug", false, "Enable debug logging"); options.addOption("p", "port", true, "Port to bind to [default: 8080]"); options.addOption("b", "bind-address", true, "Address or hostname to bind to [default: 0.0.0.0]"); options.addOption("g", "ganglia", true, "Send Ganglia metrics to host:port [default: none]"); CommandLine cmd = null;/* w ww. j ava 2s . c om*/ try { cmd = new PosixParser().parse(options, args); } catch (ParseException e) { printUsageAndExit(options, -1); } if (cmd.hasOption('d')) { Logger rootLogger = Logger.getLogger("com.trendmicro"); rootLogger.setLevel(Level.DEBUG); } if (cmd.hasOption('b')) { conf.set("hadoop.webdav.bind.address", cmd.getOptionValue('b')); } if (cmd.hasOption('p')) { conf.setInt("hadoop.webdav.port", Integer.valueOf(cmd.getOptionValue('p'))); } String gangliaHost = null; int gangliaPort = 8649; if (cmd.hasOption('g')) { String val = cmd.getOptionValue('g'); if (val.indexOf(':') != -1) { String[] split = val.split(":"); gangliaHost = split[0]; gangliaPort = Integer.valueOf(split[1]); } else { gangliaHost = val; } } InetSocketAddress addr = getAddress(conf); // Log in the server principal from keytab UserGroupInformation.setConfiguration(conf); if (UserGroupInformation.isSecurityEnabled()) try { SecurityUtil.login(conf, "hadoop.webdav.server.kerberos.keytab", "hadoop.webdav.server.kerberos.principal", addr.getHostName()); } catch (IOException e) { LOG.fatal("Could not log in", e); System.err.println("Could not log in"); System.exit(-1); } // Set up embedded Jetty Server server = new Server(); server.setSendServerVersion(false); server.setSendDateHeader(false); server.setStopAtShutdown(true); // Set up connector Connector connector = new SelectChannelConnector(); connector.setPort(addr.getPort()); connector.setHost(addr.getHostName()); server.addConnector(connector); LOG.info("Listening on " + addr); // Set up context Context context = new Context(server, "/", Context.SESSIONS); // WebDAV servlet ServletHolder servletHolder = new ServletHolder(servlet); servletHolder.setInitParameter("authenticate-header", "Basic realm=\"Hadoop WebDAV Server\""); context.addServlet(servletHolder, "/*"); // metrics instrumentation filter context.addFilter(new FilterHolder(new DefaultWebappMetricsFilter()), "/*", 0); // auth filter context.addFilter(new FilterHolder(new AuthFilter(conf)), "/*", 0); server.setHandler(context); // Set up Ganglia metrics reporting if (gangliaHost != null) { GangliaReporter.enable(1, TimeUnit.MINUTES, gangliaHost, gangliaPort); } // Start and join the server thread try { server.start(); server.join(); } catch (Exception e) { LOG.fatal("Failed to start Jetty", e); System.err.println("Failed to start Jetty"); System.exit(-1); } }
From source file:net.iridiant.hdfs.webdav.Main.java
public static void main(String[] args) { HDFSWebDAVServlet servlet = HDFSWebDAVServlet.getServlet(); Configuration conf = servlet.getConfiguration(); // Process command line Options options = new Options(); options.addOption("d", "debug", false, "Enable debug logging"); options.addOption("p", "port", true, "Port to bind to [default: 8080]"); options.addOption("b", "bind-address", true, "Address or hostname to bind to [default: 0.0.0.0]"); options.addOption("g", "ganglia", true, "Send Ganglia metrics to host:port [default: none]"); CommandLine cmd = null;//from ww w.j a va 2 s. c om try { cmd = new PosixParser().parse(options, args); } catch (ParseException e) { printUsageAndExit(options, -1); } if (cmd.hasOption('d')) { Logger rootLogger = Logger.getLogger("net.iridiant"); rootLogger.setLevel(Level.DEBUG); } if (cmd.hasOption('b')) { conf.set("hadoop.webdav.bind.address", cmd.getOptionValue('b')); } if (cmd.hasOption('p')) { conf.setInt("hadoop.webdav.port", Integer.valueOf(cmd.getOptionValue('p'))); } String gangliaHost = null; int gangliaPort = 8649; if (cmd.hasOption('g')) { String val = cmd.getOptionValue('g'); if (val.indexOf(':') != -1) { String[] split = val.split(":"); gangliaHost = split[0]; gangliaPort = Integer.valueOf(split[1]); } else { gangliaHost = val; } } InetSocketAddress addr = getAddress(conf); // Log in the server principal from keytab UserGroupInformation.setConfiguration(conf); if (UserGroupInformation.isSecurityEnabled()) try { SecurityUtil.login(conf, "hadoop.webdav.server.kerberos.keytab", "hadoop.webdav.server.kerberos.principal", addr.getHostName()); } catch (IOException e) { LOG.fatal("Could not log in", e); System.err.println("Could not log in"); System.exit(-1); } // Set up embedded Jetty Server server = new Server(); server.setSendServerVersion(false); server.setSendDateHeader(false); server.setStopAtShutdown(true); // Set up connector Connector connector = new SelectChannelConnector(); connector.setPort(addr.getPort()); connector.setHost(addr.getHostName()); server.addConnector(connector); LOG.info("Listening on " + addr); // Set up context Context context = new Context(server, "/", Context.SESSIONS); // WebDAV servlet ServletHolder servletHolder = new ServletHolder(servlet); servletHolder.setInitParameter("authenticate-header", "Basic realm=\"Hadoop WebDAV Server\""); context.addServlet(servletHolder, "/*"); // metrics instrumentation filter context.addFilter(new FilterHolder(new DefaultWebappMetricsFilter()), "/*", 0); // auth filter context.addFilter(new FilterHolder(new AuthFilter(conf)), "/*", 0); server.setHandler(context); // Set up Ganglia metrics reporting if (gangliaHost != null) { GangliaReporter.enable(1, TimeUnit.MINUTES, gangliaHost, gangliaPort); } // Start and join the server thread try { server.start(); server.join(); } catch (Exception e) { LOG.fatal("Failed to start Jetty", e); System.err.println("Failed to start Jetty"); System.exit(-1); } }
From source file:ch.epfl.eagle.daemon.util.Network.java
public static THostPort socketAddressToThrift(InetSocketAddress address) { return new THostPort(address.getAddress().getHostAddress(), address.getPort()); }
From source file:Main.java
public static void printSocketAddress(InetSocketAddress sAddr) { System.out.println("Socket Address: " + sAddr.getAddress()); System.out.println("Socket Host Name: " + sAddr.getHostName()); System.out.println("Socket Port: " + sAddr.getPort()); System.out.println("isUnresolved(): " + sAddr.isUnresolved()); System.out.println();/*from w ww . j a v a 2 s . com*/ }
From source file:SocketAddressEncoder.java
public static String encode(InetSocketAddress address) { InetAddress servAddr = address.getAddress(); int servPort = address.getPort(); return servAddr.getHostAddress().replace('.', ',') + ',' + (servPort >> 8) + ',' + (servPort & 0xFF); }
From source file:org.apache.hadoop.util.NodeUtils.java
public static String toURL(String protocol, InetSocketAddress addr) { String address = addressToString(addr); int port = addr.getPort(); return toURL(protocol, address, port); }
From source file:eu.delving.sip.base.HttpClientFactory.java
private static void handleProxy(String serverUrl, HttpClientBuilder builder) { try {// w ww . jav a2s .co m List<Proxy> proxies = ProxySelector.getDefault().select(new URI(serverUrl)); for (Proxy proxy : proxies) { if (proxy.type() != Proxy.Type.HTTP) continue; InetSocketAddress addr = (InetSocketAddress) proxy.address(); String host = addr.getHostName(); int port = addr.getPort(); builder.setProxy(new HttpHost(host, port)); } } catch (URISyntaxException e) { throw new RuntimeException("Bad address: " + serverUrl, e); } }
From source file:com.facebook.presto.jdbc.QueryExecutor.java
@Nullable private static HttpHost getSystemSocksProxy() { URI uri = URI.create("socket://0.0.0.0:80"); for (Proxy proxy : ProxySelector.getDefault().select(uri)) { if (proxy.type() == Proxy.Type.SOCKS) { if (proxy.address() instanceof InetSocketAddress) { InetSocketAddress address = (InetSocketAddress) proxy.address(); return new HttpHost(address.getHostName(), address.getPort()); }/* w ww. jav a 2 s . com*/ } } return null; }