List of usage examples for java.net InetAddress getLocalHost
public static InetAddress getLocalHost() throws UnknownHostException
From source file:org.trpr.platform.batch.impl.spring.jmx.JobAdministrator.java
/** Constructor for this class*/ public JobAdministrator() { // get the host IP try {//from w w w.j a v a 2 s. c o m this.hostIP = InetAddress.getLocalHost().getHostAddress(); } catch (UnknownHostException e) { // this shouldnot happen. set the host IP to "Unresolved IP" this.hostIP = UNKNOWN_HOST; } this.hostStartTimeStamp = Calendar.getInstance(); }
From source file:com.vivareal.logger.appender.UDPAppender.java
/** * Open the UDP sender for the <b>RemoteHost</b> and <b>Port</b>. *///from ww w. j av a2 s .co m public void activateOptions() { try { localMachine = InetAddress.getLocalHost().getHostName(); } catch (UnknownHostException uhe) { try { localMachine = InetAddress.getLocalHost().getHostAddress(); } catch (UnknownHostException uhe2) { localMachine = "unknown"; } } // allow system property of log4japp to be primary if (application == null) { application = System.getProperty("application"); } else { if (System.getProperty("application") != null) { application = application + "-" + System.getProperty("application"); } } // if not passed in, allow null app (app property won't be set) connect(address, port); }
From source file:com.roncoo.controller.BaseController.java
/** * ?IP?//from ww w.j a va2s . c o m * * @return */ public String getIpAddr(HttpServletRequest request) { String ipAddress = null; ipAddress = request.getHeader("x-forwarded-for"); if (ipAddress == null || ipAddress.length() == 0 || "unknown".equalsIgnoreCase(ipAddress)) { ipAddress = request.getHeader("Proxy-Client-IP"); } if (ipAddress == null || ipAddress.length() == 0 || "unknown".equalsIgnoreCase(ipAddress)) { ipAddress = request.getHeader("WL-Proxy-Client-IP"); } if (ipAddress == null || ipAddress.length() == 0 || "unknown".equalsIgnoreCase(ipAddress)) { ipAddress = request.getRemoteAddr(); if (ipAddress.equals("127.0.0.1") || ipAddress.equals("0:0:0:0:0:0:0:1")) { // ????IP InetAddress inet = null; try { inet = InetAddress.getLocalHost(); } catch (UnknownHostException e) { e.printStackTrace(); } ipAddress = inet.getHostAddress(); } } // ?IPIP,IP',' if (ipAddress != null && ipAddress.length() > 15) { if (ipAddress.indexOf(",") > 0) { ipAddress = ipAddress.substring(0, ipAddress.indexOf(",")); } } return ipAddress; }
From source file:SignatureInfos.java
/** * @return hostname of the current server *///from ww w .ja v a2 s .c o m private String getHostname() { try { final InetAddress addr = InetAddress.getLocalHost(); return addr.getHostName(); } catch (final UnknownHostException e) { return "localhost"; } }
From source file:com.cws.esolutions.agent.AgentDaemon.java
public void init(final DaemonContext dContext) throws DaemonInitException { final String methodName = AgentDaemon.CNAME + "#init(final DaemonContext dContext) throws DaemonInitException"; if (DEBUG) {//from ww w.ja v a2s . c o m DEBUGGER.debug(methodName); DEBUGGER.debug("DaemonContext: {}", dContext); } JAXBContext context = null; Unmarshaller marshaller = null; final File xmlFile = new File( AgentConstants.CURRENT_DIRECTORY + System.getProperty(AgentDaemon.APP_CONFIG)); if (DEBUG) { DEBUGGER.debug("xmlFile: {}", xmlFile); } try { if (!(xmlFile.canRead())) { throw new DaemonInitException("No configuration file was located. Shutting down !"); } // set the app configuration context = JAXBContext.newInstance(ConfigurationData.class); marshaller = context.createUnmarshaller(); ConfigurationData configData = (ConfigurationData) marshaller.unmarshal(xmlFile); if (DEBUG) { DEBUGGER.debug("ConfigurationData: {}", configData); } String osName = System.getProperty("os.name").toLowerCase(); if (DEBUG) { DEBUGGER.debug("osName: {}", osName); } if (osName.indexOf("win") >= 0) { AgentDaemon.agentBean.setOsType(OSType.WINDOWS); } else if (osName.indexOf("mac") >= 0) { AgentDaemon.agentBean.setOsType(OSType.MAC); } else if ((osName.indexOf("nix") >= 0) || (osName.indexOf("sunos") >= 0) || (osName.indexOf("aix") >= 0)) { AgentDaemon.agentBean.setOsType(OSType.UNIX); } AgentDaemon.agentBean.setHostName(InetAddress.getLocalHost().getHostName()); AgentDaemon.agentBean.setConfigData(configData); } catch (JAXBException jx) { ERROR_RECORDER.error(jx.getMessage(), jx); this.exitCode = 1; stop(); } catch (UnknownHostException uhx) { ERROR_RECORDER.error(uhx.getMessage(), uhx); this.exitCode = 1; stop(); } }
From source file:se.crisp.codekvast.agent.daemon.worker.impl.ZipFileDataExporterImpl.java
private String getHostname() { try {// w w w. ja v a 2s .co m return InetAddress.getLocalHost().getHostName(); } catch (UnknownHostException e) { return "-unknown-"; } }
From source file:com.legstar.test.cixs.AbstractHttpClientTester.java
/** * Assuming the local machine is running JBoss ESB. * //from w w w . j a va 2 s. c o m * @return the local machine IP address */ protected static String getLocalIPAddress() { try { InetAddress addr = InetAddress.getLocalHost(); byte[] ipAddr = addr.getAddress(); String ipAddrStr = ""; for (int i = 0; i < ipAddr.length; i++) { if (i > 0) { ipAddrStr += "."; } ipAddrStr += ipAddr[i] & 0xFF; } return ipAddrStr; } catch (UnknownHostException e) { return ""; } }
From source file:io.hops.experiments.benchmarks.interleaved.InterleavedBenchmark.java
@Override protected BenchmarkCommand.Response processCommandInternal(BenchmarkCommand.Request command) throws IOException, InterruptedException { io.hops.experiments.benchmarks.common.config.Configuration config = ((InterleavedBenchmarkCommand.Request) command) .getConfig();/*from www.j a v a2 s .c o m*/ duration = config.getInterleavedBmDuration(); System.out.println("Starting " + command.getBenchMarkType() + " for duration " + duration); List workers = new ArrayList<Worker>(); for (int i = 0; i < numThreads; i++) { Callable worker = new Worker(config); workers.add(worker); } startTime = System.currentTimeMillis(); FailOverMonitor failOverTester = null; List<String> failOverLog = null; if (config.testFailover()) { boolean canIKillNamenodes = InetAddress.getLocalHost().getHostName() .compareTo(config.getNamenodeKillerHost()) == 0; if (canIKillNamenodes) { Logger.printMsg("Responsible for killing/restarting namenodes"); } failOverTester = startFailoverTestDeamon(config.getNameNodeRestartCommands(), config.getFailOverTestDuration(), config.getFailOverTestStartTime(), config.getNameNodeRestartTimePeriod(), canIKillNamenodes); } Logger.resetTimer(); executor.invokeAll(workers); // blocking call if (config.testFailover()) { failOverTester.stop(); failOverLog = failOverTester.getFailoverLog(); } long totalTime = System.currentTimeMillis() - startTime; System.out.println("Finished " + command.getBenchMarkType() + " in " + totalTime); double speed = (operationsCompleted.get() / (double) totalTime) * 1000; InterleavedBenchmarkCommand.Response response = new InterleavedBenchmarkCommand.Response(totalTime, operationsCompleted.get(), operationsFailed.get(), speed, opsExeTimes, avgLatency.getMean(), failOverLog, getAliveNNsCount()); return response; }
From source file:co.paralleluniverse.galaxy.netty.UDPComm.java
@ConstructorProperties({ "name", "cluster", "serverComm", "port" }) UDPComm(String name, Cluster cluster, ServerComm serverComm, int port) throws Exception { super(name, cluster, new SocketNodeAddressResolver(cluster, IP_COMM_PORT)); this.serverComm = serverComm; this.port = port; cluster.addNodeProperty(IP_ADDRESS, true, true, INET_ADDRESS_READER_WRITER); cluster.setNodeProperty(IP_ADDRESS, InetAddress.getLocalHost()); cluster.addNodeProperty(IP_COMM_PORT, true, false, ReaderWriters.INTEGER); cluster.setNodeProperty(IP_COMM_PORT, port); this.monitor = new UDPCommMonitor(name, this); }
From source file:io.crate.frameworks.mesos.Main.java
private static String currentHost() { String host;/*w w w . ja va2s. co m*/ try { host = InetAddress.getLocalHost().getHostName(); } catch (UnknownHostException e) { LOGGER.warn("Could not obtain hostname. Using localhost", e); host = "127.0.0.1"; } return host; }