本文整理汇总了Java中org.xbill.DNS.SRVRecord类的典型用法代码示例。如果您正苦于以下问题:Java SRVRecord类的具体用法?Java SRVRecord怎么用?Java SRVRecord使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
SRVRecord类属于org.xbill.DNS包,在下文中一共展示了SRVRecord类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getUpdatedListOfServers
import org.xbill.DNS.SRVRecord; //导入依赖的package包/类
@Override
public List<ServiceCallServer> getUpdatedListOfServers(String name) {
final Lookup lookup = lookupFactory.apply(name);
final Record[] records = lookup.run();
List<ServiceCallServer> servers;
if (Objects.nonNull(records) && lookup.getResult() == Lookup.SUCCESSFUL) {
servers = Arrays.stream(records)
.filter(SRVRecord.class::isInstance)
.map(SRVRecord.class::cast)
.sorted(DnsServiceCallServer.COMPARATOR)
.map(DnsServiceCallServer::new)
.collect(Collectors.toList());
} else {
servers = Collections.emptyList();
}
return servers;
}
示例2: resolveSrvByName
import org.xbill.DNS.SRVRecord; //导入依赖的package包/类
private String resolveSrvByName(Resolver resolver, String name) {
try {
Lookup lookup = new Lookup(name, SRV);
if (resolver != null) {
lookup.setResolver(resolver);
}
Record[] records = lookup.run();
if (records == null) {
return null;
}
return of(records)
.filter(it -> it instanceof SRVRecord)
.map(srv -> resolveHostByName(resolver, ((SRVRecord) srv).getTarget()) + ":" + ((SRVRecord) srv).getPort())
.distinct()
.collect(joining(","));
} catch (TextParseException e) {
log.warn("unable to resolve using SRV record " + name, e);
return null;
}
}
示例3: getMultiSRV
import org.xbill.DNS.SRVRecord; //导入依赖的package包/类
public List<DNSServiceRecord> getMultiSRV(String key) throws ConfigException {
String qkey = fullyQualify(key);
List<DNSServiceRecord> result = new ArrayList<DNSServiceRecord>();
List<Record> list = m_records.get(makeHostKey(qkey));
if (list == null) {
throw new NotFoundException("No such record: " + makeHostKey(qkey));
}
for (Record r : list) {
if (r.getType() != Type.SRV) {
continue;
}
result.add(new DNSServiceRecord(((SRVRecord) r).rdataToString()));
}
return result;
}
示例4: build
import org.xbill.DNS.SRVRecord; //导入依赖的package包/类
/**
* Static builder. It wraps out a {@link SRVRecord} by extracting relevant data.
*
* @param srvRecord A {@link SRVRecord} instance to be worked out
* @return An instance of <code>ServiceRecord</code>
*/
public static ServiceRecord build(SRVRecord srvRecord)
{
String proto = "N/A";
String owner = srvRecord.getName().toString();
if(owner.contains(Constants.TCP))
proto = Constants.TCP.replace("_", "").toUpperCase();
else if(owner.contains(Constants.UDP))
proto = Constants.UDP.replace("_", "").toUpperCase();
return new ServiceRecord(srvRecord.getName().toString(),
srvRecord.getTarget().toString(),
proto,
srvRecord.getPort(), srvRecord.getPriority(),
srvRecord.getWeight(), srvRecord.getTTL());
}
示例5: toLookupResults
import org.xbill.DNS.SRVRecord; //导入依赖的package包/类
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();
}
示例6: getSRV
import org.xbill.DNS.SRVRecord; //导入依赖的package包/类
public DNSServiceRecord getSRV(String key) throws ConfigException {
String qkey = fullyQualify(key);
List<Record> list = m_records.get(makeHostKey(qkey));
if (list == null || list.get(0).getType() != Type.SRV) {
throw new NotFoundException("No such record: " + makeHostKey(qkey));
}
SRVRecord srec = (SRVRecord) list.get(0);
return new DNSServiceRecord(srec.rdataToString());
}
示例7: parseRecords
import org.xbill.DNS.SRVRecord; //导入依赖的package包/类
/**
* Scrapes the Discovery Service Records according to their nature.
*
* @param records An array of <code>Record</code> retrieve upon a lookup
* @param set A <code>ResourcesContainer</code>
* @param pht A Resource Record Type holder
*/
private void parseRecords(Record[] records, final RecordsContainer set, RrHolderType pht)
{
if (records != null) {
for (Record record : records) {
if ((record instanceof PTRRecord && pht == RrHolderType.ZONES) ||
(record instanceof PTRRecord && pht == RrHolderType.NAMES)) {
String zone = PointerRecord.build((PTRRecord) record).getRData();
if (zone != null) {
set.getLabels().add(zone);
}
} else if (record instanceof PTRRecord && pht == RrHolderType.TYPES) {
set.getLabels().add(PointerRecord.build((PTRRecord) record).getServiceType());
} else if (record instanceof SRVRecord) {
ServiceRecord svcRecord = ServiceRecord.build((SRVRecord) record);
if (svcRecord != null) {
set.getRecords().add(svcRecord);
}
} else if (record instanceof TXTRecord) {
set.getTexts().add(TextRecord.build((TXTRecord) record));
} else {
errorsTrace.get().put(
ExceptionsUtil.traceKey(record.toString(), "",
"Parsing-Service-Records"),
StatusCode.RESOURCE_UNEXPECTED);
}
}
}
}
示例8: getAllAddresses
import org.xbill.DNS.SRVRecord; //导入依赖的package包/类
private InetAddress[] getAllAddresses(SRVRecord srv)
throws UnknownHostException {
try {
return org.xbill.DNS.Address.getAllByName(srv.getTarget().canonicalize().toString(true));
} catch (UnknownHostException e) {
logger.severe("Parsing DNS records failed", e);
throw e;
}
}
示例9: messageWithNodes
import org.xbill.DNS.SRVRecord; //导入依赖的package包/类
private Message messageWithNodes(String query, Iterable<String> names) throws TextParseException {
Name queryName = Name.fromString(query);
Record question = Record.newRecord(queryName, Type.SRV, DClass.IN);
Message queryMessage = Message.newQuery(question);
Message result = new Message();
result.setHeader(queryMessage.getHeader());
result.addRecord(question, Section.QUESTION);
for (String name1 : names){
result.addRecord(new SRVRecord(queryName, DClass.IN, 1, 1, 1, 8080, Name.fromString(name1)), Section.ANSWER);
}
return result;
}
示例10: dnsSrvLookup
import org.xbill.DNS.SRVRecord; //导入依赖的package包/类
private String dnsSrvLookup(String query) throws ServiceAddressResolvingException {
String result;
try {
Record[] records = new Lookup(query, Type.SRV).run();
if (records != null && records.length > 0) {
SRVRecord srv = (SRVRecord) records[0];
result = srv.getTarget().toString().replaceFirst("\\.$", "") + ':' + srv.getPort();
} else {
throw new ServiceAddressResolvingException("The Service " + query + " cannot be resolved");
}
} catch (TextParseException e) {
throw new ServiceAddressResolvingException("The Service " + query + " cannot be resolved", e);
}
return result;
}
示例11: DnsServiceCallServer
import org.xbill.DNS.SRVRecord; //导入依赖的package包/类
public DnsServiceCallServer(SRVRecord record) {
super(record.getTarget().toString(true), record.getPort());
}
示例12: comparator
import org.xbill.DNS.SRVRecord; //导入依赖的package包/类
public static Comparator<SRVRecord> comparator() {
Comparator<SRVRecord> byPriority = (e1, e2) -> Integer.compare(e2.getPriority(), e1.getPriority());
Comparator<SRVRecord> byWeight = (e1, e2) -> Integer.compare(e2.getWeight(), e1.getWeight());
return byPriority.thenComparing(byWeight);
}
示例13: createSrvRecord
import org.xbill.DNS.SRVRecord; //导入依赖的package包/类
public static SRVRecord createSrvRecord ( String host, int port, int priority, int weight, long ttl )
throws TextParseException {
return new SRVRecord( Name.fromString( "example.com." ), DClass.IN, ttl, priority, weight, port, Name.fromString( host ) );
}
示例14: setup
import org.xbill.DNS.SRVRecord; //导入依赖的package包/类
@Before
public void setup() throws Exception {
PowerMockito.whenNew(DefaultKubernetesClient.class).withAnyArguments().thenReturn(client);
PowerMockito.whenNew(SRVRecord.class).withAnyArguments().thenReturn(srvRecord);
when(srvRecord.getTarget()).thenReturn(Name.fromString("127.0.0.1"));
}
示例15: startAddressFetch
import org.xbill.DNS.SRVRecord; //导入依赖的package包/类
private synchronized void startAddressFetch() {
if( addressFetchThread != null )
return;
addressFetchThread = new Thread() {
@Override
public void run() {
Record[] stunRecords = null;
Record[] turnRecords = null;
for( int i=0; i<hosts.length; ++i ) {
String stunQuery = "_stun._udp." + hosts[i] ;
String turnQuery = "_turn._udp." + hosts[i] ;
try {
if( stunRecords == null )
stunRecords = lookupSrv( stunQuery );
if( turnRecords == null )
turnRecords = lookupSrv( turnQuery );
if( stunRecords != null && turnRecords != null )
break;
} catch( TextParseException tpe ) {
throw new RuntimeException( tpe );
}
}
if( stunRecords == null ) {
stunAddresses = null ;
} else {
stunAddresses = new TransportAddress[stunRecords.length];
for( int i=0; i<stunRecords.length; ++i ) {
SRVRecord srv = (SRVRecord) stunRecords[i] ;
stunAddresses[i] = new TransportAddress(srv.getTarget().toString().replaceFirst("\\.$", ""), srv.getPort(), Transport.UDP);
}
}
if( turnRecords == null ) {
turnAddresses = null ;
} else {
turnAddresses = new TransportAddress[stunRecords.length];
for( int i=0; i<turnAddresses.length; ++i ) {
SRVRecord srv = (SRVRecord) turnRecords[i] ;
turnAddresses[i] = new TransportAddress(srv.getTarget().toString().replaceFirst("\\.$", ""), srv.getPort(), Transport.UDP);
}
}
}
private Record[] lookupSrv(String query) throws TextParseException {
while( true ) {
try {
// Bug 6427854 causes this to sometimes throw an NPE
return new Lookup( query, Type.SRV ).run();
} catch( NullPointerException npe ) {
Thread.yield();
}
}
}
};
addressFetchThread.start();
}