Example usage for java.net InetSocketAddress getHostName

List of usage examples for java.net InetSocketAddress getHostName

Introduction

In this page you can find the example usage for java.net InetSocketAddress getHostName.

Prototype

public final String getHostName() 

Source Link

Document

Gets the hostname .

Usage

From source file:org.apache.flink.client.CliFrontendAddressConfigurationTest.java

@Test
public void testManualOptionsOverridesConfig() {
    try {//from   w  ww . ja  v  a2s.c  o  m
        CliFrontend frontend = new CliFrontend(CliFrontendTestUtils.getConfigDir());

        CommandLineOptions options = mock(CommandLineOptions.class);
        when(options.getJobManagerAddress()).thenReturn("10.221.130.22:7788");

        frontend.updateConfig(options);

        Configuration config = frontend.getConfiguration();

        InetSocketAddress expectedAddress = new InetSocketAddress("10.221.130.22", 7788);

        checkJobManagerAddress(config, expectedAddress.getHostName(), expectedAddress.getPort());
    } catch (Exception e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
}

From source file:org.apache.flink.client.CliFrontendAddressConfigurationTest.java

@Test
public void testManualOptionsOverridesYarn() {
    try {/*from  w ww  .j  ava 2  s.  co m*/
        CliFrontend frontend = new CliFrontend(CliFrontendTestUtils.getConfigDirWithYarnFile());

        CommandLineOptions options = mock(CommandLineOptions.class);
        when(options.getJobManagerAddress()).thenReturn("10.221.130.22:7788");

        frontend.updateConfig(options);

        Configuration config = frontend.getConfiguration();

        InetSocketAddress expectedAddress = new InetSocketAddress("10.221.130.22", 7788);

        checkJobManagerAddress(config, expectedAddress.getHostName(), expectedAddress.getPort());
    } catch (Exception e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
}

From source file:io.github.bonigarcia.wdm.WdmHttpClient.java

private final HttpHost createProxyHttpHost(String proxyUrl) {
    Proxy proxy = createProxy(proxyUrl);
    if (proxy == null || proxy.address() == null) {
        return null;
    }//from w  w  w.  j  ava2  s. c  om
    if (!(proxy.address() instanceof InetSocketAddress)) {
        throw new RuntimeException(
                "Detect an unsupported subclass of SocketAddress. Please use the InetSocketAddress or subclass. Actual:"
                        + proxy.address().getClass());
    }
    InetSocketAddress proxyAddress = (InetSocketAddress) proxy.address();
    return new HttpHost(proxyAddress.getHostName(), proxyAddress.getPort());
}

From source file:com.kixeye.chassis.bootstrap.webapp.TestSpringWebApp.java

@Bean(initMethod = "start", destroyMethod = "stop", name = "httpServer")
@Order(0)//  w  w  w  . ja v  a 2s  . co  m
public Server httpServer(ConfigurableWebApplicationContext webApplicationContext) {

    // set up servlets
    ServletHandler servlets = new ServletHandler();
    ServletContextHandler context = new ServletContextHandler(ServletContextHandler.NO_SECURITY);
    context.setErrorHandler(null);
    context.setWelcomeFiles(new String[] { "/" });

    // set up spring with the servlet context
    setServletContext(context.getServletContext());

    // configure the spring mvc dispatcher
    DispatcherServlet dispatcher = new DispatcherServlet(webApplicationContext);

    // map application servlets
    context.addServlet(new ServletHolder(dispatcher), "/");

    servlets.setHandler(context);

    // create the server
    InetSocketAddress address = new InetSocketAddress(SocketUtils.findAvailableTcpPort());

    Server server = new Server();
    ServerConnector connector = new ServerConnector(server);
    connector.setHost(address.getHostName());
    connector.setPort(address.getPort());
    server.setConnectors(new Connector[] { connector });
    server.setHandler(servlets);
    server.setStopAtShutdown(true);

    return server;
}

From source file:org.apache.hadoop.mapred.JobTrackerHADaemon.java

public void start() throws IOException {

    Configuration jtConf = new Configuration(conf);
    String logicalName = HAUtil.getLogicalName(jtConf);
    String jtId = HAUtil.getJobTrackerId(jtConf);
    HAUtil.setGenericConf(jtConf, logicalName, jtId, HAUtil.JOB_TRACKER_SPECIFIC_KEYS);

    // Login HA daemon, if auth is not kerberos login() is a NOP
    InetSocketAddress addr = HAUtil.getJtHaRpcAddress(conf, jtId);
    String localMachine = addr.getHostName();
    UserGroupInformation.setConfiguration(conf);
    SecurityUtil.login(conf, JobTracker.JT_KEYTAB_FILE, JobTracker.JT_USER_NAME, localMachine);

    // To avoid the JT from doing a new login() as re-login seems to be destructive
    JobTracker.loggedIn = true;/*from ww  w .  j  a va  2s .co  m*/

    //Using a thread outside of all login context to start/stop the JT
    //otherwise the credentials of the UGI making the RPC call to activate
    //get in the way breaking things.
    jtRunner = new JobTrackerRunner();
    jtRunner.start();

    this.proto = new JobTrackerHAServiceProtocol(jtConf, jtRunner);

    RPC.setProtocolEngine(conf, HAServiceProtocolPB.class, ProtobufRpcEngine.class);

    HAServiceProtocolServerSideTranslatorPB haServiceProtocolXlator = new HAServiceProtocolServerSideTranslatorPB(
            proto);
    BlockingService haPbService = HAServiceProtocolService
            .newReflectiveBlockingService(haServiceProtocolXlator);

    WritableRpcEngine.ensureInitialized();

    InetSocketAddress rpcAddr = HAUtil.getJtHaRpcAddress(conf);

    this.rpcServer = RPC.getServer(HAServiceProtocolPB.class, haPbService, rpcAddr.getHostName(),
            rpcAddr.getPort(), conf);

    // set service-level authorization security policy
    if (conf.getBoolean(CommonConfigurationKeys.HADOOP_SECURITY_AUTHORIZATION, false)) {
        rpcServer.refreshServiceAcl(conf, new MapReducePolicyProvider());
    }

    this.rpcServer.start();

    // set port in config
    int port = rpcServer.getListenerAddress().getPort();
    HAUtil.setJtHaRpcAddress(conf, rpcAddr.getHostName() + ":" + port);
    LOG.info("Started " + getClass().getSimpleName() + " on port " + port);
}

From source file:org.apache.tajo.cli.tools.TajoGetConf.java

public void runCommand(String[] args, boolean tsqlMode) throws Exception {
    CommandLineParser parser = new PosixParser();

    if (args.length == 0) {
        printUsage(tsqlMode);/*from  w  ww .j a v a2 s . co  m*/
        return;
    }

    CommandLine cmd = parser.parse(options, args);

    String hostName = null;
    Integer port = null;
    if (cmd.hasOption("h")) {
        hostName = cmd.getOptionValue("h");
    }
    if (cmd.hasOption("p")) {
        port = Integer.parseInt(cmd.getOptionValue("p"));
    }

    String param;
    if (cmd.getArgs().length > 1) {
        printUsage(tsqlMode);
        return;
    } else {
        param = cmd.getArgs()[0];
    }

    // if there is no "-h" option,
    InetSocketAddress address = tajoConf.getSocketAddrVar(TajoConf.ConfVars.TAJO_MASTER_CLIENT_RPC_ADDRESS,
            TajoConf.ConfVars.TAJO_MASTER_UMBILICAL_RPC_ADDRESS);

    if (hostName == null) {
        hostName = address.getHostName();
    }

    if (port == null) {
        port = address.getPort();
    }

    if ((hostName == null) ^ (port == null)) {
        return;
    } else if (hostName != null && port != null) {
        tajoConf.setVar(TajoConf.ConfVars.TAJO_MASTER_CLIENT_RPC_ADDRESS,
                NetUtils.getHostPortString(hostName, port));
    }

    processConfKey(writer, param);
    writer.flush();
}

From source file:com.pinterest.terrapin.zookeeper.ZooKeeperManagerTest.java

@Test
public void testGetControllerLeader() throws Exception {
    String host = "somehost";
    int port = 9090;
    String json = String.format("{\"id\": \"%s_%d\"}", host, port);
    when(zk.getData(eq("/" + CLUSTER_NAME + "/CONTROLLER/LEADER"), anyBoolean(), any(Stat.class)))
            .thenReturn(json.getBytes());
    InetSocketAddress address = zkManager.getControllerLeader();
    assertEquals(host, address.getHostName());
    assertEquals(port, address.getPort());
}

From source file:com.sharneng.net.portforward.Listener.java

/**
 * Constructs a new instance of Listener.
 * //  w  w w . j av a  2 s  .  c  om
 * @param from
 *            the address to listen for connections
 * @param to
 *            the address to forward connections to
 * @throws IOException
 *             when something is not going write when network operation
 */
public Listener(InetSocketAddress from, InetSocketAddress to) throws IOException {
    this.from = from;
    this.to = to;
    serverSocket = new ServerSocket();
    serverSocket.setReuseAddress(true);
    serverSocket.bind(from);
    String hostname = from.getHostName();
    if (hostname == null)
        hostname = "*";
    log.info("Ready to accept client connection on " + hostname + ":" + from.getPort());
}

From source file:org.ros.internal.node.DefaultNodeTest.java

@Test
public void testPublicAddresses() throws InterruptedException {
    MasterServer master = new MasterServer(BindAddress.newPublic(), AdvertiseAddress.newPublic());
    master.start();//from  w ww. j av a 2 s  .c o  m
    URI masterUri = master.getUri();
    checkHostName(masterUri.getHost());

    NodeConfiguration nodeConfiguration = NodeConfiguration.newPublic(masterUri.getHost(), masterUri);
    nodeConfiguration.setNodeName("test_addresses");
    Node node = nodeFactory.newNode(nodeConfiguration, false);

    URI nodeUri = node.getUri();
    assertTrue(nodeUri.getPort() > 0);
    checkHostName(nodeUri.getHost());

    CountDownPublisherListener<org.ros.message.std_msgs.Int64> publisherListener = CountDownPublisherListener
            .newDefault();
    Publisher<org.ros.message.std_msgs.Int64> publisher = node.newPublisher("test_addresses_pub",
            "std_msgs/Int64");
    publisher.addListener(publisherListener);
    assertTrue(publisherListener.awaitMasterRegistrationSuccess(1, TimeUnit.SECONDS));

    // Check the TCPROS server address via the XML-RPC API.
    SlaveClient slaveClient = new SlaveClient(new GraphName("test_addresses"), nodeUri);
    Response<ProtocolDescription> response = slaveClient.requestTopic(new GraphName("test_addresses_pub"),
            Lists.newArrayList(ProtocolNames.TCPROS));
    ProtocolDescription result = response.getResult();
    InetSocketAddress tcpRosAddress = result.getAdverstiseAddress().toInetSocketAddress();
    checkHostName(tcpRosAddress.getHostName());
}

From source file:org.sonar.ide.intellij.wsclient.WSClientFactory.java

/**
 * Workaround for http://jira.codehaus.org/browse/SONAR-1586
 *//*from ww  w .ja  v a2 s .com*/
private void configureProxy(DefaultHttpClient httpClient, Host server) {
    try {
        Proxy proxyData = getIntelliJProxyFor(server);
        if (proxyData != null) {
            InetSocketAddress address = (InetSocketAddress) proxyData.address();
            HttpConfigurable proxySettings = HttpConfigurable.getInstance();
            LOG.debug("Proxy for [" + address.getHostName() + "] - [" + address + "]");
            HttpHost proxy = new HttpHost(address.getHostName(), address.getPort());
            httpClient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);
            if (proxySettings.PROXY_AUTHENTICATION) {
                httpClient.getCredentialsProvider().setCredentials(
                        new AuthScope(address.getHostName(), address.getPort()),
                        new UsernamePasswordCredentials(proxySettings.PROXY_LOGIN,
                                proxySettings.getPlainProxyPassword()));
            }
        } else {
            LOG.debug("No proxy for [" + server.getHost() + "]");
        }
    } catch (Exception e) {
        LOG.error("Unable to configure proxy for sonar-ws-client", e);
    }
}