List of usage examples for java.net InetAddress equals
public boolean equals(Object obj)
From source file:Main.java
public static void main(String[] argv) throws Exception { byte[] ipAddr = new byte[] { 127, 0, 0, 1 }; InetAddress addr = InetAddress.getByAddress("Localhost", ipAddr); System.out.println(addr.equals(InetAddress.getByAddress(ipAddr))); }
From source file:MainClass.java
public static void main(String args[]) throws Exception { InetAddress ca = InetAddress.getByName("www.google.ca"); InetAddress com = InetAddress.getByName("www.google.com"); if (ca.equals(com)) { System.out.println("same"); } else {/* w w w . j a v a2 s . c om*/ System.out.println("not the same"); } }
From source file:Main.java
public static void checkIfValidAddress(InetAddress bind_addr, String prot_name) throws Exception { //if(bind_addr.isAnyLocalAddress() || bind_addr.isLoopbackAddress()) // return;/*from w w w .j ava2s . c o m*/ Collection<InetAddress> addrs = getAllAvailableAddresses(); for (InetAddress addr : addrs) { if (addr.equals(bind_addr)) return; } throw new BindException( "[" + prot_name + "] " + bind_addr + " is not a valid address on any local network interface"); }
From source file:Main.java
/** * Method to check if internet is available. * * @return Returns true if the internet is available *//*from ww w . j a v a 2 s. co m*/ public static boolean isInternetAvailable() { try { InetAddress address = InetAddress.getByName("google.com"); return !address.equals(""); } catch (Exception e) { return false; } }
From source file:com.cloudera.sqoop.util.DirectImportUtils.java
/** @return true if someHost refers to localhost. *//*from www. jav a 2 s . c o m*/ public static boolean isLocalhost(String someHost) { if (null == someHost) { return false; } try { InetAddress localHostAddr = InetAddress.getLocalHost(); InetAddress someAddr = InetAddress.getByName(someHost); return localHostAddr.equals(someAddr); } catch (UnknownHostException uhe) { return false; } }
From source file:com.bigdata.dastor.dht.BootStrapper.java
static InetAddress getBootstrapSource(final TokenMetadata metadata, final Map<InetAddress, Double> load) { // sort first by number of nodes already bootstrapping into a source node's range, then by load. List<InetAddress> endpoints = new ArrayList<InetAddress>(load.size()); for (InetAddress endpoint : load.keySet()) { if (!metadata.isMember(endpoint)) continue; endpoints.add(endpoint);/*from w ww . j av a2 s.c o m*/ } if (endpoints.isEmpty()) throw new RuntimeException("No other nodes seen! Unable to bootstrap"); Collections.sort(endpoints, new Comparator<InetAddress>() { public int compare(InetAddress ia1, InetAddress ia2) { int n1 = metadata.pendingRangeChanges(ia1); int n2 = metadata.pendingRangeChanges(ia2); if (n1 != n2) return -(n1 - n2); // more targets = _less_ priority! double load1 = load.get(ia1); double load2 = load.get(ia2); if (load1 == load2) return 0; return load1 < load2 ? -1 : 1; } }); InetAddress maxEndpoint = endpoints.get(endpoints.size() - 1); assert !maxEndpoint.equals(FBUtilities.getLocalAddress()); return maxEndpoint; }
From source file:edu.cornell.med.icb.ip.IpUtils.java
/** * See if the supplied IpAddress List contains the specified InetAddress address. * @param list the IpAddress List//from ww w .j ava 2 s . com * @param address the ip address to find * @return true if the ip address is in the list */ public static boolean ipListContains(final List<IpAddress> list, final InetAddress address) { if (list == null || address == null) { return false; } for (final IpAddress listAddr : list) { if (address.equals(listAddr.getIpAddress())) { return true; } } return false; }
From source file:org.apache.cassandra.dht.BootStrapper.java
static InetAddress getBootstrapSource(final TokenMetadata metadata, final Map<InetAddress, Double> load) { // sort first by number of nodes already bootstrapping into a source node's range, then by load. List<InetAddress> endpoints = new ArrayList<InetAddress>(load.size()); for (InetAddress endpoint : load.keySet()) { if (!metadata.isMember(endpoint)) continue; endpoints.add(endpoint);/* w w w . j a v a 2 s .c o m*/ } if (endpoints.isEmpty()) throw new RuntimeException("No other nodes seen! Unable to bootstrap"); Collections.sort(endpoints, new Comparator<InetAddress>() { public int compare(InetAddress ia1, InetAddress ia2) { int n1 = metadata.pendingRangeChanges(ia1); int n2 = metadata.pendingRangeChanges(ia2); if (n1 != n2) return -(n1 - n2); // more targets = _less_ priority! double load1 = load.get(ia1); double load2 = load.get(ia2); if (load1 == load2) return 0; return load1 < load2 ? -1 : 1; } }); InetAddress maxEndpoint = endpoints.get(endpoints.size() - 1); assert !maxEndpoint.equals(FBUtilities.getLocalAddress()); if (metadata.pendingRangeChanges(maxEndpoint) > 0) throw new RuntimeException( "Every node is a bootstrap source! Please specify an initial token manually or wait for an existing bootstrap operation to finish."); return maxEndpoint; }
From source file:org.lealone.cluster.dht.RangeStreamer.java
/** * @param rangesWithSources The ranges we want to fetch (key) and their potential sources (value) * @param sourceFilters A (possibly empty) collection of source filters to apply. * In addition to any filters given here, we always exclude ourselves. * @param dbName database name//from w ww .j a v a 2 s .c o m * @return Map of source endpoint to collection of ranges */ private static Multimap<InetAddress, Range<Token>> getRangeFetchMap( Multimap<Range<Token>, InetAddress> rangesWithSources, Collection<ISourceFilter> sourceFilters, String dbName) { Multimap<InetAddress, Range<Token>> rangeFetchMapMap = HashMultimap.create(); for (Range<Token> range : rangesWithSources.keySet()) { boolean foundSource = false; outer: for (InetAddress address : rangesWithSources.get(range)) { if (address.equals(Utils.getBroadcastAddress())) { // If localhost is a source, we have found one, but we don't add it to the map to avoid streaming // locally foundSource = true; continue; } for (ISourceFilter filter : sourceFilters) { if (!filter.shouldInclude(address)) continue outer; } rangeFetchMapMap.put(address, range); foundSource = true; break; // ensure we only stream from one other node for each range } if (!foundSource) throw new IllegalStateException("unable to find sufficient sources for streaming range " + range + " in database " + dbName); } return rangeFetchMapMap; }
From source file:org.apache.cassandra.dht.RangeStreamer.java
/** * @param rangesWithSources The ranges we want to fetch (key) and their potential sources (value) * @param sourceFilters A (possibly empty) collection of source filters to apply. In addition to any filters given * here, we always exclude ourselves. * @param keyspace keyspace name/*from w ww .j a v a 2 s . c o m*/ * @return Map of source endpoint to collection of ranges */ private static Multimap<InetAddress, Range<Token>> getRangeFetchMap( Multimap<Range<Token>, InetAddress> rangesWithSources, Collection<ISourceFilter> sourceFilters, String keyspace) { Multimap<InetAddress, Range<Token>> rangeFetchMapMap = HashMultimap.create(); for (Range<Token> range : rangesWithSources.keySet()) { boolean foundSource = false; outer: for (InetAddress address : rangesWithSources.get(range)) { if (address.equals(FBUtilities.getBroadcastAddress())) { // If localhost is a source, we have found one, but we don't add it to the map to avoid streaming locally foundSource = true; continue; } for (ISourceFilter filter : sourceFilters) { if (!filter.shouldInclude(address)) continue outer; } rangeFetchMapMap.put(address, range); foundSource = true; break; // ensure we only stream from one other node for each range } if (!foundSource) throw new IllegalStateException("unable to find sufficient sources for streaming range " + range + " in keyspace " + keyspace); } return rangeFetchMapMap; }