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:com.wealdtech.jackson.modules.InetSocketAddressSerializer.java

@Override
public void serialize(final InetSocketAddress value, final JsonGenerator jgen,
        final SerializerProvider provider) throws IOException {
    jgen.writeString(value.getHostName() + ":" + value.getPort());
}

From source file:com.groupon.jenkins.util.HttpPoster.java

private HttpHost getProxy(HttpUriRequest method) throws URIException {

    ProxyConfiguration proxy = Jenkins.getInstance().proxy;
    if (proxy == null)
        return null;

    Proxy p = proxy.createProxy(method.getURI().getHost());
    switch (p.type()) {
    case DIRECT://from  ww w  .  j  a  va2  s .c  o  m
        return null;
    case HTTP:
        InetSocketAddress sa = (InetSocketAddress) p.address();
        return new HttpHost(sa.getHostName(), sa.getPort());
    case SOCKS:
    default:
        return null;
    }
}

From source file:alluxio.cli.fs.command.LeaderCommand.java

@Override
public int run(CommandLine cl) {
    try (CloseableResource<FileSystemMasterClient> client = FileSystemContext.INSTANCE
            .acquireMasterClientResource()) {
        try {//www  .  j a v  a 2 s  . c o  m
            InetSocketAddress address = client.get().getAddress();
            System.out.println(address.getHostName());

            List<InetSocketAddress> addresses = Arrays.asList(address);
            MasterInquireClient inquireClient = new PollingMasterInquireClient(addresses,
                    () -> new ExponentialBackoffRetry(50, 100, 2));
            try {
                inquireClient.getPrimaryRpcAddress();
            } catch (UnavailableException e) {
                System.err.println("The leader is not currently serving requests.");
            }
        } catch (UnavailableException e) {
            System.err.println("Failed to get the leader master.");
        }
    }
    return 0;
}

From source file:com.nl.util.redis.config.JedisClusterConfig.java

/**
 * Returns nodes./* w w  w .ja v a2s .co  m*/
 * @return list of node information
 */
public Set<HostAndPort> getNodes() {
    Set<HostAndPort> ret = new HashSet<>();
    for (InetSocketAddress node : nodes) {
        ret.add(new HostAndPort(node.getHostName(), node.getPort()));
    }
    return ret;
}

From source file:org.apache.hadoop.hdfsproxy.HdfsProxy.java

private void initialize(Configuration conf) throws IOException {
    sslAddr = getSslAddr(conf);//  w w w  .ja v a2  s .c o  m
    String nn = conf.get("hdfsproxy.dfs.namenode.address");
    if (nn == null)
        throw new IOException("HDFS NameNode address is not specified");
    InetSocketAddress nnAddr = NetUtils.createSocketAddr(nn);
    LOG.info("HDFS NameNode is at: " + nnAddr.getHostName() + ":" + nnAddr.getPort());

    Configuration sslConf = new Configuration(false);
    sslConf.addResource(conf.get("hdfsproxy.https.server.keystore.resource", "ssl-server.xml"));
    // unit testing
    sslConf.set("proxy.http.test.listener.addr", conf.get("proxy.http.test.listener.addr"));

    this.server = new ProxyHttpServer(sslAddr, sslConf);
    this.server.setAttribute("proxy.https.port", server.getPort());
    this.server.setAttribute("name.node.address", nnAddr);
    this.server.setAttribute(JspHelper.CURRENT_CONF, new Configuration());
    this.server.addGlobalFilter("ProxyFilter", ProxyFilter.class.getName(), null);
    this.server.addServlet("listPaths", "/listPaths/*", ProxyListPathsServlet.class);
    this.server.addServlet("data", "/data/*", ProxyFileDataServlet.class);
    this.server.addServlet("streamFile", "/streamFile/*", ProxyStreamFile.class);
}

From source file:com.urswolfer.intellij.plugin.gerrit.rest.ProxyHttpClientBuilderExtension.java

