当前位置: 首页>>代码示例>>Java>>正文


Java SRVRecord类代码示例

本文整理汇总了Java中org.jivesoftware.smack.util.dns.SRVRecord的典型用法代码示例。如果您正苦于以下问题:Java SRVRecord类的具体用法?Java SRVRecord怎么用?Java SRVRecord使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


SRVRecord类属于org.jivesoftware.smack.util.dns包,在下文中一共展示了SRVRecord类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: lookupSRVRecords

import org.jivesoftware.smack.util.dns.SRVRecord; //导入依赖的package包/类
@Override
public List<SRVRecord> lookupSRVRecords(String name) throws TextParseException {
    List<SRVRecord> res = new ArrayList<SRVRecord>();

    Lookup lookup = new Lookup(name, Type.SRV);
    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) {
            String host = srvRecord.getTarget().toString();
            int port = srvRecord.getPort();
            int priority = srvRecord.getPriority();
            int weight = srvRecord.getWeight();

            SRVRecord r = new SRVRecord(host, port, priority, weight);
            res.add(r);
        }
    }

    return res;
}
 
开发者ID:TTalkIM,项目名称:Smack,代码行数:25,代码来源:DNSJavaResolver.java

示例2: lookupSRVRecords

import org.jivesoftware.smack.util.dns.SRVRecord; //导入依赖的package包/类
@Override
public List<SRVRecord> lookupSRVRecords(String name) throws NamingException {
    List<SRVRecord> res = new ArrayList<SRVRecord>();

    Attributes dnsLookup = dirContext.getAttributes(name, new String[] { "SRV" });
    Attribute srvAttribute = dnsLookup.get("SRV");
    if (srvAttribute == null)
        return res;
    @SuppressWarnings("unchecked")
    NamingEnumeration<String> srvRecords = (NamingEnumeration<String>) srvAttribute.getAll();
    while (srvRecords.hasMore()) {
        String srvRecordString = srvRecords.next();
        String[] srvRecordEntries = srvRecordString.split(" ");
        int priority = Integer.parseInt(srvRecordEntries[srvRecordEntries.length - 4]);
        int port = Integer.parseInt(srvRecordEntries[srvRecordEntries.length - 2]);
        int weight = Integer.parseInt(srvRecordEntries[srvRecordEntries.length - 3]);
        String host = srvRecordEntries[srvRecordEntries.length - 1];

        SRVRecord srvRecord = new SRVRecord(host, port, priority, weight);
        res.add(srvRecord);
    }
    return res;
}
 
开发者ID:TTalkIM,项目名称:Smack,代码行数:24,代码来源:JavaxResolver.java

示例3: createSRVRecords

import org.jivesoftware.smack.util.dns.SRVRecord; //导入依赖的package包/类
private static List<SRVRecord> createSRVRecords() {
    List<SRVRecord> records = new ArrayList<SRVRecord>();
    // We create one record with priority 0 that should also be tried first
    // Then 4 records with priority 5 and different weights (50, 20, 20, 10)
    // Then 2 records with priority 10 and weight 0 which should be treaded equal
    // These records are added in a 'random' way to the list
    try {
        records.add(new SRVRecord("5.20.one.foo.bar", 42, 5, 20));     // Priority 5, Weight 20
        records.add(new SRVRecord("10.0.one.foo.bar", 42, 10, 0)); // Priority 10, Weight 0
        records.add(new SRVRecord("5.10.foo.bar", 42, 5, 10));     // Priority 5, Weight 10
        records.add(new SRVRecord("10.0.two.foo.bar", 42, 10, 0)); // Priority 10, Weight 0
        records.add(new SRVRecord("5.20.two.foo.bar", 42, 5, 20));     // Priority 5, Weight 20
        records.add(new SRVRecord("0.20.foo.bar", 42, 0, 20));     // Priority 0, Weight 20
        records.add(new SRVRecord("5.50.foo.bar", 42, 5, 50));     // Priority 5, Weight 50
    } catch (IllegalArgumentException e) {
        // Ignore
    }
    assertTrue(records.size() > 0);
    return records;
}
 
开发者ID:TTalkIM,项目名称:Smack,代码行数:21,代码来源:DNSUtilTest.java

示例4: lookupSRVRecords

import org.jivesoftware.smack.util.dns.SRVRecord; //导入依赖的package包/类
@Override
public List<SRVRecord> lookupSRVRecords(String name) {
    List<SRVRecord> res = new LinkedList<SRVRecord>();
    DNSMessage message = client.query(name, TYPE.SRV, CLASS.IN);
    if (message == null) {
        return res;
    }
    for (Record record : message.getAnswers()) {
        SRV srv = (SRV) record.getPayload();
        res.add(new SRVRecord(srv.getName(), srv.getPort(), srv.getPriority(), srv.getWeight()));
    }
    return res;
}
 
开发者ID:TTalkIM,项目名称:Smack,代码行数:14,代码来源:MiniDnsResolver.java

示例5: resolveDomain

import org.jivesoftware.smack.util.dns.SRVRecord; //导入依赖的package包/类
/**
 * 
 * @param domain the domain.
 * @param domainType the XMPP domain type, server or client.
 * @param failedAddresses on optional list that will be populated with host addresses that failed to resolve.
 * @return a list of resolver host addresses for this domain.
 */
private static List<HostAddress> resolveDomain(String domain, DomainType domainType, List<HostAddress> failedAddresses) {
    List<HostAddress> addresses = new ArrayList<HostAddress>();

    // Step one: Do SRV lookups
    String srvDomain;
    switch (domainType) {
    case Server:
        srvDomain = "_xmpp-server._tcp." + domain;
        break;
    case Client:
        srvDomain = "_xmpp-client._tcp." + domain;
        break;
    default:
        throw new AssertionError();
    }
    try {
        List<SRVRecord> srvRecords = dnsResolver.lookupSRVRecords(srvDomain);
        if (LOGGER.isLoggable(Level.FINE)) {
            String logMessage = "Resolved SRV RR for " + srvDomain + ":";
            for (SRVRecord r : srvRecords)
                logMessage += " " + r;
            LOGGER.fine(logMessage);
        }
        List<HostAddress> sortedRecords = sortSRVRecords(srvRecords);
        addresses.addAll(sortedRecords);
    }
    catch (Exception e) {
        LOGGER.log(Level.WARNING, "Exception while resovling SRV records for " + domain
                        + ". Consider adding '_xmpp-(server|client)._tcp' DNS SRV Records", e);
        if (failedAddresses != null) {
            HostAddress failedHostAddress = new HostAddress(srvDomain);
            failedHostAddress.setException(e);
            failedAddresses.add(failedHostAddress);
        }
    }

    // Step two: Add the hostname to the end of the list
    addresses.add(new HostAddress(domain));

    return addresses;
}
 
开发者ID:TTalkIM,项目名称:Smack,代码行数:49,代码来源:DNSUtil.java


注:本文中的org.jivesoftware.smack.util.dns.SRVRecord类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。