List of usage examples for java.net InetSocketAddress isUnresolved
public final boolean isUnresolved()
From source file:org.apache.tajo.rpc.NettyClientBase.java
public synchronized void connect() throws ConnectException { if (isConnected()) return;/*from ww w . j a va 2s . c o m*/ int retries = 0; InetSocketAddress address = key.addr; if (address.isUnresolved()) { address = resolveAddress(address); } /* do not call await() inside handler */ ChannelFuture f = doConnect(address).awaitUninterruptibly(); if (!f.isSuccess()) { if (maxRetryNum > 0) { doReconnect(address, f, ++retries); } else { throw makeConnectException(address, f); } } }
From source file:org.cloudgraph.hbase.mapreduce.GraphInputFormat.java
@Override public List<InputSplit> getSplits(JobContext context) throws IOException, InterruptedException { if (scans.isEmpty()) { throw new IOException("No scans were provided."); }// ww w .jav a 2 s . c om try { RegionSizeCalculator sizeCalculator = new RegionSizeCalculator(regionLocator, admin); Pair<byte[][], byte[][]> keys = getStartEndKeys(); // if potentially a single split (or table is empty?) if (keys == null || keys.getFirst() == null || keys.getFirst().length == 0) { HRegionLocation regLoc = regionLocator.getRegionLocation(HConstants.EMPTY_BYTE_ARRAY, false); if (null == regLoc) { throw new IOException("Expecting at least one region."); } List<InputSplit> splits = new ArrayList<InputSplit>(1); long regionSize = sizeCalculator.getRegionSize(regLoc.getRegionInfo().getRegionName()); Scan scan = scans.get(0); if (scans.size() > 1) log.warn("single split with multiple scans - ignoring other than first scan"); TableSplit split = new TableSplit(table.getName(), scan, HConstants.EMPTY_BYTE_ARRAY, HConstants.EMPTY_BYTE_ARRAY, regLoc.getHostnamePort().split(Addressing.HOSTNAME_PORT_SEPARATOR)[0], regionSize); splits.add(split); return splits; } List<InputSplit> splits = new ArrayList<InputSplit>(keys.getFirst().length); for (Scan scan : scans) { for (int i = 0; i < keys.getFirst().length; i++) { if (!includeRegionInSplit(keys.getFirst()[i], keys.getSecond()[i])) { continue; } HRegionLocation location = regionLocator.getRegionLocation(keys.getFirst()[i], false); // The below InetSocketAddress creation does a name // resolution. InetSocketAddress isa = new InetSocketAddress(location.getHostname(), location.getPort()); if (isa.isUnresolved()) { log.error("Failed to resolve host: " + isa + " - ignoring entire split for this host!"); continue; } InetAddress regionAddress = isa.getAddress(); String regionLocation; try { regionLocation = reverseDNS(regionAddress); } catch (NamingException e) { log.warn("Cannot resolve the host name for " + regionAddress + " because of " + e); regionLocation = location.getHostname(); } byte[] startRow = scan.getStartRow(); byte[] stopRow = scan.getStopRow(); // determine if the given start an stop key fall into the // region. if ((startRow.length == 0 || keys.getSecond()[i].length == 0 || Bytes.compareTo(startRow, keys.getSecond()[i]) < 0) && (stopRow.length == 0 || Bytes.compareTo(stopRow, keys.getFirst()[i]) > 0)) { byte[] splitStart = startRow.length == 0 || Bytes.compareTo(keys.getFirst()[i], startRow) >= 0 ? keys.getFirst()[i] : startRow; byte[] splitStop = (stopRow.length == 0 || Bytes.compareTo(keys.getSecond()[i], stopRow) <= 0) && keys.getSecond()[i].length > 0 ? keys.getSecond()[i] : stopRow; byte[] regionName = location.getRegionInfo().getRegionName(); long regionSize = sizeCalculator.getRegionSize(regionName); TableSplit split = new TableSplit(table.getName(), scan, // must // include // the scan // as it // may have // various filters splitStart, splitStop, regionLocation, regionSize); splits.add(split); if (log.isDebugEnabled()) { log.debug("getSplits: split -> " + i + " -> " + split); } } } } return splits; } finally { closeAll(); } }
From source file:org.cloudifysource.dsl.utils.IPUtils.java
/** * Validates a connection can be made to the given address and port, within * the given time limit./*from w w w . j a v a 2 s.c o m*/ * * @param ipAddress * The IP address to connect to * @param port * The port number to use * @param timeout * The time to wait before timing out, in seconds * @throws IOException * Reports a failure to connect or resolve the given address. */ public static void validateConnection(final String ipAddress, final int port, final int timeout) throws IOException { final Socket socket = new Socket(); try { final InetSocketAddress endPoint = new InetSocketAddress(ipAddress, port); if (endPoint.isUnresolved()) { throw new UnknownHostException(ipAddress); } socket.connect(endPoint, safeLongToInt(TimeUnit.SECONDS.toMillis(timeout), true)); } finally { try { socket.close(); } catch (final IOException ioe) { // ignore } } }