List of usage examples for java.net InetAddress equals
public boolean equals(Object obj)
From source file:org.lealone.cluster.db.ClusterMetaData.java
public static synchronized void updateTokens(InetAddress ep, Collection<Token> tokens) { if (ep.equals(Utils.getBroadcastAddress())) { removeEndpoint(ep);//from w ww .ja v a2s. c o m return; } String sql = "MERGE INTO %s (peer, tokens) KEY(peer) VALUES('%s', '%s')"; try { sql = String.format(sql, PEERS_TABLE, ep.getHostAddress(), StringUtils.join(tokensAsSet(tokens), ',')); stmt.executeUpdate(sql); } catch (SQLException e) { handleException(e); } }
From source file:co.mike.apptemplate.Utils.ServerUtils.RESTCient.java
public static boolean isInternetAvailable(String domain) { try {/*from w w w . ja v a 2 s .co m*/ InetAddress ipAddr = InetAddress.getByName(domain); //You can replace it with your name if (ipAddr.equals("")) { return false; } else { return true; } } catch (Exception e) { return false; } }
From source file:org.apache.cassandra.service.MigrationManager.java
private static Future<?> announce(final Collection<RowMutation> schema) { Future<?> f = StageManager.getStage(Stage.MIGRATION).submit(new Callable<Object>() { public Object call() throws Exception { DefsTable.mergeSchema(schema); return null; }/*from ww w.j a v a 2 s . c om*/ }); for (InetAddress endpoint : Gossiper.instance.getLiveMembers()) { if (endpoint.equals(FBUtilities.getBroadcastAddress())) continue; // we've delt with localhost already // don't send migrations to the nodes with the versions older than < 1.1 if (Gossiper.instance.getVersion(endpoint) < MessagingService.VERSION_11) continue; pushSchemaMutation(endpoint, schema); } return f; }
From source file:gridool.util.GridUtils.java
public static boolean isSameHost(GridNode lhs, GridNode rhs) { InetAddress laddr = lhs.getPhysicalAdress(); InetAddress raddr = rhs.getPhysicalAdress(); return laddr.equals(raddr); }
From source file:edu.uci.ics.asterix.event.service.AsterixEventServiceUtil.java
public static void evaluateConflictWithOtherInstances(AsterixInstance instance) throws Exception { List<AsterixInstance> existingInstances = ServiceProvider.INSTANCE.getLookupService().getAsterixInstances(); List<String> usedIps = new ArrayList<String>(); String masterIp = instance.getCluster().getMasterNode().getClusterIp(); for (Node node : instance.getCluster().getNode()) { usedIps.add(node.getClusterIp()); }/*www.ja v a 2s .c o m*/ usedIps.add(instance.getCluster().getMasterNode().getClusterIp()); boolean conflictFound = false; AsterixInstance conflictingInstance = null; for (AsterixInstance existing : existingInstances) { if (existing.getState().equals(State.INACTIVE)) { continue; } InetAddress extantAddress = InetAddress.getByName(existing.getCluster().getMasterNode().getClusterIp()); InetAddress masterAddress = InetAddress.getByName(masterIp); if (extantAddress.equals(masterAddress)) { conflictingInstance = existing; break; } for (Node n : existing.getCluster().getNode()) { if (usedIps.contains(n.getClusterIp())) { conflictFound = true; conflictingInstance = existing; break; } } } if (conflictFound) { throw new Exception("Cluster definition conflicts with an existing instance of Asterix: " + conflictingInstance.getName()); } }
From source file:org.apache.cassandra.db.SystemTable.java
/** * Record tokens being used by another node *///from w w w . j ava 2s . com public static synchronized void updateTokens(InetAddress ep, Collection<Token> tokens) { if (ep.equals(FBUtilities.getBroadcastAddress())) { removeEndpoint(ep); return; } String req = "INSERT INTO system.%s (peer, tokens) VALUES ('%s', %s)"; processInternal(String.format(req, PEERS_CF, ep.getHostAddress(), tokensAsSet(tokens))); forceBlockingFlush(PEERS_CF); }
From source file:com.bigdata.dastor.service.StorageProxy.java
private static List<Row> strongRead(List<ReadCommand> commands, ConsistencyLevel consistency_level) throws IOException, UnavailableException, TimeoutException { List<QuorumResponseHandler<Row>> quorumResponseHandlers = new ArrayList<QuorumResponseHandler<Row>>(); List<InetAddress[]> commandEndPoints = new ArrayList<InetAddress[]>(); List<Row> rows = new ArrayList<Row>(); // send out read requests for (ReadCommand command : commands) { assert !command.isDigestQuery(); ReadCommand readMessageDigestOnly = command.copy(); readMessageDigestOnly.setDigestQuery(true); Message message = command.makeReadMessage(); Message messageDigestOnly = readMessageDigestOnly.makeReadMessage(); InetAddress dataPoint = StorageService.instance.findSuitableEndPoint(command.table, command.key); List<InetAddress> endpointList = StorageService.instance.getLiveNaturalEndpoints(command.table, command.key);//from w ww . jav a2 s . c om final String table = command.table; int responseCount = determineBlockFor(DatabaseDescriptor.getReplicationFactor(table), consistency_level); if (endpointList.size() < responseCount) throw new UnavailableException(); InetAddress[] endPoints = new InetAddress[endpointList.size()]; Message messages[] = new Message[endpointList.size()]; // 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. int n = 0; for (InetAddress endpoint : endpointList) { Message m = endpoint.equals(dataPoint) ? message : messageDigestOnly; endPoints[n] = endpoint; messages[n++] = m; if (logger.isDebugEnabled()) logger.debug("strongread reading " + (m == message ? "data" : "digest") + " for " + command + " from " + m.getMessageId() + "@" + endpoint); } QuorumResponseHandler<Row> quorumResponseHandler = new QuorumResponseHandler<Row>(responseCount, new ReadResponseResolver(command.table, responseCount)); MessagingService.instance.sendRR(messages, endPoints, quorumResponseHandler); quorumResponseHandlers.add(quorumResponseHandler); commandEndPoints.add(endPoints); } // read results and make a second pass for any digest mismatches List<QuorumResponseHandler<Row>> repairResponseHandlers = null; for (int i = 0; i < commands.size(); i++) { QuorumResponseHandler<Row> quorumResponseHandler = quorumResponseHandlers.get(i); Row row; ReadCommand command = commands.get(i); try { long startTime2 = System.currentTimeMillis(); row = quorumResponseHandler.get(); if (row != null) rows.add(row); if (logger.isDebugEnabled()) logger.debug("quorumResponseHandler: " + (System.currentTimeMillis() - startTime2) + " ms."); } catch (DigestMismatchException ex) { if (DatabaseDescriptor.getConsistencyCheck()) { if (logger.isDebugEnabled()) logger.debug("Digest mismatch:", ex); int responseCount = determineBlockFor(DatabaseDescriptor.getReplicationFactor(command.table), consistency_level); QuorumResponseHandler<Row> qrhRepair = new QuorumResponseHandler<Row>(responseCount, new ReadResponseResolver(command.table, responseCount)); Message messageRepair = command.makeReadMessage(); MessagingService.instance.sendRR(messageRepair, commandEndPoints.get(i), qrhRepair); if (repairResponseHandlers == null) repairResponseHandlers = new ArrayList<QuorumResponseHandler<Row>>(); repairResponseHandlers.add(qrhRepair); } } } // read the results for the digest mismatch retries if (repairResponseHandlers != null) { for (QuorumResponseHandler<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.bigdata.dastor.service.StorageProxy.java
private static List<Row> weakRead(List<ReadCommand> commands) throws IOException, UnavailableException, TimeoutException { List<Row> rows = new ArrayList<Row>(); // send off all the commands asynchronously List<Future<Object>> localFutures = null; List<IAsyncResult> remoteResults = null; for (ReadCommand command : commands) { InetAddress endPoint = StorageService.instance.findSuitableEndPoint(command.table, command.key); if (endPoint.equals(FBUtilities.getLocalAddress())) { if (logger.isDebugEnabled()) logger.debug("weakread reading " + command + " locally"); if (localFutures == null) localFutures = new ArrayList<Future<Object>>(); Callable<Object> callable = new weakReadLocalCallable(command); localFutures.add(StageManager.getStage(StageManager.READ_STAGE).submit(callable)); } else {/* w w w . j ava2 s .c o m*/ if (remoteResults == null) remoteResults = new ArrayList<IAsyncResult>(); Message message = command.makeReadMessage(); if (logger.isDebugEnabled()) logger.debug( "weakread reading " + command + " from " + message.getMessageId() + "@" + endPoint); if (DatabaseDescriptor.getConsistencyCheck()) message.setHeader(ReadCommand.DO_REPAIR, ReadCommand.DO_REPAIR.getBytes()); remoteResults.add(MessagingService.instance.sendRR(message, endPoint)); } } // wait for results if (localFutures != null) { for (Future<Object> future : localFutures) { Row row; try { row = (Row) future.get(); } catch (Exception e) { throw new RuntimeException(e); } rows.add(row); } } if (remoteResults != null) { for (IAsyncResult iar : remoteResults) { byte[] body; body = iar.get(DatabaseDescriptor.getRpcTimeout(), TimeUnit.MILLISECONDS); ByteArrayInputStream bufIn = new ByteArrayInputStream(body); ReadResponse response = ReadResponse.serializer().deserialize(new DataInputStream(bufIn)); if (response.row() != null) rows.add(response.row()); } } return rows; }
From source file:org.apache.cassandra.db.SystemKeyspace.java
/** * Record tokens being used by another node *//*from w w w . j av a2 s. c o m*/ public static synchronized void updateTokens(InetAddress ep, Collection<Token> tokens) { if (ep.equals(FBUtilities.getBroadcastAddress())) { removeEndpoint(ep); return; } String req = "INSERT INTO system.%s (peer, tokens) VALUES ('%s', %s)"; processInternal(String.format(req, PEERS_CF, ep.getHostAddress(), tokensAsSet(tokens))); }
From source file:org.apache.cassandra.db.SystemKeyspace.java
public static synchronized void updatePeerInfo(InetAddress ep, String columnName, String value) { if (ep.equals(FBUtilities.getBroadcastAddress())) return;/*from ww w . j a v a2s . co m*/ String req = "INSERT INTO system.%s (peer, %s) VALUES ('%s', %s)"; processInternal(String.format(req, PEERS_CF, columnName, ep.getHostAddress(), value)); }