List of usage examples for java.net InetAddress getLocalHost
public static InetAddress getLocalHost() throws UnknownHostException
From source file:com.cloudera.branchreduce.impl.thrift.VassalMain.java
private void initialize(String[] args) throws Exception { this.hostname = InetAddress.getLocalHost().getHostName(); this.socket = new ServerSocket(0); this.job = new BranchReduceJob(false, getConf()); this.masterHostname = args[0]; this.masterPort = Integer.valueOf(args[1]); }
From source file:net.dovemq.transport.connection.CAMQPConnectionManager.java
public synchronized static void initialize(String containerId) { if (CAMQPConnectionManager.containerId == null) { String hostName = "localhost"; try {/*from w ww.jav a2 s . c om*/ InetAddress localMachine = InetAddress.getLocalHost(); hostName = localMachine.getHostAddress(); log.debug("hostName: " + hostName); } catch (java.net.UnknownHostException uhe) { String errorMessage = "Caught UnknownHostException while resolving canonicalHostName: " + uhe.getMessage(); log.error(errorMessage); throw new CAMQPConnectionException(errorMessage); } CAMQPConnectionManager.containerId = String.format("%s@%s", containerId, hostName); log.info("Initialized DoveMQ endpoint ID: " + CAMQPConnectionManager.containerId); System.out.println("Initialized DoveMQ endpoint ID: " + CAMQPConnectionManager.containerId); } else { throw new IllegalStateException("CAMQPConnectionManager already initialized: containerId: " + CAMQPConnectionManager.containerId); } }
From source file:UUIDGenerator.java
protected static String getInitialUUID() { try {/* w w w. j av a2 s.c o m*/ if (System.class.getMethod("nanoTime", new Class[0]) != null) { useNano = true; } } catch (NoSuchMethodException ignore) { } if (myRand == null) { myRand = new Random(); } long rand = myRand.nextLong(); String sid; try { sid = InetAddress.getLocalHost().toString(); } catch (UnknownHostException e) { sid = Thread.currentThread().getName(); } StringBuffer sb = new StringBuffer(); sb.append(sid); sb.append(":"); sb.append(Long.toString(rand)); MessageDigest md5 = null; try { md5 = MessageDigest.getInstance("MD5"); } catch (NoSuchAlgorithmException e) { //System.out.println("Error: " + e); //todo heve to be properly handle } md5.update(sb.toString().getBytes()); byte[] array = md5.digest(); StringBuffer sb2 = new StringBuffer(); for (int j = 0; j < array.length; ++j) { int b = array[j] & 0xFF; sb2.append(Integer.toHexString(b)); } int begin = myRand.nextInt(); if (begin < 0) begin = begin * -1; begin = begin % 8; return sb2.toString().substring(begin, begin + 18).toUpperCase(); }
From source file:net.oneandone.jasmin.main.Servlet.java
private static String getHostname() { try {/*from ww w .j av a 2 s . c o m*/ return InetAddress.getLocalHost().getHostName(); } catch (UnknownHostException e) { LOG.error("unknown hostname", e); return "unknown"; } }
From source file:io.udvi.amqp.mq.transport.connection.CAMQPConnectionManager.java
public synchronized static void initialize(String containerId) { if (CAMQPConnectionManager.containerId == null) { String hostName = "localhost"; try {/* ww w. j a va2 s . c o m*/ InetAddress localMachine = InetAddress.getLocalHost(); hostName = localMachine.getHostAddress(); log.debug("hostName: " + hostName); } catch (java.net.UnknownHostException uhe) { String errorMessage = "Caught UnknownHostException while resolving canonicalHostName: " + uhe.getMessage(); log.error(errorMessage); throw new CAMQPConnectionException(errorMessage); } CAMQPConnectionManager.containerId = String.format("%s@%s", containerId, hostName); log.info("Initialized UdviMQ endpoint ID: " + CAMQPConnectionManager.containerId); System.out.println("Initialized UdviMQ endpoint ID: " + CAMQPConnectionManager.containerId); } else { throw new IllegalStateException("CAMQPConnectionManager already initialized: containerId: " + CAMQPConnectionManager.containerId); } }
From source file:com.example.HolaRestController.java
@RequestMapping(method = RequestMethod.GET, value = "/hola", produces = "text/plain") public String hola() throws UnknownHostException { String hostname = null;/* w w w . ja v a 2 s .c o m*/ try { hostname = InetAddress.getLocalHost().getHostAddress(); } catch (UnknownHostException e) { hostname = "unknown"; } return saying + " " + hostname; }
From source file:com.ut.healthelink.errorHandling.ExceptionControllerAdvice.java
@ExceptionHandler(Exception.class) public ModelAndView exception(HttpSession session, Exception e, Authentication authentication) throws Exception { ModelAndView mav = new ModelAndView(); mav.setViewName("/exception"); mailMessage messageDetails = new mailMessage(); messageDetails.settoEmailAddress("dphuniversaltranslator@gmail.com"); messageDetails.setfromEmailAddress("dphuniversaltranslator@gmail.com"); messageDetails.setmessageSubject("Exception Error " + InetAddress.getLocalHost().getHostAddress()); StringBuilder sb = new StringBuilder(); /* If a user is logged in then send along the user details */ if (session.getAttribute("userDetails") != null || authentication != null) { User userInfo = (User) session.getAttribute("userDetails"); if (userInfo == null && authentication != null) { // see if it is an admin that is logged in userInfo = usermanager.getUserByUserName(authentication.getName()); }//from ww w. j a va 2 s. c o m if (userInfo != null) { sb.append("Logged in User: " + userInfo.getFirstName() + " " + userInfo.getLastName() + " (ID: " + userInfo.getId() + ")"); sb.append(System.getProperty("line.separator")); sb.append("User OrgId: " + userInfo.getOrgId()); sb.append(System.getProperty("line.separator")); } } sb.append("Error: " + e); sb.append("<br /><br />"); sb.append("Time: " + new Date()); sb.append("<br /><br />"); sb.append("Message: " + e.getMessage()); sb.append("<br /><br />"); sb.append("Stack Trace: " + Arrays.toString(e.getStackTrace())); messageDetails.setmessageBody(sb.toString()); emailMessageManager.sendEmail(messageDetails); /*mav.addObject("messageBody",sb.toString());*/ return mav; }
From source file:cloud.thrift.server.conf.ZooKeeperConfig.java
public ZkClient registService() { String servicePath = "/" + serviceName;// ZkClient zkClient = new ZkClient(serverList); boolean rootExists = zkClient.exists(servicePath); if (!rootExists) { zkClient.createPersistent(servicePath); }/*from w ww.j a v a2 s . c o m*/ InetAddress addr = null; try { addr = InetAddress.getLocalHost(); } catch (UnknownHostException e) { e.printStackTrace(); } String ip = addr.getHostAddress().toString(); String serviceInstance = System.nanoTime() + "-" + ip; // ?? zkClient.createEphemeral(servicePath + "/" + serviceInstance); System.out.println("???" + servicePath + "/" + serviceInstance); return zkClient; }
From source file:com.googlecode.fascinator.common.storage.StorageUtils.java
/** * Generates a Object identifier for a given file * /*w w w.j a v a 2s.c o m*/ * @param file the File to store * @return a String object id */ public static String generateOid(File file) { // MD5 hash the file path, String path = FilenameUtils.separatorsToUnix(file.getAbsolutePath()); String hostname = "localhost"; try { hostname = InetAddress.getLocalHost().getCanonicalHostName(); } catch (UnknownHostException uhe) { } String username = System.getProperty("user.name", "anonymous"); // log.debug("Generating OID path:'{}' hostname:'{}' username:'{}'", // new String[] { path, hostname, username }); return DigestUtils.md5Hex(path + hostname + username); }
From source file:me.adaptive.core.metrics.ServerMetricsProducer.java
@Scheduled(fixedRate = 30000) public void sendServerMetrics() { MetricServerEntity metricServer = new MetricServerEntity(); Map<String, String> attributes = new HashMap<String, String>(); // Hostname/*from ww w.j a va 2 s . c o m*/ try { metricServer.setHostname(InetAddress.getLocalHost().getHostName()); } catch (UnknownHostException e) { metricServer.setHostname("undefined"); System.out.println(e.getMessage()); } SystemInfo si = new SystemInfo(); HardwareAbstractionLayer hal = si.getHardware(); // Memory Long memAvailable = hal.getMemory().getAvailable(); Long memUsed = hal.getMemory().getTotal() - memAvailable; attributes.put(Constants.MEM_USED, String.valueOf(memUsed)); attributes.put(Constants.MEM_AVAILABLE, String.valueOf(memAvailable)); // CPU // Get the first CPU to get the system load at that time Double systemLoad = hal.getProcessors()[0].getSystemCpuLoad(); attributes.put(Constants.SYSTEM_CPU_LOAD, String.valueOf(systemLoad)); // FileSystem // Get the first FileSystem supposing there is only one disk Long diskAvailable = hal.getFileStores()[0].getUsableSpace(); Long diskUsed = hal.getFileStores()[0].getTotalSpace() - diskAvailable; attributes.put(Constants.DISK_USED, String.valueOf(diskUsed)); attributes.put(Constants.DISK_AVAILABLE, String.valueOf(diskAvailable)); metricServer.setAttributes(attributes); this.jmsTemplate.convertAndSend(metricServer); }