List of usage examples for java.net InetAddress equals
public boolean equals(Object obj)
From source file:org.apache.cassandra.gms.FailureDetector.java
public boolean isAlive(InetAddress ep) { if (ep.equals(FBUtilities.getLocalAddress())) return true; EndpointState epState = Gossiper.instance.getEndpointStateForEndpoint(ep); // we could assert not-null, but having isAlive fail screws a node over so badly that // it's worth being defensive here so minor bugs don't cause disproportionate // badness. (See CASSANDRA-1463 for an example). if (epState == null) logger_.error("unknown endpoint " + ep); return epState != null && epState.isAlive(); }
From source file:com.bigdata.dastor.gms.FailureDetector.java
public boolean isAlive(InetAddress ep) { if (ep.equals(FBUtilities.getLocalAddress())) return true; EndPointState epState = Gossiper.instance.getEndPointStateForEndPoint(ep); // we could assert not-null, but having isAlive fail screws a node over so badly that // it's worth being defensive here so minor bugs don't cause disproportionate // badness. (See issue-1463 for an example). if (epState == null) logger_.error("unknown endpoint " + ep); return epState != null && epState.isAlive(); }
From source file:com.myJava.file.driver.remote.ftp.FTPClient.java
public int pasv() throws IOException { int passiveReturnCode = super.pasv(); if (passiveReturnCode == FTPReply.ENTERING_PASSIVE_MODE) { // Parse and display reply host and port in passive mode // It's quite ugly but there is no entry point in apache's ftp library to perform this check. String reply = getReplyStrings()[0]; int i, index, lastIndex; String octet1, octet2;//w ww . ja va2s.co m StringBuffer host; reply = reply.substring(reply.indexOf('(') + 1, reply.indexOf(')')).trim(); host = new StringBuffer(24); lastIndex = 0; index = reply.indexOf(','); host.append(reply.substring(lastIndex, index)); for (i = 0; i < 3; i++) { host.append('.'); lastIndex = index + 1; index = reply.indexOf(',', lastIndex); host.append(reply.substring(lastIndex, index)); } lastIndex = index + 1; index = reply.indexOf(',', lastIndex); octet1 = reply.substring(lastIndex, index); octet2 = reply.substring(index + 1); // index and lastIndex now used as temporaries try { index = Integer.parseInt(octet1); lastIndex = Integer.parseInt(octet2); } catch (NumberFormatException e) { throw new MalformedServerReplyException( "Could not parse passive host information.\nServer Reply: " + reply); } index <<= 8; index |= lastIndex; String passvHost = host.toString(); //int passvPort = index; //Logger.defaultLogger().info("Passive host received from server : " + passvHost + ":" + passvPort); InetAddress refAddress = InetAddress.getByName(passvHost); if (!refAddress.equals(this._socket_.getInetAddress())) { String msg = "Passive address (" + refAddress + ") differs from host address (" + this._socket_.getInetAddress() + "). This is probably because your server is behind a router. Please check your FTP server's configuration. (for instance, use a masquerade address)"; Logger.defaultLogger().warn(msg); if (!ignorePasvErrors) { throw new IOException(msg); } } } return passiveReturnCode; }
From source file:org.apache.cassandra.service.ConsistencyChecker.java
public void run() { ReadCommand readCommandDigestOnly = constructReadMessage(true); try {// w ww. ja va 2 s .c om Message message = readCommandDigestOnly.makeReadMessage(); if (logger_.isDebugEnabled()) logger_.debug("Reading consistency digest for " + readCommand_.key + " from " + message.getMessageId() + "@[" + StringUtils.join(replicas_, ", ") + "]"); MessagingService.instance.addCallback(new DigestResponseHandler(), message.getMessageId()); Util.debug("cc line 78 sendoneway"); for (InetAddress endpoint : replicas_) { if (!endpoint.equals(FBUtilities.getLocalAddress())) MessagingService.instance.sendOneWay(message, endpoint); } } catch (IOException ex) { throw new RuntimeException(ex); } }
From source file:com.bigdata.dastor.service.ConsistencyChecker.java
public void run() { ReadCommand readCommandDigestOnly = constructReadMessage(true); try {/* w ww. j a v a 2 s. c o m*/ Message message = readCommandDigestOnly.makeReadMessage(); if (logger_.isDebugEnabled()) logger_.debug("Reading consistency digest for " + readCommand_.key + " from " + message.getMessageId() + "@[" + StringUtils.join(replicas_, ", ") + "]"); MessagingService.instance.addCallback(new DigestResponseHandler(), message.getMessageId()); for (InetAddress endpoint : replicas_) { if (!endpoint.equals(FBUtilities.getLocalAddress())) MessagingService.instance.sendOneWay(message, endpoint); } } catch (IOException ex) { throw new RuntimeException(ex); } }
From source file:org.apache.cassandra.service.StorageProxy.java
/** * This function executes local and remote reads, and blocks for the results: * * 1. Get the replica locations, sorted by response time according to the snitch * 2. Send a data request to the closest replica, and digest requests to either * a) all the replicas, if read repair is enabled * b) the closest R-1 replicas, where R is the number required to satisfy the ConsistencyLevel * 3. Wait for a response from R replicas * 4. If the digests (if any) match the data return the data * 5. else carry out read repair by getting data from all the nodes. *///from w w w. j a v a 2s . co m private static List<Row> fetchRows(List<ReadCommand> commands, ConsistencyLevel consistency_level) throws IOException, UnavailableException, TimeoutException { List<ReadCallback<Row>> readCallbacks = new ArrayList<ReadCallback<Row>>(); List<Row> rows = new ArrayList<Row>(); // send out read requests for (ReadCommand command : commands) { assert !command.isDigestQuery(); logger.debug("Command/ConsistencyLevel is {}/{}", command, consistency_level); List<InetAddress> endpoints = StorageService.instance.getLiveNaturalEndpoints(command.table, command.key); DatabaseDescriptor.getEndpointSnitch().sortByProximity(FBUtilities.getLocalAddress(), endpoints); RowDigestResolver resolver = new RowDigestResolver(command.table, command.key); ReadCallback<Row> handler = getReadCallback(resolver, command, consistency_level, endpoints); handler.assureSufficientLiveNodes(); assert !handler.endpoints.isEmpty(); // The data-request message is sent to dataPoint, the node that will actually get // the data for us. The other replicas are only sent a digest query. ReadCommand digestCommand = null; if (handler.endpoints.size() > 1) { digestCommand = command.copy(); digestCommand.setDigestQuery(true); } InetAddress dataPoint = handler.endpoints.get(0); if (dataPoint.equals(FBUtilities.getLocalAddress())) { if (logger.isDebugEnabled()) logger.debug("reading data locally"); StageManager.getStage(Stage.READ).execute(new LocalReadRunnable(command, handler)); } else { if (logger.isDebugEnabled()) logger.debug("reading data from " + dataPoint); MessagingService.instance().sendRR(command, dataPoint, handler); } // We lazy-construct the digest Message object since it may not be necessary if we // are doing a local digest read, or no digest reads at all. MessageProducer producer = new CachingMessageProducer(digestCommand); for (InetAddress digestPoint : handler.endpoints.subList(1, handler.endpoints.size())) { if (digestPoint.equals(FBUtilities.getLocalAddress())) { if (logger.isDebugEnabled()) logger.debug("reading digest locally"); StageManager.getStage(Stage.READ).execute(new LocalReadRunnable(digestCommand, handler)); } else { if (logger.isDebugEnabled()) logger.debug("reading digest for from " + digestPoint); MessagingService.instance().sendRR(producer, digestPoint, handler); } } readCallbacks.add(handler); } // read results and make a second pass for any digest mismatches List<RepairCallback<Row>> repairResponseHandlers = null; for (int i = 0; i < commands.size(); i++) { ReadCallback<Row> handler = readCallbacks.get(i); Row row; ReadCommand command = commands.get(i); try { long startTime2 = System.currentTimeMillis(); row = handler.get(); // CL.ONE is special cased here to ignore digests even if some have arrived if (row != null) rows.add(row); if (logger.isDebugEnabled()) logger.debug("Read: " + (System.currentTimeMillis() - startTime2) + " ms."); } catch (TimeoutException ex) { if (logger.isDebugEnabled()) logger.debug("Read timeout: {}", ex.toString()); throw ex; } catch (DigestMismatchException ex) { if (logger.isDebugEnabled()) logger.debug("Digest mismatch: {}", ex.toString()); RowRepairResolver resolver = new RowRepairResolver(command.table, command.key); RepairCallback<Row> repairHandler = new RepairCallback<Row>(resolver, handler.endpoints); for (InetAddress endpoint : handler.endpoints) MessagingService.instance().sendRR(command, endpoint, repairHandler); if (repairResponseHandlers == null) repairResponseHandlers = new ArrayList<RepairCallback<Row>>(); repairResponseHandlers.add(repairHandler); } } // read the results for the digest mismatch retries if (repairResponseHandlers != null) { for (RepairCallback<Row> handler : repairResponseHandlers) { try { Row row = handler.get(); if (row != null) rows.add(row); } catch (DigestMismatchException e) { throw new AssertionError(e); // full data requested from each node here, no digests should be sent } } } return rows; }
From source file:com.predic8.membrane.core.transport.http.Connection.java
public boolean isSame(InetAddress host, int port) { return socket != null && host.equals(socket.getInetAddress()) && port == socket.getPort(); }
From source file:org.egov.android.view.activity.SplashActivity.java
public boolean isInternetAvailable() { try {/*from w w w.j a v a 2s . c om*/ InetAddress ipAddr = InetAddress.getByName("google.com"); if (ipAddr.equals("")) { return false; } else { return true; } } catch (Exception e) { return false; } }
From source file:edu.ucsd.crbs.cws.auth.UserIpAddressValidatorImpl.java
/** * Checks if {@link User} request is originating from valid ip address by * comparing the {@link User#getIpAddress()} against the valid ip addresses * in {@link User#getAllowedIpAddresses()} list. This list can contain * ipv4 and ipv6 addresses with or without CIDR notation. * @param user {@link User} object with {@link User#getIpAddress()} set * @return true if {@link User#getAllowedIpAddresses()} is null or empty or * or if {@link User#getIpAddress()} is in {@link User#getAllowedIpAddresses()} * list. //from www .j ava 2 s . c o m * @throws Exception if <b>user</b> is null or if no ip address is set for <b>user</b> * or if there is an error parsing the ip addresses. * */ @Override public boolean isUserRequestFromValidIpAddress(User user) throws Exception { if (user == null) { throw new IllegalArgumentException("User is null"); } if (user.getIpAddress() == null || user.getIpAddress().trim().isEmpty() == true) { throw new Exception("No ip address found"); } //simple case the list is empty or null so return true if (user.getAllowedIpAddresses() == null || user.getAllowedIpAddresses().isEmpty()) { return true; } InetAddress requestAddress = InetAddresses.forString(user.getIpAddress()); boolean requestAddressIsIpv6 = false; if (requestAddress instanceof Inet6Address) { requestAddressIsIpv6 = true; } for (String validIp : user.getAllowedIpAddresses()) { if (doesAddressContainCidr(validIp) == true) { if (isIpv6Address(validIp)) { //if valid ip is an ipv6 address then dont bother checking the cidr //cause the request is ipv4 if (requestAddressIsIpv6 == false) { continue; } if (isIpv6AddressInCidrAddress(requestAddress, validIp)) { return true; } } else { //if valid ip is an ipv4 address then dont bother checking the cidr //cause the request is ipv6 if (requestAddressIsIpv6 == true) { continue; } if (isIpv4AddressInCidrAddress(requestAddress, validIp)) { return true; } } continue; } InetAddress validAddress = InetAddresses.forString(validIp); if (validAddress.equals(requestAddress)) { return true; } } return false; }
From source file:com.all.peer.commons.services.ForwardingService.java
public void forwardTo(AllMessage<?> message, InetAddress destination) { if (destination.equals(peerSettings.getPublicIp()) || isSandbox()) { log.info("Forwarding " + message.getType() + " message to the same ultrapeer."); messEngine.send(message);//from w ww. jav a 2s .c o m } else { log.info("Forwarding " + message.getType() + " message to ultrapeer[" + destination + "]."); peerNetworkingService.send(peerSettings.getName(), message, destination.getHostAddress(), AllConstants.ULTRAPEER_PORT); } }