Example usage for org.openqa.selenium.net NetworkUtils getIp4NonLoopbackAddressOfThisMachine

List of usage examples for org.openqa.selenium.net NetworkUtils getIp4NonLoopbackAddressOfThisMachine

Introduction

In this page you can find the example usage for org.openqa.selenium.net NetworkUtils getIp4NonLoopbackAddressOfThisMachine.

Prototype

public InetAddress getIp4NonLoopbackAddressOfThisMachine() 

Source Link

Document

Returns a non-loopback IP4 hostname of the local host.

Usage

From source file:org.openqa.grid.common.RegistrationRequest.java

License:Apache License

private static String guessHost(String host) {
    if ("ip".equalsIgnoreCase(host)) {
        NetworkUtils util = new NetworkUtils();
        return util.getIp4NonLoopbackAddressOfThisMachine().getHostAddress();
    } else if ("host".equalsIgnoreCase(host)) {
        NetworkUtils util = new NetworkUtils();
        return util.getIp4NonLoopbackAddressOfThisMachine().getHostName();
    } else {//  ww w. j  a  v a  2 s  . c o m
        return host;
    }
}

From source file:org.openqa.grid.web.Hub.java

License:Apache License

public Hub(GridHubConfiguration config) {
    Level logLevel = config.isDebug() ? Level.FINE : Level.INFO;
    Logger.getLogger("").setLevel(logLevel);

    for (Handler handler : Logger.getLogger("").getHandlers()) {
        Logger.getLogger("").removeHandler(handler);
    }/*from  www  .  j  a v  a  2 s .c o  m*/

    String logFilename = config.getLogFilename() == null ? RemoteControlConfiguration.getDefaultLogOutFile()
            : config.getLogFilename();
    if (logFilename != null) {
        try {
            Handler logFile = new FileHandler(new File(logFilename).getAbsolutePath(), true);
            logFile.setFormatter(new TerseFormatter(true));
            logFile.setLevel(logLevel);
            Logger.getLogger("").addHandler(logFile);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    } else {
        Handler console = new ConsoleHandler();
        console.setLevel(logLevel);
        Logger.getLogger("").addHandler(console);
    }

    registry = Registry.newInstance(this, config);

    if (config.getHost() != null) {
        host = config.getHost();
    } else {
        NetworkUtils utils = new NetworkUtils();
        host = utils.getIp4NonLoopbackAddressOfThisMachine().getHostAddress();
    }
    this.port = config.getPort();

    for (String s : config.getServlets()) {
        Class<? extends Servlet> servletClass = ExtraServletUtil.createServlet(s);
        if (servletClass != null) {
            String path = "/grid/admin/" + servletClass.getSimpleName() + "/*";
            log.info("binding " + servletClass.getCanonicalName() + " to " + path);
            addServlet(path, servletClass);
        }
    }

    initServer();

}