List of usage examples for java.net InetAddress getLocalHost
public static InetAddress getLocalHost() throws UnknownHostException
From source file:leap.webunit.client.THttpClientImpl.java
@Override public THttpClient addHostName(String hostName) { try {//from w w w. j av a2 s . c om dnsResolver.add(hostName, InetAddress.getLocalHost()); } catch (UnknownHostException e) { throw new IllegalStateException("Cannot add host name '" + hostName + "', " + e.getMessage(), e); } return this; }
From source file:fr.univlorraine.mondossierweb.photo.PhotoUnivLorraineImpl.java
public void initForServer(String loginUser) { String hostadress = ""; try {/*from www .ja v a 2 s .c o m*/ hostadress = InetAddress.getLocalHost().getHostAddress(); tc = photoClient.getTicket(PhotoClient.MODE_NORMAL, hostadress, "ID", "NONE", loginUser); } catch (UnknownHostException e1) { LOG.error("PhotoUnivLorraineImplCodEtu-Erreur initForServer loginUser:" + loginUser + " hostadress : " + hostadress, e1); } catch (PhotoClientException e) { LOG.error("PhotoUnivLorraineImplCodEtu-Erreur initForServer loginUser:" + loginUser + " hostadress : " + hostadress, e); tc = null; } forserver = true; }
From source file:com.edmunds.common.configuration.dns.ConfigurationUtilImpl.java
private Map<String, String> buildTokenMap() { Validate.notNull(configuration, "ConfigurationUtilImpl.configuration is null"); Validate.notNull(connection, "ConfigurationUtilImpl.connection is null"); Map<String, String> tokenMap = new HashMap<String, String>(); tokenMap.put(ENVIRONMENT_REPLACE_TOKEN, getLegacyEnvironmentName()); tokenMap.put(URL_PREFIX_REPLACE_TOKEN, configuration.getUrlLegacyPrefix()); tokenMap.put(TOKEN_LOGICAL_ENVIRONMENT_NAME, configuration.getLogicalEnvironmentName()); tokenMap.put(TOKEN_ENVIRONMENT_INDEX, configuration.getEnvironmentIndex()); final String urlPrefix = configuration.getUrlPrefix(); tokenMap.put(TOKEN_URL_PREFIX, urlPrefix); tokenMap.put(TOKEN_LOCAL_ENVIRONMENT_NAME, configuration.getEnvironmentName()); tokenMap.put(TOKEN_LOCAL_ENVIRONMENT_DATA_CENTER, configuration.getDataCenter()); tokenMap.put(TOKEN_LOCAL_ENVIRONMENT_SITE, configuration.getSite()); tokenMap.put(TOKEN_INTERNAL_ENVIRONMENT_NAME, connection.getInternalEnvironmentName()); tokenMap.put(TOKEN_INTERNAL_ENVIRONMENT_DATA_CENTER, connection.getInternalDataCenter()); String prefixNoDash = null;//from www. jav a2 s . c o m if (urlPrefix != null) { prefixNoDash = urlPrefix.endsWith("-") ? urlPrefix.substring(0, urlPrefix.length() - 1) : urlPrefix; } tokenMap.put(TOKEN_URL_PREFIX_NODASH, prefixNoDash); try { String hostName = InetAddress.getLocalHost().getHostName(); tokenMap.put(HOST_REPLACE_TOKEN, hostName); } catch (UnknownHostException exc) { log.warn("Error looking up host name. No substitution will be performed: " + exc.getMessage(), exc); } try { String canonicalHostName = InetAddress.getLocalHost().getCanonicalHostName(); tokenMap.put(CANONICAL_HOST_REPLACE_TOKEN, canonicalHostName); } catch (UnknownHostException exc) { log.warn("Error looking up host name. No substitution will be performed: " + exc.getMessage(), exc); } return tokenMap; }
From source file:calculus.backend.JpaConfig.java
/** * /*w w w.java2s. c o m*/ */ private void loadEnviromentConfig() { LOG.info("Cargando configuracion de la BDs en funcion del ambiente .."); String env = "RD00155DFBD797"; //DEFAULT_ENV try { env = InetAddress.getLocalHost().getHostName(); } catch (UnknownHostException ex) { LOG.error(ex.getMessage(), ex); } LOG.info("env=" + env); if (env.equals("localhost")) { //postgres local this.driver = "org.postgresql.Driver"; this.url = "jdbc:postgresql://localhost:5432/pis2016"; this.user = "postgres"; this.pass = "user"; this.dataBase = Database.POSTGRESQL; this.poolSize = 1; } else if (env.equals("RD00155DFBD985")) { //AZURE_PROD this.driver = "org.postgresql.Driver"; this.url = "jdbc:postgresql://nutty-custard-apple.db.elephantsql.com:5432/gxedfpdw"; this.user = "gxedfpdw"; this.pass = "Ci05wYOZACatHbnzav_VmHiSIF6J-fNB"; this.dataBase = Database.POSTGRESQL; this.poolSize = 1; } else if (env.equals("abentan-PC")) { this.driver = "com.mysql.jdbc.Driver"; this.url = "jdbc:mysql://localhost:3306/pis2016"; this.user = "pis2016"; this.pass = "pis2016"; this.dataBase = Database.MYSQL; this.poolSize = 5; } else if (env.equals("RD00155DFBD797")) { //AZURE_BETA this.driver = "org.postgresql.Driver"; this.url = "jdbc:postgresql://nutty-custard-apple.db.elephantsql.com:5432/fbonhmwr"; this.user = "fbonhmwr"; this.pass = "4axmS5tbJRUh_f5j8K2LBQZ8wrEO4jBR"; this.dataBase = Database.POSTGRESQL; this.poolSize = 1; } else if (env.equals("MacBook-Pro.local")) { this.driver = "org.postgresql.Driver"; this.url = "jdbc:postgresql://localhost:5432/pis2016"; this.user = "tavidian"; this.pass = ""; this.dataBase = Database.POSTGRESQL; this.poolSize = 1; } else if (env.equals("NetPC")) { //postgres local this.driver = "org.postgresql.Driver"; this.url = "jdbc:postgresql://localhost:5432/postgres"; this.user = "postgres"; this.pass = "4512161-7"; this.dataBase = Database.POSTGRESQL; this.poolSize = 1; } else if (env.equals("MARTINV-DELL")) { //postgres local this.driver = "org.postgresql.Driver"; this.url = "jdbc:postgresql://localhost:5432/postgres"; this.user = "postgres"; this.pass = "user"; this.dataBase = Database.POSTGRESQL; this.poolSize = 1; } else if (env.equals("PC3")) { this.driver = "org.postgresql.Driver"; this.url = "jdbc:postgresql://localhost:5432/pis2016"; this.user = "postgres"; this.pass = "admin"; this.dataBase = Database.POSTGRESQL; this.poolSize = 1; } }
From source file:com.lunix.cheata.gui.CheataMainMenu.java
public CheataMainMenu() { try {//from www . j a v a 2 s . c om if (!"127.0.0.1".equals(InetAddress.getLocalHost().getHostAddress().toString())) { try { URL u = new URL( "https://raw.githubusercontent.com/CheataClient/CheataClientSrc/master/VERSION"); URLConnection conn = u.openConnection(); BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream())); StringBuffer buffer = new StringBuffer(); String inputLine; while ((inputLine = in.readLine()) != null) buffer.append(inputLine); in.close(); if (Double.parseDouble(buffer.toString()) > Client.getVer()) { mc.logger.info("Latest version is " + buffer.toString()); mc.logger.info("Your version is " + Double.toString(Client.getVer())); updateVersion = buffer.toString(); needsUpdate = true; } else { mc.logger.info("Current pre-release is " + Double.toString(Client.getVer())); } } catch (IOException e) { System.out.println("Unable to open github page"); } } } catch (UnknownHostException e) { System.out.println("Unable to connect to host"); } Client.setInGame(false); this.openGLWarning2 = field_96138_a; this.field_183502_L = false; this.splashText = "missingno"; IResource iresource = null; try { List<String> list = Lists.<String>newArrayList(); iresource = Minecraft.getMinecraft().getResourceManager().getResource(splashTexts); BufferedReader bufferedreader = new BufferedReader( new InputStreamReader(iresource.getInputStream(), Charsets.UTF_8)); String s; while ((s = bufferedreader.readLine()) != null) { s = s.trim(); if (!s.isEmpty()) { list.add(s); } } if (!list.isEmpty()) { while (true) { this.splashText = (String) list.get(RANDOM.nextInt(list.size())); if (this.splashText.hashCode() != 125780783) { break; } } } } catch (IOException var8) { ; } finally { IOUtils.closeQuietly((Closeable) iresource); } this.updateCounter = RANDOM.nextFloat(); this.openGLWarning1 = ""; if (!GLContext.getCapabilities().OpenGL20 && !OpenGlHelper.areShadersSupported()) { this.openGLWarning1 = I18n.format("title.oldgl1", new Object[0]); this.openGLWarning2 = I18n.format("title.oldgl2", new Object[0]); this.openGLWarningLink = "https://help.mojang.com/customer/portal/articles/325948?ref=game"; } }
From source file:com.flipkart.aesop.runtime.producer.hbase.HBaseEventProducer.java
/** * Interface method implementation. Checks for mandatory dependencies and creates the SEP consumer * @see org.springframework.beans.factory.InitializingBean#afterPropertiesSet() *///from w w w .j av a 2 s. co m public void afterPropertiesSet() throws Exception { Assert.notNull(this.zkQuorum, "'zkQuorum' cannot be null. Zookeeper quorum list must be specified. This HBase Events producer will not be initialized"); if (this.zkQuorum.contains(":")) { throw new IllegalStateException( "'zkQuorum' is comma separated list of only hosts. Specify port using 'zkClientPort' : " + this.zkQuorum); } Assert.notNull(this.sepEventMapper, "'sepEventMapper' cannot be null. No WAL edits event mapper found. This HBase Events producer will not be initialized"); if (this.zkQuorum.contains(LOCAL_HOST_NAME)) { // we dont want 'localhost' to resolve to other names - say from /etc/hosts if ZK is also running locally during testing this.localHost = LOCAL_HOST_NAME; } else { this.localHost = InetAddress.getLocalHost().getHostName(); } }
From source file:imageviewer.system.ImageViewerClient.java
private void initialize(CommandLine args) { // First, process all the different command line arguments that we // need to override and/or send onwards for initialization. boolean fullScreen = (args.hasOption("fullscreen")) ? true : false; String dir = (args.hasOption("dir")) ? args.getOptionValue("dir") : null; String type = (args.hasOption("type")) ? args.getOptionValue("type") : "DICOM"; String prefix = (args.hasOption("client")) ? args.getOptionValue("client") : null; LOG.info("Java home environment: " + System.getProperty("java.home")); // Logging system taken care of through properties file. Check // for JAI. Set up JAI accordingly with the size of the cache // tile and to recycle cached tiles as needed. verifyJAI();//from w ww.j a va 2s . co m TileCache tc = JAI.getDefaultInstance().getTileCache(); tc.setMemoryCapacity(32 * 1024 * 1024); TileScheduler ts = JAI.createTileScheduler(); ts.setPriority(Thread.MAX_PRIORITY); JAI.getDefaultInstance().setTileScheduler(ts); JAI.getDefaultInstance().setRenderingHint(JAI.KEY_CACHED_TILE_RECYCLING_ENABLED, Boolean.TRUE); // Set up the frame and everything else. First, try and set the // UI manager to use our look and feel because it's groovy and // lets us control the GUI components much better. try { UIManager.setLookAndFeel(new ImageViewerLookAndFeel()); LookAndFeelAddons.setAddon(ImageViewerLookAndFeelAddons.class); } catch (Exception exc) { LOG.error("Could not set imageViewer L&F."); } // Load up the ApplicationContext information... ApplicationContext ac = ApplicationContext.getContext(); if (ac == null) { LOG.error("Could not load configuration, exiting."); System.exit(1); } // Override the client node information based on command line // arguments...Make sure that the files are there, otherwise just // default to a local configuration. String hostname = new String("localhost"); try { hostname = InetAddress.getLocalHost().getHostName(); } catch (Exception exc) { } String[] gatewayConfigs = (prefix != null) ? (new String[] { "resources/server/" + prefix + "GatewayConfig.xml", (String) ac.getProperty(ApplicationContext.IMAGESERVER_GATEWAY_CONFIG), "resources/server/" + hostname + "GatewayConfig.xml", "resources/server/localGatewayConfig.xml" }) : (new String[] { (String) ac.getProperty(ApplicationContext.IMAGESERVER_GATEWAY_CONFIG), "resources/server/" + hostname + "GatewayConfig.xml", "resources/server/localGatewayConfig.xml" }); String[] nodeConfigs = (prefix != null) ? (new String[] { "resources/server/" + prefix + "NodeConfig.xml", (String) ac.getProperty(ApplicationContext.IMAGESERVER_CLIENT_NODE), "resources/server/" + hostname + "NodeConfig.xml", "resources/server/localNodeConfig.xml" }) : (new String[] { (String) ac.getProperty(ApplicationContext.IMAGESERVER_CLIENT_NODE), "resources/server/" + hostname + "NodeConfig.xml", "resources/server/localNodeConfig.xml" }); for (int loop = 0; loop < gatewayConfigs.length; loop++) { String s = gatewayConfigs[loop]; if ((s != null) && (s.length() != 0) && (!"null".equals(s))) { File f = new File(s); if (f.exists()) { ac.setProperty(ApplicationContext.IMAGESERVER_GATEWAY_CONFIG, s); break; } } } LOG.info("Using gateway config: " + ac.getProperty(ApplicationContext.IMAGESERVER_GATEWAY_CONFIG)); for (int loop = 0; loop < nodeConfigs.length; loop++) { String s = nodeConfigs[loop]; if ((s != null) && (s.length() != 0) && (!"null".equals(s))) { File f = new File(s); if (f.exists()) { ac.setProperty(ApplicationContext.IMAGESERVER_CLIENT_NODE, s); break; } } } LOG.info("Using client config: " + ac.getProperty(ApplicationContext.IMAGESERVER_CLIENT_NODE)); // Load the layouts and set the default window/level manager... LayoutFactory.initialize(); DefaultWindowLevelManager dwlm = new DefaultWindowLevelManager(); // Create the main JFrame, set its behavior, and let the // ApplicationPanel know the glassPane and layeredPane. Set the // menubar based on reading in the configuration menus. mainFrame = new JFrame("imageviewer"); try { ArrayList<Image> iconList = new ArrayList<Image>(); iconList.add(ImageIO.read(new File("resources/icons/mii.png"))); iconList.add(ImageIO.read(new File("resources/icons/mii32.png"))); mainFrame.setIconImages(iconList); } catch (Exception exc) { } mainFrame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); mainFrame.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent we) { int confirm = ApplicationPanel.getInstance().showDialog( "Are you sure you want to quit imageViewer?", null, JOptionPane.QUESTION_MESSAGE, JOptionPane.OK_CANCEL_OPTION, UIManager.getIcon("Dialog.shutdownIcon")); if (confirm == JOptionPane.OK_OPTION) { boolean hasUnsaved = SaveStack.getInstance().hasUnsavedItems(); if (hasUnsaved) { int saveResult = ApplicationPanel.getInstance().showDialog( "There is still unsaved data. Do you want to save this data in the local archive?", null, JOptionPane.QUESTION_MESSAGE, JOptionPane.YES_NO_CANCEL_OPTION); if (saveResult == JOptionPane.CANCEL_OPTION) return; if (saveResult == JOptionPane.YES_OPTION) SaveStack.getInstance().saveAll(); } LOG.info("Shutting down imageServer local archive..."); try { ImageViewerClientNode.getInstance().shutdown(); } catch (Exception exc) { LOG.error("Problem shutting down imageServer local archive..."); } finally { System.exit(0); } } } }); String menuFile = (String) ApplicationContext.getContext().getProperty(ac.CONFIG_MENUS); String ribbonFile = (String) ApplicationContext.getContext().getProperty(ac.CONFIG_RIBBON); if (menuFile != null) { JMenuBar mb = new JMenuBar(); mb.setBackground(Color.black); MenuReader.parseFile(menuFile, mb); mainFrame.setJMenuBar(mb); ApplicationContext.getContext().setApplicationMenuBar(mb); } else if (ribbonFile != null) { RibbonReader rr = new RibbonReader(); JRibbon jr = rr.parseFile(ribbonFile); mainFrame.getContentPane().add(jr, BorderLayout.NORTH); ApplicationContext.getContext().setApplicationRibbon(jr); } mainFrame.getContentPane().add(ApplicationPanel.getInstance(), BorderLayout.CENTER); ApplicationPanel.getInstance().setGlassPane((JPanel) (mainFrame.getGlassPane())); ApplicationPanel.getInstance().setLayeredPane(mainFrame.getLayeredPane()); // Load specified plugins...has to occur after the menus are // created, btw. PluginLoader.initialize("config/plugins.xml"); // Detect operating system... String osName = System.getProperty("os.name"); ApplicationContext.getContext().setProperty(ApplicationContext.OS_NAME, osName); LOG.info("Detected operating system: " + osName); // Try and hack the searched library paths if it's windows so we // can add a local dll path... try { if (osName.contains("Windows")) { Field f = ClassLoader.class.getDeclaredField("usr_paths"); f.setAccessible(true); String[] paths = (String[]) f.get(null); String[] tmp = new String[paths.length + 1]; System.arraycopy(paths, 0, tmp, 0, paths.length); File currentPath = new File("."); tmp[paths.length] = currentPath.getCanonicalPath() + "/lib/dll/"; f.set(null, tmp); f.setAccessible(false); } } catch (Exception exc) { LOG.error("Error attempting to dynamically set library paths."); } // Get screen resolution... GraphicsConfiguration gc = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice() .getDefaultConfiguration(); Rectangle r = gc.getBounds(); LOG.info("Detected screen resolution: " + (int) r.getWidth() + "x" + (int) r.getHeight()); // Try and see if Java3D is installed, and if so, what version... try { VirtualUniverse vu = new VirtualUniverse(); Map m = vu.getProperties(); String s = (String) m.get("j3d.version"); LOG.info("Detected Java3D version: " + s); } catch (Throwable t) { LOG.info("Unable to detect Java3D installation"); } // Try and see if native JOGL is installed... try { System.loadLibrary("jogl"); ac.setProperty(ApplicationContext.JOGL_DETECTED, Boolean.TRUE); LOG.info("Detected native libraries for JOGL"); } catch (Throwable t) { LOG.info("Unable to detect native JOGL installation"); ac.setProperty(ApplicationContext.JOGL_DETECTED, Boolean.FALSE); } // Start the local client node to connect to the network and the // local archive running on this machine...Thread the connection // process so it doesn't block the imageViewerClient creating this // instance. We may not be connected to the given gateway, so the // socketServer may go blah... final boolean useNetwork = (args.hasOption("nonet")) ? false : true; ApplicationPanel.getInstance().addStatusMessage("ImageViewer is starting up, please wait..."); if (useNetwork) LOG.info("Starting imageServer client to join network - please wait..."); Thread t = new Thread(new Runnable() { public void run() { try { ImageViewerClientNode.getInstance( (String) ApplicationContext.getContext() .getProperty(ApplicationContext.IMAGESERVER_GATEWAY_CONFIG), (String) ApplicationContext.getContext() .getProperty(ApplicationContext.IMAGESERVER_CLIENT_NODE), useNetwork); ApplicationPanel.getInstance().addStatusMessage("Ready"); } catch (Exception exc) { exc.printStackTrace(); } } }); t.setPriority(9); t.start(); this.fullScreen = fullScreen; mainFrame.setUndecorated(fullScreen); // Set the view to encompass the default screen. if (fullScreen) { Insets i = Toolkit.getDefaultToolkit().getScreenInsets(gc); mainFrame.setLocation(r.x + i.left, r.y + i.top); mainFrame.setSize(r.width - i.left - i.right, r.height - i.top - i.bottom); } else { mainFrame.setSize(1100, 800); mainFrame.setLocation(r.x + 200, r.y + 100); } if (dir != null) ApplicationPanel.getInstance().load(dir, type); timer = new Timer(); timer.schedule(new GarbageCollectionTimer(), 5000, 2500); mainFrame.setVisible(true); }
From source file:com.skp.experiment.cf.als.hadoop.SolveImplicitFeedbackMultithreadedMapper.java
/** create file lock per each datanode to prevent too many map task simultaneously * runs on same datanode *//*from w ww.j a v a 2s . c o m*/ private void checkLock(Context ctx, int lockNums) throws InterruptedException, IOException { InetAddress thisIp = InetAddress.getLocalHost(); String hostIp = thisIp.getHostAddress(); // busy wait Configuration conf = ctx.getConfiguration(); long totalSleep = 0; boolean haveLock = false; FileSystem fs = FileSystem.get(conf); while (haveLock == false) { for (int i = 0; i < lockNums; i++) { Path checkPath = new Path(lockPath, hostIp + "_" + i); if (fs.exists(checkPath) == false) { haveLock = true; currentLockPath = checkPath; BufferedWriter br = new BufferedWriter(new OutputStreamWriter(fs.create(currentLockPath))); br.write(ctx.getTaskAttemptID().toString()); break; } } if (haveLock == false) { Random random = new Random(); int diff = 1000 + random.nextInt(1000) % 1000; totalSleep += diff + sleepPeriod; ctx.setStatus("sleeping: " + String.valueOf(totalSleep)); Thread.sleep(sleepPeriod + diff); } } }
From source file:de.martido.log4jes.LogstashLayoutV1.java
private static String getHostName() { try {// w w w.ja v a2s . co m return InetAddress.getLocalHost().getHostName(); } catch (UnknownHostException e) { return "unknown"; } }
From source file:com.qubole.rubix.bookkeeper.BookKeeper.java
private void initializeClusterManager(int clusterType) { if (clusterManager == null || currentNodeIndex == -1) { synchronized (lock) { if (clusterManager == null || currentNodeIndex == -1) { try { nodeName = InetAddress.getLocalHost().getCanonicalHostName(); } catch (UnknownHostException e) { e.printStackTrace(); log.warn("Could not get nodeName", e); }// w ww . ja v a2 s .c o m if (clusterType == HADOOP2_CLUSTER_MANAGER.ordinal()) { clusterManager = new Hadoop2ClusterManager(); clusterManager.initialize(conf); nodes = clusterManager.getNodes(); splitSize = clusterManager.getSplitSize(); } else if (clusterType == TEST_CLUSTER_MANAGER.ordinal()) { nodes = new ArrayList<>(); nodes.add(nodeName); splitSize = 64 * 1024 * 1024; } nodeListSize = nodes.size(); currentNodeIndex = nodes.indexOf(nodeName); } else { nodes = clusterManager.getNodes(); } } } else { nodes = clusterManager.getNodes(); } }