Example usage for java.net InetAddress getHostName

List of usage examples for java.net InetAddress getHostName

Introduction

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

Prototype

public String getHostName() 

Source Link

Document

Gets the host name for this IP address.

Usage

From source file:Server.ConnectionHandler.java

private void initialize(Socket client) {
    this.client = client;
    client_in.addListener(this);
    InetAddress clientAdress = client.getInetAddress();
    hostName = clientAdress.getHostName();
    hostAddress = clientAdress.getHostAddress();

    System.out.println("Client accepted: ");
    System.out.println("Hostname: " + hostName);
    System.out.println("Hostaddress: " + hostAddress);
    System.out.println("Session token: " + my_session_token);
    System.out.println("Nickname : " + my_nickname + " (will be changed in a few milliseconds)");
}

From source file:org.apache.whirr.service.hbase.integration.HBaseServiceController.java

private void getScanner(InetAddress thriftAddress) throws Exception {
    TTransport transport = new TSocket(thriftAddress.getHostName(), HBaseThriftServerClusterActionHandler.PORT);
    transport.open();//from w w  w .j  av a2 s .c o  m
    LOG.info("Connected to thrift server.");
    LOG.info("Waiting for .META. table...");
    TProtocol protocol = new TBinaryProtocol(transport, true, true);
    Hbase.Client client = new Hbase.Client(protocol);
    int scannerId = client.scannerOpen(HConstants.META_TABLE_NAME, Bytes.toBytes(""), null);
    client.scannerClose(scannerId);
    thriftClient = client;
}

From source file:org.nuxeo.runtime.management.ServerLocatorService.java

protected String doGetHostname() {
    if (hostname != null) {
        return hostname;
    }/*from w w  w  .j  ava2 s . c o m*/
    try {
        InetAddress addr = InetAddress.getLocalHost();
        hostname = addr.getHostName();
    } catch (UnknownHostException e) {
        hostname = "localhost";
    }
    return hostname;
}

From source file:uk.ac.ebi.fg.annotare2.web.server.services.MessengerImpl.java

@Override
public void send(String note, Throwable x, User user) {
    try {// www. j  av a2 s . c  o  m
        Thread currentThread = Thread.currentThread();
        String hostName = "unknown";
        try {
            InetAddress localMachine = InetAddress.getLocalHost();
            hostName = localMachine.getHostName();
        } catch (UnknownHostException xx) {
            log.error("Unable to obtain a hostname", xx);
        }
        send(EXCEPTION_REPORT_TEMPLATE,
                ImmutableMap.of("application.host", hostName, "application.thread", currentThread.getName(),
                        "exception.note", note, "exception.message",
                        (null != x && null != x.getMessage()) ? x.getMessage() : "", "exception.stack",
                        getStackTrace(x)),
                user, null, true);
    } catch (Throwable xxx) {
        log.error("[SEVERE] Unable to send exception report, error:", xxx);
    }
}

From source file:net.gplatform.sudoor.server.test.unit.TestUtils.java

public String getEmbeddedServletContainerBaseURL() {
    InetAddress address = abstractConfigurableEmbeddedServletContainer.getAddress();
    String addressStr = "localhost";
    if (address != null) {
        addressStr = address.getHostName();
    }/*from   w  ww.  ja  v a 2 s . co  m*/

    int port = abstractConfigurableEmbeddedServletContainer.getPort();
    String contextPath = abstractConfigurableEmbeddedServletContainer.getContextPath();

    return "http://" + addressStr + ":" + port + contextPath;
}

From source file:com.github.kpavlov.ssl.DynamicSSLSocketFactory.java

@Override
public Socket createSocket(InetAddress address, int port, InetAddress localAddress, int localPort)
        throws IOException {
    return getSslSocketFactory(address.getHostName()).createSocket(address, port, localAddress, localPort);
}

From source file:org.mariotaku.twidere.util.net.HostResolvedSocketFactory.java

@Override
public Socket createSocket(InetAddress address, int port, InetAddress localAddress, int localPort)
        throws IOException {
    final String hostName = address.getHostName();
    final String resolvedHost = resolver.resolve(hostName);
    if (resolvedHost != null && !resolvedHost.equals(hostName)) {
        if (InetAddressUtils.isIPv6Address(resolvedHost)) {
            final byte[] resolvedAddress = Inet6Address.getByName(resolvedHost).getAddress();
            return new Socket(InetAddress.getByAddress(hostName, resolvedAddress), port, localAddress,
                    localPort);// ww w. jav  a2s .c  o  m
        } else if (InetAddressUtils.isIPv4Address(resolvedHost)) {
            final byte[] resolvedAddress = Inet4Address.getByName(resolvedHost).getAddress();
            return new Socket(InetAddress.getByAddress(hostName, resolvedAddress), port, localAddress,
                    localPort);
        }
    }
    return defaultFactory.createSocket(address, port, localAddress, localPort);
}

From source file:com.edmunds.etm.management.api.HostAddress.java

/**
 * Gets the host name.//  www .  j av  a 2  s .co m
 *
 * @return host name
 */
public String getHostName() {
    if (hostName == null) {
        try {
            InetAddress addr = InetAddress.getByName(host);
            hostName = addr.getHostName();
        } catch (UnknownHostException e) {
            hostName = null;
        }
    }
    return hostName;
}

From source file:org.springframework.amqp.rabbit.connection.AbstractConnectionFactory.java

final protected String getDefaultHostName() {
    String temp;/*from www.  java  2s  .c  o  m*/
    try {
        InetAddress localMachine = InetAddress.getLocalHost();
        temp = localMachine.getHostName();
        logger.debug("Using hostname [" + temp + "] for hostname.");
    } catch (UnknownHostException e) {
        logger.warn("Could not get host name, using 'localhost' as default value", e);
        temp = "localhost";
    }
    return temp;
}

From source file:org.wso2.carbon.as.monitoring.collector.jmx.CollectorUtil.java

/**
 * Feed the serverAddress, serverName, clusterDomain and ClusterSubDomain values to the event.
 * Set "-" as the value for any param which cannot be retrieved because of errors etc...
 *
 * @param event The monitoring event// w  w w .j av a 2s  .  c om
 */
public void mapMetaData(MonitoringEvent event) {
    String serverAddress = "-";
    String serverName = "-";

    try {
        InetAddress ip = InetAddress.getLocalHost();
        serverAddress = ip.getHostAddress();
        serverName = ip.getHostName();
    } catch (UnknownHostException ignored) {
        // we miss the host address & host name
        // no alternative. not a blocker.
        if (LOG.isDebugEnabled()) {
            LOG.debug("Exception occurred while getting local host InetAddress.", ignored);
        }
    }

    event.setServerAddress(serverAddress);
    event.setServerName(serverName);
    event.setClusterDomain(getClusterDomain());
    event.setClusterSubDomain(getClusterSubDomain());
}