/** * @param hostAndPort Formatted as <code><hostname> ':' <port></code> * @return An InetSocketInstance */ public static InetSocketAddress createInetSocketAddressFromHostAndPortStr( final String hostAndPort) { return new InetSocketAddress(parseHostname(hostAndPort), parsePort(hostAndPort)); }
/** * @return String made of hostname and port formatted as * per {@link Addressing#createHostAndPortStr(String, int)} */ public String getHostnamePort() { return Addressing.createHostAndPortStr(this.getHostname(), this.getPort()); }
public static InetAddress getIpAddress() throws SocketException { return getIpAddress(new AddressSelectionCondition() { @Override public boolean isAcceptableAddress(InetAddress addr) { return addr instanceof Inet4Address || addr instanceof Inet6Address; } }); }
InetAddress localAddress; if (ina instanceof Inet6Address) { localAddress = Addressing.getIp6Address(); family = InternetProtocolFamily.IPv6; } else { localAddress = Addressing.getIp4Address(); family = InternetProtocolFamily.IPv4;
public MemcachedBlockCache(Configuration c) throws IOException { LOG.info("Creating MemcachedBlockCache"); long opTimeout = c.getLong(MEMCACHED_OPTIMEOUT_KEY, MEMCACHED_DEFAULT_TIMEOUT); long queueTimeout = c.getLong(MEMCACHED_TIMEOUT_KEY, opTimeout + MEMCACHED_DEFAULT_TIMEOUT); boolean optimize = c.getBoolean(MEMCACHED_OPTIMIZE_KEY, MEMCACHED_OPTIMIZE_DEFAULT); ConnectionFactoryBuilder builder = new ConnectionFactoryBuilder() .setOpTimeout(opTimeout) .setOpQueueMaxBlockTime(queueTimeout) // Cap the max time before anything times out .setFailureMode(FailureMode.Redistribute) .setShouldOptimize(optimize) .setDaemon(true) // Don't keep threads around past the end of days. .setUseNagleAlgorithm(false) // Ain't nobody got time for that .setReadBufferSize(HConstants.DEFAULT_BLOCKSIZE * 4 * 1024); // Much larger just in case // Assume only the localhost is serving memecached. // A la mcrouter or co-locating memcached with split regionservers. // // If this config is a pool of memecached servers they will all be used according to the // default hashing scheme defined by the memcache client. Spy Memecache client in this // case. String serverListString = c.get(MEMCACHED_CONFIG_KEY,"localhost:11211"); String[] servers = serverListString.split(","); List<InetSocketAddress> serverAddresses = new ArrayList<>(servers.length); for (String s:servers) { serverAddresses.add(Addressing.createInetSocketAddressFromHostAndPortStr(s)); } client = new MemcachedClient(builder.build(), serverAddresses); }
public HServerAddress getAddress(int i) { return new HServerAddress(Addressing.createInetSocketAddressFromHostAndPortStr(getHostnamePort(i))); }
InetAddress localAddress; if (ina instanceof Inet6Address) { localAddress = Addressing.getIp6Address(); family = InternetProtocolFamily.IPv6; }else{ localAddress = Addressing.getIp4Address(); family = InternetProtocolFamily.IPv4;
public static StartcodeAgnosticServerName valueOf(final String hostnameAndPort, long startcode) { return new StartcodeAgnosticServerName(Addressing.parseHostname(hostnameAndPort), Addressing.parsePort(hostnameAndPort), startcode); }
/** * @return Return a SHORT version of {@link ServerName#toString()}, one that has the host only, * minus the domain, and the port only -- no start code; the String is for us internally mostly * tying threads to their server. Not for external use. It is lossy and will not work in * in compares, etc. */ public String toShortString() { return Addressing.createHostAndPortStr( getHostNameMinusDomain(this.address.getHostname()), this.address.getPort()); }
public static InetAddress getIp4Address() throws SocketException { return getIpAddress(new AddressSelectionCondition() { @Override public boolean isAcceptableAddress(InetAddress addr) { return addr instanceof Inet4Address; } }); }
/** * Gets all the regions and their address for this table. * @return A map of HRegionInfo with it's server address * @throws IOException if a remote or network exception occurs * @deprecated Use {@link #getRegionLocations()} or {@link #getStartEndKeys()} */ public Map<HRegionInfo, HServerAddress> getRegionsInfo() throws IOException { final Map<HRegionInfo, HServerAddress> regionMap = new TreeMap<HRegionInfo, HServerAddress>(); final Map<HRegionInfo, ServerName> regionLocations = getRegionLocations(); for (Map.Entry<HRegionInfo, ServerName> entry : regionLocations.entrySet()) { HServerAddress server = new HServerAddress(); ServerName serverName = entry.getValue(); if (serverName != null && serverName.getHostAndPort() != null) { server = new HServerAddress(Addressing.createInetSocketAddressFromHostAndPortStr( serverName.getHostAndPort())); } regionMap.put(entry.getKey(), server); } return regionMap; }
@Override public synchronized void stopRegionServer(final String hostnamePort) throws IOException { String hostname = Addressing.parseHostname(hostnamePort); int port = Addressing.parsePort(hostnamePort); final AdminService.BlockingInterface admin = this.connection.getAdmin(ServerName.valueOf(hostname, port, 0)); // TODO: There is no timeout on this controller. Set one! HBaseRpcController controller = rpcControllerFactory.newController(); controller.setPriority(HConstants.HIGH_QOS); StopServerRequest request = RequestConverter.buildStopServerRequest( "Called by admin client " + this.connection.toString()); try { admin.stopServer(controller, request); } catch (Exception e) { throw ProtobufUtil.handleRemoteException(e); } }
/** * @return String made of hostname and port formatted as * per {@link Addressing#createHostAndPortStr(String, int)} */ public String getHostnamePort() { return Addressing.createHostAndPortStr(this.getHostname(), this.getPort()); }
public static InetAddress getIp6Address() throws SocketException { return getIpAddress(new AddressSelectionCondition() { @Override public boolean isAcceptableAddress(InetAddress addr) { return addr instanceof Inet6Address; } }); }
public MemcachedBlockCache(Configuration c) throws IOException { LOG.info("Creating MemcachedBlockCache"); long opTimeout = c.getLong(MEMCACHED_OPTIMEOUT_KEY, MEMCACHED_DEFAULT_TIMEOUT); long queueTimeout = c.getLong(MEMCACHED_TIMEOUT_KEY, opTimeout + MEMCACHED_DEFAULT_TIMEOUT); boolean optimize = c.getBoolean(MEMCACHED_OPTIMIZE_KEY, MEMCACHED_OPTIMIZE_DEFAULT); ConnectionFactoryBuilder builder = new ConnectionFactoryBuilder() .setOpTimeout(opTimeout) .setOpQueueMaxBlockTime(queueTimeout) // Cap the max time before anything times out .setFailureMode(FailureMode.Redistribute) .setShouldOptimize(optimize) .setDaemon(true) // Don't keep threads around past the end of days. .setUseNagleAlgorithm(false) // Ain't nobody got time for that .setReadBufferSize(HConstants.DEFAULT_BLOCKSIZE * 4 * 1024); // Much larger just in case // Assume only the localhost is serving memecached. // A la mcrouter or co-locating memcached with split regionservers. // // If this config is a pool of memecached servers they will all be used according to the // default hashing scheme defined by the memcache client. Spy Memecache client in this // case. String serverListString = c.get(MEMCACHED_CONFIG_KEY,"localhost:11211"); String[] servers = serverListString.split(","); List<InetSocketAddress> serverAddresses = new ArrayList<>(servers.length); for (String s:servers) { serverAddresses.add(Addressing.createInetSocketAddressFromHostAndPortStr(s)); } client = new MemcachedClient(builder.build(), serverAddresses); }
String hostname = Addressing.parseHostname(str); int port = Addressing.parsePort(str); return ServerName.valueOf(hostname, port, -1L);
/** * @return Hostname and port formatted as described at * {@link Addressing#createHostAndPortStr(String, int)} */ public String getHostAndPort() { return Addressing.createHostAndPortStr(this.hostname, this.port); }
/** * @return Some IPv4/IPv6 address available on the current machine that is up, not virtual * and not a loopback address. Empty array if none can be found or error occurred. */ public static byte[] getIpAddressBytes() { try { return Addressing.getIpAddress().getAddress(); } catch (IOException ex) { LOG.warn("Failed to get IP address bytes", ex); } return new byte[0]; } }
String hostname = Addressing.parseHostname(str); int port = Addressing.parsePort(str); return ServerName.valueOf(hostname, port, -1L);
/** * @return String made of hostname and port formatted as per * {@link org.apache.hadoop.hbase.util.Addressing#createHostAndPortStr(String, int)} */ public synchronized String getHostnamePort() { if (this.cachedHostnamePort == null) { this.cachedHostnamePort = Addressing.createHostAndPortStr(this.hostname, this.port); } return this.cachedHostnamePort; }