List of usage examples for java.net InetSocketAddress getAddress
public final InetAddress getAddress()
From source file:org.apache.bookkeeper.bookie.Bookie.java
/** * Return the configured address of the bookie. *//*from w w w. j ava 2 s. c o m*/ public static BookieSocketAddress getBookieAddress(ServerConfiguration conf) throws UnknownHostException { String iface = conf.getListeningInterface(); if (iface == null) { iface = "default"; } InetSocketAddress inetAddr = new InetSocketAddress(DNS.getDefaultHost(iface), conf.getBookiePort()); String hostAddress = inetAddr.getAddress().getHostAddress(); if (conf.getUseHostNameAsBookieID()) { hostAddress = inetAddr.getAddress().getCanonicalHostName(); } BookieSocketAddress addr = new BookieSocketAddress(hostAddress, conf.getBookiePort()); if (addr.getSocketAddress().getAddress().isLoopbackAddress() && !conf.getAllowLoopback()) { throw new UnknownHostException("Trying to listen on loopback address, " + addr + " but this is forbidden by default " + "(see ServerConfiguration#getAllowLoopback())"); } return addr; }
From source file:com.tesora.dve.mysqlapi.repl.MyReplicationSlaveService.java
@Override public boolean denyServiceStart(ExternalServiceContext ctxt) throws PEException { String serviceAddress = stripPort( GroupManager.getCoordinationServices().getExternalServiceRegisteredAddress(ctxt.getServiceName())); InetSocketAddress isa = GroupManager.getCoordinationServices().getMemberAddress(); InetAddress ia = isa.getAddress(); String ourAddress = null;/* ww w .j a va 2s . c o m*/ if (ia == null) { ourAddress = stripPort(isa.getHostName()); } else { ourAddress = stripPort(ia.getHostAddress()); } if (!StringUtils.equals(serviceAddress, ourAddress)) { // someone else has started replication slave so don't allow start if (logger.isDebugEnabled()) { logger.debug("Service '" + ctxt.getServiceName() + "' is already registered at '" + serviceAddress + "'"); } return true; } return false; }
From source file:org.apache.hadoop.hdfs.qjournal.server.JournalNodeJournalSyncer.java
/** * Fetch manifest from a single given journal node over http. *///from w w w.java2 s . co m private List<EditLogFile> getManifest(InetSocketAddress jn, Journal journal, long minTxId) throws IOException { String m = DFSUtil .getHTMLContentWithTimeout( new URL("http", jn.getAddress().getHostAddress(), jn.getPort(), GetJournalManifestServlet.buildPath(journal.getJournalId(), minTxId, journal.getJournalStorage())), httpConnectReadTimeoutMs, httpConnectReadTimeoutMs); return convertJsonToListManifest(m); }
From source file:org.apache.kudu.mapreduce.KuduTableInputFormat.java
/** * This method might seem alien, but we do this in order to resolve the hostnames the same way * Hadoop does. This ensures we get locality if Kudu is running along MR/YARN. * @param host hostname we got from the master * @param port port we got from the master * @return reverse DNS'd address/*from w w w . jav a 2 s .c o m*/ */ private String reverseDNS(String host, Integer port) { String location = this.reverseDNSCacheMap.get(host); if (location != null) { return location; } // The below InetSocketAddress creation does a name resolution. InetSocketAddress isa = new InetSocketAddress(host, port); if (isa.isUnresolved()) { LOG.warn("Failed address resolve for: " + isa); } InetAddress tabletInetAddress = isa.getAddress(); try { location = domainNamePointerToHostName(DNS.reverseDns(tabletInetAddress, this.nameServer)); this.reverseDNSCacheMap.put(host, location); } catch (NamingException e) { LOG.warn("Cannot resolve the host name for " + tabletInetAddress + " because of " + e); location = host; } return location; }
From source file:ninja.undertow.NinjaUndertowContext.java
@Override public String getRealRemoteAddr() { InetSocketAddress sourceAddress = exchange.getSourceAddress(); if (sourceAddress != null) { InetAddress address = sourceAddress.getAddress(); if (address != null) { return address.getHostAddress(); }//from w w w.ja v a2 s .c o m } return null; }
From source file:org.talend.core.nexus.HttpClientTransport.java
private IProxySelectorProvider addProxy(final DefaultHttpClient httpClient, URI requestURI) { IProxySelectorProvider proxySelectorProvider = null; try {//ww w.j av a 2 s . co m if (Boolean.valueOf( System.getProperty(PROP_PROXY_HTTP_CLIENT_USE_DEFAULT_SETTINGS, Boolean.FALSE.toString()))) { return proxySelectorProvider; } final List<Proxy> proxyList = TalendProxySelector.getInstance().getDefaultProxySelector() .select(requestURI); Proxy usedProxy = null; if (proxyList != null && !proxyList.isEmpty()) { usedProxy = proxyList.get(0); } if (usedProxy != null) { if (Type.DIRECT.equals(usedProxy.type())) { return proxySelectorProvider; } final Proxy finalProxy = usedProxy; InetSocketAddress address = (InetSocketAddress) finalProxy.address(); String proxyServer = address.getHostName(); int proxyPort = address.getPort(); PasswordAuthentication proxyAuthentication = Authenticator.requestPasswordAuthentication( proxyServer, address.getAddress(), proxyPort, "Http Proxy", "Http proxy authentication", null); if (proxyAuthentication != null) { String proxyUser = proxyAuthentication.getUserName(); if (StringUtils.isNotBlank(proxyUser)) { String proxyPassword = ""; char[] passwordChars = proxyAuthentication.getPassword(); if (passwordChars != null) { proxyPassword = new String(passwordChars); } httpClient.getCredentialsProvider().setCredentials(new AuthScope(proxyServer, proxyPort), new UsernamePasswordCredentials(proxyUser, proxyPassword)); } } HttpHost proxyHost = new HttpHost(proxyServer, proxyPort); httpClient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxyHost); proxySelectorProvider = createProxySelectorProvider(); } return proxySelectorProvider; } finally { if (proxySelectorProvider != null) { TalendProxySelector.getInstance().addProxySelectorProvider(proxySelectorProvider); } } }
From source file:org.apache.flink.client.program.Client.java
/** * Creates a new instance of the class that submits the jobs to a job-manager. * at the given address using the default port. * /*from w w w .ja v a 2 s . c o m*/ * @param jobManagerAddress Address and port of the job-manager. */ public Client(InetSocketAddress jobManagerAddress, Configuration config, ClassLoader userCodeClassLoader) { Preconditions.checkNotNull(config, "Configuration is null"); this.configuration = config; configuration.setString(ConfigConstants.JOB_MANAGER_IPC_ADDRESS_KEY, jobManagerAddress.getAddress().getHostAddress()); configuration.setInteger(ConfigConstants.JOB_MANAGER_IPC_PORT_KEY, jobManagerAddress.getPort()); this.userCodeClassLoader = userCodeClassLoader; this.compiler = new PactCompiler(new DataStatistics(), new DefaultCostEstimator()); }
From source file:de.cubeisland.engine.core.webapi.ApiServer.java
public void whitelistAddress(InetSocketAddress address) { this.whitelistAddress(address.getAddress()); }
From source file:de.cubeisland.engine.core.webapi.ApiServer.java
/** * Checks whether an InetSocketAddress is whitelisted * * @param ip the IP/*from w ww . ja va 2s .c o m*/ * @return true if it is */ public boolean isWhitelisted(InetSocketAddress ip) { return this.isWhitelisted(ip.getAddress()); }
From source file:de.cubeisland.engine.core.webapi.ApiServer.java
public void blacklistAddress(InetSocketAddress address) { this.blacklistAddress(address.getAddress()); }