@Override protected List<SRVRecord> lookupSRVRecords0(DnsName name, List<HostAddress> failedAddresses, DnssecMode dnssecMode) { List<SRVRecord> res = new ArrayList<>(); Lookup lookup; try { lookup = new Lookup(name.ace, Type.SRV); } catch (TextParseException e) { throw new IllegalStateException(e); } Record[] recs = lookup.run(); if (recs == null) return res; for (Record record : recs) { org.xbill.DNS.SRVRecord srvRecord = (org.xbill.DNS.SRVRecord) record; if (srvRecord != null && srvRecord.getTarget() != null) { DnsName host = DnsName.from(srvRecord.getTarget().toString()); int port = srvRecord.getPort(); int priority = srvRecord.getPriority(); int weight = srvRecord.getWeight(); List<InetAddress> hostAddresses = lookupHostAddress0(host, failedAddresses, dnssecMode); if (shouldContinue(name, host, hostAddresses)) { continue; } SRVRecord r = new SRVRecord(host, port, priority, weight, hostAddresses); res.add(r); } } return res; }
@Override public int compare(Record rec1, Record rec2) { if (((SRVRecord)rec1).getPriority() == ((SRVRecord)rec2).getPriority()) { if (((SRVRecord)rec1).getWeight() < ((SRVRecord)rec2).getWeight()) return 1; else return (((SRVRecord)rec1).getWeight() > ((SRVRecord)rec2).getWeight()) ? -1 : 0; } return (((SRVRecord)rec1).getPriority() < ((SRVRecord)rec2).getPriority()) ? -1 : 1; }
@Nullable protected HostService toHostService(@Nonnull SRVRecord record) { final InetSocketAddress address = toInetSocketAddress(record); return address != null ? new HostService(address, record.getPriority(), record.getWeight(), record.getTTL()) : null; }
public int compare(Record o1, Record o2) { SRVRecord o1SRVRecord = (SRVRecord) o1; SRVRecord o2SRVRecord = (SRVRecord) o2; int o1Priority = o1SRVRecord.getPriority(); int o2Priority = o2SRVRecord.getPriority(); // the lower priority is the best if(o1Priority > o2Priority) return 1; if(o1Priority < o2Priority) return -1; // if they are the same sort them through weight int o1Weight = o1SRVRecord.getWeight(); int o2Weight = o2SRVRecord.getWeight(); // the higher weight is the best if(o1Weight < o2Weight) return 1; if(o1Weight > o2Weight) return -1; // RFC 3263 Section 4.4 return o1SRVRecord.getTarget().compareTo(o2SRVRecord.getTarget()); }
private static List<LookupResult> toLookupResults(Record[] queryResult) { ImmutableList.Builder<LookupResult> builder = ImmutableList.builder(); if (queryResult != null) { for (Record record: queryResult) { if (record instanceof SRVRecord) { SRVRecord srvRecord = (SRVRecord) record; builder.add(LookupResult.create(srvRecord.getTarget().toString(), srvRecord.getPort(), srvRecord.getPriority(), srvRecord.getWeight(), srvRecord.getTTL())); } } } return builder.build(); } }
private static List<LookupResult> toLookupResults(Record[] queryResult) { ImmutableList.Builder<LookupResult> builder = ImmutableList.builder(); if (queryResult != null) { for (Record record: queryResult) { if (record instanceof SRVRecord) { SRVRecord srvRecord = (SRVRecord) record; builder.add(LookupResult.create(srvRecord.getTarget().toString(), srvRecord.getPort(), srvRecord.getPriority(), srvRecord.getWeight(), srvRecord.getTTL())); } } } return builder.build(); } }
public ServiceInstance(final SRVRecord srv) throws TextParseException { this(new ServiceName(srv.getName()), srv.getPriority(), srv.getWeight(), srv.getPort(), srv.getTarget(), null, (Map) null); }
int port = srvRecord.getPort(); int priority = srvRecord.getPriority(); int weight = srvRecord.getWeight();