List of usage examples for java.net InetAddress getLocalHost
public static InetAddress getLocalHost() throws UnknownHostException
From source file:net.sf.zekr.engine.server.DefaultHttpServer.java
private String getServerName() throws HttpServerRuntimeException { try {/*from ww w. jav a 2s . c om*/ return InetAddress.getLocalHost().getCanonicalHostName(); } catch (UnknownHostException e) { throw new HttpServerRuntimeException(e); } }
From source file:de.undercouch.gradle.tasks.download.TestBase.java
/** * Gets the local host name to use for the tests * @throws UnknownHostException if the local host name could not be * resolved into an address// w w w . j av a2 s. co m * @throws SocketException if an I/O error occurs */ @BeforeClass public static void setUpClass() throws UnknownHostException, SocketException { try { InetAddress.getByName("localhost.localdomain"); localHostName = "localhost.localdomain"; } catch (UnknownHostException e) { localHostName = findSiteLocal(); if (localHostName == null) { localHostName = InetAddress.getLocalHost().getCanonicalHostName(); } } }
From source file:com.tc.config.schema.setup.BaseConfigurationSetupManagerTest.java
public void testServerDefaults1() throws IOException, ConfigurationSetupException { this.tcConfig = getTempFile("default-config.xml"); String config = "<tc-config xmlns=\"http://www.terracotta.org/config\">" + "<servers>" + "<server>" + "</server>" + "</servers>" + "</tc-config>"; writeConfigFile(config);// ww w . j av a2 s . c o m BaseConfigurationSetupManager configSetupMgr = initializeAndGetBaseTVSConfigSetupManager(false); Servers servers = configSetupMgr.serversBeanRepository(); Server server = servers.getServer().get(0); Assert.assertEquals(InetAddress.getLocalHost().getHostAddress(), server.getHost()); Assert.assertEquals("0.0.0.0", server.getBind()); Assert.assertEquals(InetAddress.getLocalHost().getHostAddress() + ":" + server.getTsaPort().getValue(), server.getName()); Assert.assertEquals(9510, server.getTsaPort().getValue()); Assert.assertEquals(server.getBind(), server.getTsaPort().getBind()); int tempGroupPort = 9510 + L2ConfigObject.DEFAULT_GROUPPORT_OFFSET_FROM_TSAPORT; int defaultGroupPort = ((tempGroupPort <= L2ConfigObject.MAX_PORTNUMBER) ? (tempGroupPort) : (tempGroupPort % L2ConfigObject.MAX_PORTNUMBER) + L2ConfigObject.MIN_PORTNUMBER); Assert.assertEquals(defaultGroupPort, server.getTsaGroupPort().getValue()); Assert.assertEquals(server.getBind(), server.getTsaGroupPort().getBind()); }
From source file:com.twitter.common.net.InetSocketAddressHelper.java
public static InetSocketAddress getLocalAddress(int port) throws UnknownHostException { String ipAddress = InetAddress.getLocalHost().getHostAddress(); return new InetSocketAddress(ipAddress, port); }
From source file:com.netflix.genie.web.configs.GenieApiAutoConfiguration.java
/** * Get the {@link GenieHostInfo} for this application. This is the default fallback implementation if no other bean * instance of this type has been created. * * @return The hostname calculated from {@link InetAddress} * @throws UnknownHostException When the host can't be calculated * @throws IllegalStateException When an instance can't be created * @see InetAddress#getCanonicalHostName() *//*w w w .jav a2 s.co m*/ @Bean @ConditionalOnMissingBean(GenieHostInfo.class) public GenieHostInfo genieHostInfo() throws UnknownHostException { final String hostname = InetAddress.getLocalHost().getCanonicalHostName(); if (StringUtils.isNotBlank(hostname)) { return new GenieHostInfo(hostname); } else { throw new IllegalStateException("Unable to create a Genie Host Info instance"); } }
From source file:net.dfs.remote.filestorage.impl.FileReceiverSupportImpl.java
/** * retrieveFile will create an instance of {@link FileStorageModel} and takes * the matching File objects from the Space. It makes sure that the Space is not * null before taking the File objects.//from w w w.ja v a 2s . c o m * <p> * The received File object will be then sent to the {@link StorageManager} for ensure * the persistent storage. It accepts no values and returns no value. */ public void retrieveFile() { FileToken tempToken = new FileToken(); if (space == null) { try { log.debug("Space Requested from " + serverIP); space = spaceCreator.getSpace(InetAddress.getByName(serverIP), InetAddress.getLocalHost()); log.debug("Space Returned to " + serverIP); } catch (UnknownHostException e) { log.error("e"); } } for (;;) { try { FileToken received = (FileToken) space.take(tempToken, null, Long.MAX_VALUE); log.info("Chunk " + received.fileName + " with Chunk No " + received.CHUNK_NO + " Taken from the Space"); FileStorageModel fileStorageModel = tokenFileManager.receiveChunk(received.fileName, received.ext, received.CHUNK_NO); log.info("ACTUAL File " + fileStorageModel.fileName + " with bytes " + fileStorageModel.bytesRead + " Received from the Server"); storageManager.fileStorage(fileStorageModel); hashMap.createHashIndex(fileStorageModel.fileName, InetAddress.getLocalHost().getHostAddress()); } catch (RemoteException e) { log.error("e"); } catch (UnusableEntryException e) { log.error("e"); } catch (TransactionException e) { log.error("e"); } catch (InterruptedException e) { log.error("e"); } catch (IOException e) { log.error("e"); } } }
From source file:com.spotify.ffwd.AgentConfig.java
private Supplier<String> hostProvider() { return new Supplier<String>() { @Override/*from ww w. j a va 2 s . c o m*/ public String get() { try { return InetAddress.getLocalHost().getHostName(); } catch (UnknownHostException e) { throw new RuntimeException("unable to get local host", e); } } }; }
From source file:com.yahoo.ads.pb.network.netty.NettyPistachioClient.java
public NettyPistachioClient() throws Exception { if (helixPartitionSpectator == null) { synchronized (this) { if (helixPartitionSpectator == null) { try { helixPartitionSpectator = new HelixPartitionSpectator(conf.getString(ZOOKEEPER_SERVER), // zkAddr "PistachiosCluster", InetAddress.getLocalHost().getHostName() //conf.getString(PROFILE_HELIX_INSTANCE_ID) // instanceName );// w ww. j a v a2 s .c o m localHostAddress = InetAddress.getLocalHost().getHostAddress(); } catch (Exception e) { logger.error( "Error init HelixPartitionSpectator, are zookeeper and helix installed and configured correctly?", e); throw e; } } } } }
From source file:com.ibm.connectors.splunklog.SplunkConnectionData.java
private String getLocalhost() { String hostname = ""; try {/*w ww. ja va 2 s . com*/ hostname = InetAddress.getLocalHost().getHostName(); } catch (UnknownHostException e) { return hostname; } return hostname; }