@Override
public CredentialsProvider extendCredentialProvider(HttpClientBuilder httpClientBuilder,
        CredentialsProvider credentialsProvider, GerritAuthData authData) {
    HttpConfigurable proxySettings = HttpConfigurable.getInstance();
    IdeaWideProxySelector ideaWideProxySelector = new IdeaWideProxySelector(proxySettings);

    // This will always return at least one proxy, which can be the "NO_PROXY" instance.
    List<Proxy> proxies = ideaWideProxySelector.select(URI.create(authData.getHost()));

    // Find the first real proxy with an address type we support.
    for (Proxy proxy : proxies) {
        SocketAddress socketAddress = proxy.address();

        if (HttpConfigurable.isRealProxy(proxy) && socketAddress instanceof InetSocketAddress) {
            InetSocketAddress address = (InetSocketAddress) socketAddress;
            HttpHost proxyHttpHost = new HttpHost(address.getHostName(), address.getPort());
            httpClientBuilder.setProxy(proxyHttpHost);

            // Here we use the single username/password that we got from IDEA's settings. It feels kinda strange
            // to use these credential but it's probably what the user expects.
            if (proxySettings.PROXY_AUTHENTICATION) {
                AuthScope authScope = new AuthScope(proxySettings.PROXY_HOST, proxySettings.PROXY_PORT);
                UsernamePasswordCredentials credentials = new UsernamePasswordCredentials(
                        proxySettings.PROXY_LOGIN, proxySettings.getPlainProxyPassword());
                credentialsProvider.setCredentials(authScope, credentials);
                break;
            }//from w w w.j  a v  a  2s .c o m
        }
    }
    return credentialsProvider;
}

From source file:org.apache.hadoop.mapred.tools.MRZKFailoverController.java

@Override
protected byte[] targetToData(HAServiceTarget target) {
    InetSocketAddress addr = target.getAddress();

    return ActiveNodeInfo.newBuilder().setHostname(addr.getHostName()).setPort(addr.getPort())
            .setZkfcPort(target.getZKFCAddress().getPort()).setNameserviceId(localJTTarget.getLogicalName())
            .setNamenodeId(localJTTarget.getJobTrackerId()).build().toByteArray();
}

From source file:org.siddhiesb.transport.http.conn.ClientConnFactory.java

private SSLContext getSSLContext(final IOSession iosession) {
    InetSocketAddress address = (InetSocketAddress) iosession.getRemoteAddress();
    String host = address.getHostName() + ":" + address.getPort();
    SSLContext customContext = null;
    if (sslByHostMap != null) {
        // See if there's a custom SSL profile configured for this server
        customContext = sslByHostMap.get(host);
    }//from  w  w w .  j  a  v  a2s  .  c o m
    if (customContext != null) {
        return customContext;
    } else {
        return ssl != null ? ssl.getContext() : null;
    }
}

From source file:org.apache.hadoop.yarn.server.webproxy.WebAppProxyServer.java

/**
 * Log in as the Kerberose principal designated for the proxy
 * @param conf the configuration holding this information in it.
 * @throws IOException on any error.//from   w ww.  ja va2  s.c  o m
 */
protected void doSecureLogin(Configuration conf) throws IOException {
    InetSocketAddress socAddr = getBindAddress(conf);
    SecurityUtil.login(conf, YarnConfiguration.PROXY_KEYTAB, YarnConfiguration.PROXY_PRINCIPAL,
            socAddr.getHostName());
}

From source file:org.apache.hadoop.metrics2.sink.TSDBSink.java

public void init(SubsetConfiguration conf) {
    this.LOG.info("Initializing TSDBSink");

    if (conf.getString("slave.host.name") != null)
        this.fqdn = conf.getString("slave.host.name");
    else {// w w w . j  av  a2 s .  c  o m
        try {
            this.fqdn = DNS.getDefaultHost(conf.getString("dfs.datanode.dns.interface", "default"),
                    conf.getString("dfs.datanode.dns.nameserver", "default"));
        } catch (UnknownHostException exception) {
            this.LOG.error(exception);
        }
    }

    this.TSDBServers = Servers.parse(conf.getString("servers"), 4242);
    try {
        InetSocketAddress address = (InetSocketAddress) this.TSDBServers.get(0);
        this.collector = new Socket(address.getHostName(), address.getPort());
        this.TSDBEndPoint = new DataOutputStream(this.collector.getOutputStream());
    } catch (IOException exception) {
        this.LOG.error(exception);
    }
}