Java 类org.jivesoftware.smack.util.dns.HostAddress 实例源码

项目:Smack    文件:DNSUtilTest.java   
@Test
public void sortSRVdistributeOverWeights() {
    int weight50 = 0;
    int weight20one = 0;
    int weight20two = 0;
    int weight10 = 0;
    for (int i = 0; i < 1000; i++) {
        List<HostAddress> sortedRecords = DNSUtil.sortSRVRecords(createSRVRecords());
        String host = sortedRecords.get(1).getFQDN();
        if (host.equals("5.20.one.foo.bar")) {
            weight20one++;
        } else if (host.equals("5.20.two.foo.bar")) {
            weight20two++;
        } else if (host.equals("5.10.foo.bar")) {
            weight10++;
        } else if (host.equals("5.50.foo.bar")) {
            weight50++;
        } else {
            fail("Wrong host after SRVRecord sorting");
        }
    }
    assertTrue(weight50 > 400 && weight50 < 600);
    assertTrue(weight20one > 100 && weight20one < 300);
    assertTrue(weight20two > 100 && weight20two < 300);
    assertTrue(weight10 > 0&& weight10 < 200);
}
项目:Smack    文件:DNSUtilTest.java   
@Test
public void sortSRVdistributeZeroWeights() {
    int weightZeroOne = 0;
    int weightZeroTwo = 0;
    for (int i = 0; i < 1000; i++) {
        List<HostAddress> sortedRecords = DNSUtil.sortSRVRecords(createSRVRecords());
        // Remove the first 5 records with a lower priority
        for (int j = 0; j < 5; j++) {
            sortedRecords.remove(0);
        }
        String host = sortedRecords.remove(0).getFQDN();
        if (host.equals("10.0.one.foo.bar")) {
            weightZeroOne++;
        } else if (host.endsWith("10.0.two.foo.bar")) {
            weightZeroTwo++;
        } else {
            fail("Wrong host after SRVRecord sorting");
        }
    }
    assertTrue(weightZeroOne > 400 && weightZeroOne < 600);
    assertTrue(weightZeroTwo > 400 && weightZeroTwo < 600);
}
项目:Smack    文件:SmackException.java   
public static ConnectionException from(List<HostAddress> failedAddresses) {
    final String DELIMITER = ", ";
    StringBuilder sb = new StringBuilder("The following addresses failed: ");
    for (HostAddress hostAddress : failedAddresses) {
        sb.append(hostAddress.getErrorMessage());
        sb.append(DELIMITER);
    }
    // Remove the last delimiter
    sb.setLength(sb.length() - DELIMITER.length());
    return new ConnectionException(sb.toString(), failedAddresses);
}
项目:Smack    文件:SmackException.java   
public ConnectionException(Throwable wrappedThrowable) {
    super(wrappedThrowable);
    failedAddresses = new ArrayList<HostAddress>(0);
}
项目:Smack    文件:SmackException.java   
private ConnectionException(String message, List<HostAddress> failedAddresses) {
    super(message);
    this.failedAddresses = failedAddresses;
}
项目:Smack    文件:SmackException.java   
public List<HostAddress> getFailedAddresses() {
    return failedAddresses;
}
项目:Smack    文件:DNSUtil.java   
/**
 * 
 * @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;
}
项目:Smack    文件:DNSUtilTest.java   
@Test
public void sortSRVlowestPrioFirstTest() {
    List<HostAddress> sortedRecords = DNSUtil.sortSRVRecords(createSRVRecords());
    assertTrue(sortedRecords.get(0).getFQDN().equals("0.20.foo.bar"));
}
项目:Smack    文件:DNSUtilTest.java   
private void xmppClientDomainTest() {
    List<HostAddress> hostAddresses = DNSUtil.resolveXMPPDomain(igniterealtimeDomain);
    HostAddress ha = hostAddresses.get(0);
    assertEquals(ha.getFQDN(), igniterealtimeXMPPServer);
    assertEquals(ha.getPort(), igniterealtimeClientPort);
}
项目:Smack    文件:DNSUtilTest.java   
private void xmppServerDomainTest() {
    List<HostAddress> hostAddresses = DNSUtil.resolveXMPPServerDomain(igniterealtimeDomain);
    HostAddress ha = hostAddresses.get(0);
    assertEquals(ha.getFQDN(), igniterealtimeXMPPServer);
    assertEquals(ha.getPort(), igniterealtimeServerPort);
}
项目:androidPN-client.    文件:ConnectionConfiguration.java   
public void setUsedHostAddress(HostAddress hostAddress) {
    this.host = hostAddress.getFQDN();
    this.port = hostAddress.getPort();
}
项目:androidPN-client.    文件:ConnectionConfiguration.java   
public List<HostAddress> getHostAddresses() {
    return Collections.unmodifiableList(hostAddresses);
}
项目:jamppa    文件:ConnectionConfiguration.java   
public void setUsedHostAddress(HostAddress hostAddress) {
    this.host = hostAddress.getFQDN();
    this.port = hostAddress.getPort();
}
项目:jamppa    文件:ConnectionConfiguration.java   
public List<HostAddress> getHostAddresses() {
    return Collections.unmodifiableList(hostAddresses);
}
项目:java-bells    文件:ConnectionConfiguration.java   
public void setUsedHostAddress(HostAddress hostAddress) {
    this.host = hostAddress.getFQDN();
    this.port = hostAddress.getPort();
}
项目:java-bells    文件:ConnectionConfiguration.java   
public List<HostAddress> getHostAddresses() {
    return Collections.unmodifiableList(hostAddresses);
}
项目:asmack-mini    文件:ConnectionConfiguration.java   
public void setUsedHostAddress(HostAddress hostAddress) {
    this.host = hostAddress.getFQDN();
    this.port = hostAddress.getPort();
}
项目:asmack-mini    文件:ConnectionConfiguration.java   
public List<HostAddress> getHostAddresses() {
    return Collections.unmodifiableList(hostAddresses);
}
项目:Smack    文件:DNSUtil.java   
/**
 * Returns a list of HostAddresses under which the specified XMPP server can be reached at for client-to-server
 * communication. A DNS lookup for a SRV record in the form "_xmpp-client._tcp.example.com" is attempted, according
 * to section 3.2.1 of RFC 6120. If that lookup fails, it's assumed that the XMPP server lives at the host resolved
 * by a DNS lookup at the specified domain on the default port of 5222.
 * <p>
 * As an example, a lookup for "example.com" may return "im.example.com:5269".
 * </p>
 *
 * @param domain the domain.
 * @param failedAddresses on optional list that will be populated with host addresses that failed to resolve.
 * @return List of HostAddress, which encompasses the hostname and port that the
 *      XMPP server can be reached at for the specified domain.
 */
public static List<HostAddress> resolveXMPPDomain(String domain, List<HostAddress> failedAddresses) {
    domain = idnaTransformer.transform(domain);
    if (dnsResolver == null) {
        LOGGER.warning("No DNS Resolver active in Smack, will be unable to perform DNS SRV lookups");
        List<HostAddress> addresses = new ArrayList<HostAddress>(1);
        addresses.add(new HostAddress(domain, 5222));
        return addresses;
    }
    return resolveDomain(domain, DomainType.Client, failedAddresses);
}
项目:Smack    文件:DNSUtil.java   
/**
 * Returns a list of HostAddresses under which the specified XMPP server can be reached at for server-to-server
 * communication. A DNS lookup for a SRV record in the form "_xmpp-server._tcp.example.com" is attempted, according
 * to section 3.2.1 of RFC 6120. If that lookup fails , it's assumed that the XMPP server lives at the host resolved
 * by a DNS lookup at the specified domain on the default port of 5269.
 * <p>
 * As an example, a lookup for "example.com" may return "im.example.com:5269".
 * </p>
 *
 * @param domain the domain.
 * @param failedAddresses on optional list that will be populated with host addresses that failed to resolve.
 * @return List of HostAddress, which encompasses the hostname and port that the
 *      XMPP server can be reached at for the specified domain.
 */
public static List<HostAddress> resolveXMPPServerDomain(String domain, List<HostAddress> failedAddresses) {
    domain = idnaTransformer.transform(domain);
    if (dnsResolver == null) {
        LOGGER.warning("No DNS Resolver active in Smack, will be unable to perform DNS SRV lookups");
        List<HostAddress> addresses = new ArrayList<HostAddress>(1);
        addresses.add(new HostAddress(domain, 5269));
        return addresses;
    }
    return resolveDomain(domain, DomainType.Server, failedAddresses);
}
项目:jamppa    文件:DNSUtil.java   
/**
 * Returns a list of HostAddresses under which the specified XMPP server can
 * be reached at for client-to-server communication. A DNS lookup for a SRV
 * record in the form "_xmpp-client._tcp.example.com" is attempted,
 * according to section 14.4 of RFC 3920. If that lookup fails, a lookup in
 * the older form of "_jabber._tcp.example.com" is attempted since servers
 * that implement an older version of the protocol may be listed using that
 * notation. If that lookup fails as well, it's assumed that the XMPP server
 * lives at the host resolved by a DNS lookup at the specified domain on the
 * default port of 5222.
 * <p>
 * 
 * As an example, a lookup for "example.com" may return
 * "im.example.com:5269".
 * 
 * @param domain
 *            the domain.
 * @return List of HostAddress, which encompasses the hostname and port that
 *         the XMPP server can be reached at for the specified domain.
 */
public static List<HostAddress> resolveXMPPDomain(final String domain) {
    if (dnsResolver == null) {
        List<HostAddress> addresses = new ArrayList<HostAddress>(1);
        addresses.add(new HostAddress(domain, 5222));
        return addresses;
    }
    return resolveDomain(domain, 'c');
}
项目:jamppa    文件:DNSUtil.java   
/**
 * Returns a list of HostAddresses under which the specified XMPP server can
 * be reached at for server-to-server communication. A DNS lookup for a SRV
 * record in the form "_xmpp-server._tcp.example.com" is attempted,
 * according to section 14.4 of RFC 3920. If that lookup fails, a lookup in
 * the older form of "_jabber._tcp.example.com" is attempted since servers
 * that implement an older version of the protocol may be listed using that
 * notation. If that lookup fails as well, it's assumed that the XMPP server
 * lives at the host resolved by a DNS lookup at the specified domain on the
 * default port of 5269.
 * <p>
 * 
 * As an example, a lookup for "example.com" may return
 * "im.example.com:5269".
 * 
 * @param domain
 *            the domain.
 * @return List of HostAddress, which encompasses the hostname and port that
 *         the XMPP server can be reached at for the specified domain.
 */
public static List<HostAddress> resolveXMPPServerDomain(final String domain) {
    if (dnsResolver == null) {
        List<HostAddress> addresses = new ArrayList<HostAddress>(1);
        addresses.add(new HostAddress(domain, 5269));
        return addresses;
    }
    return resolveDomain(domain, 's');
}
项目:java-bells    文件:DNSUtil.java   
/**
 * Returns a list of HostAddresses under which the specified XMPP server can be
 * reached at for client-to-server communication. A DNS lookup for a SRV
 * record in the form "_xmpp-client._tcp.example.com" is attempted, according
 * to section 14.4 of RFC 3920. If that lookup fails, a lookup in the older form
 * of "_jabber._tcp.example.com" is attempted since servers that implement an
 * older version of the protocol may be listed using that notation. If that
 * lookup fails as well, it's assumed that the XMPP server lives at the
 * host resolved by a DNS lookup at the specified domain on the default port
 * of 5222.<p>
 *
 * As an example, a lookup for "example.com" may return "im.example.com:5269".
 *
 * @param domain the domain.
 * @return List of HostAddress, which encompasses the hostname and port that the
 *      XMPP server can be reached at for the specified domain.
 */
public static List<HostAddress> resolveXMPPDomain(final String domain) {
    if (dnsResolver == null) {
        List<HostAddress> addresses = new ArrayList<HostAddress>(1);
        addresses.add(new HostAddress(domain, 5222));
        return addresses;
    }
    return resolveDomain(domain, 'c');
}
项目:java-bells    文件:DNSUtil.java   
/**
 * Returns a list of HostAddresses under which the specified XMPP server can be
 * reached at for server-to-server communication. A DNS lookup for a SRV
 * record in the form "_xmpp-server._tcp.example.com" is attempted, according
 * to section 14.4 of RFC 3920. If that lookup fails, a lookup in the older form
 * of "_jabber._tcp.example.com" is attempted since servers that implement an
 * older version of the protocol may be listed using that notation. If that
 * lookup fails as well, it's assumed that the XMPP server lives at the
 * host resolved by a DNS lookup at the specified domain on the default port
 * of 5269.<p>
 *
 * As an example, a lookup for "example.com" may return "im.example.com:5269".
 *
 * @param domain the domain.
 * @return List of HostAddress, which encompasses the hostname and port that the
 *      XMPP server can be reached at for the specified domain.
 */
public static List<HostAddress> resolveXMPPServerDomain(final String domain) {
    if (dnsResolver == null) {
        List<HostAddress> addresses = new ArrayList<HostAddress>(1);
        addresses.add(new HostAddress(domain, 5269));
        return addresses;
    }
    return resolveDomain(domain, 's');
}
项目:androidPN-client.    文件:DNSUtil.java   
/**
 * Returns a list of HostAddresses under which the specified XMPP server can be
 * reached at for client-to-server communication. A DNS lookup for a SRV
 * record in the form "_xmpp-client._tcp.example.com" is attempted, according
 * to section 14.4 of RFC 3920. If that lookup fails, a lookup in the older form
 * of "_jabber._tcp.example.com" is attempted since servers that implement an
 * older version of the protocol may be listed using that notation. If that
 * lookup fails as well, it's assumed that the XMPP server lives at the
 * host resolved by a DNS lookup at the specified domain on the default port
 * of 5222.<p>
 *
 * As an example, a lookup for "example.com" may return "im.example.com:5269".
 *
 * @param domain the domain.
 * @return List of HostAddress, which encompasses the hostname and port that the
 *      XMPP server can be reached at for the specified domain.
 */
public static List<HostAddress> resolveXMPPDomain(String domain) {
    return resolveDomain(domain, 'c');
}
项目:androidPN-client.    文件:DNSUtil.java   
/**
 * Returns a list of HostAddresses under which the specified XMPP server can be
 * reached at for server-to-server communication. A DNS lookup for a SRV
 * record in the form "_xmpp-server._tcp.example.com" is attempted, according
 * to section 14.4 of RFC 3920. If that lookup fails, a lookup in the older form
 * of "_jabber._tcp.example.com" is attempted since servers that implement an
 * older version of the protocol may be listed using that notation. If that
 * lookup fails as well, it's assumed that the XMPP server lives at the
 * host resolved by a DNS lookup at the specified domain on the default port
 * of 5269.<p>
 *
 * As an example, a lookup for "example.com" may return "im.example.com:5269".
 *
 * @param domain the domain.
 * @return List of HostAddress, which encompasses the hostname and port that the
 *      XMPP server can be reached at for the specified domain.
 */
public static List<HostAddress> resolveXMPPServerDomain(String domain) {
    return resolveDomain(domain, 's');
}
项目:asmack-mini    文件:DNSUtil.java   
/**
 * Returns a list of HostAddresses under which the specified XMPP server can be
 * reached at for client-to-server communication. A DNS lookup for a SRV
 * record in the form "_xmpp-client._tcp.example.com" is attempted, according
 * to section 14.4 of RFC 3920. If that lookup fails, a lookup in the older form
 * of "_jabber._tcp.example.com" is attempted since servers that implement an
 * older version of the protocol may be listed using that notation. If that
 * lookup fails as well, it's assumed that the XMPP server lives at the
 * host resolved by a DNS lookup at the specified domain on the default port
 * of 5222.<p>
 *
 * As an example, a lookup for "example.com" may return "im.example.com:5269".
 *
 * @param domain the domain.
 * @return List of HostAddress, which encompasses the hostname and port that the
 *      XMPP server can be reached at for the specified domain.
 */
public static List<HostAddress> resolveXMPPDomain(String domain) {
    return resolveDomain(domain, 'c');
}
项目:asmack-mini    文件:DNSUtil.java   
/**
 * Returns a list of HostAddresses under which the specified XMPP server can be
 * reached at for server-to-server communication. A DNS lookup for a SRV
 * record in the form "_xmpp-server._tcp.example.com" is attempted, according
 * to section 14.4 of RFC 3920. If that lookup fails, a lookup in the older form
 * of "_jabber._tcp.example.com" is attempted since servers that implement an
 * older version of the protocol may be listed using that notation. If that
 * lookup fails as well, it's assumed that the XMPP server lives at the
 * host resolved by a DNS lookup at the specified domain on the default port
 * of 5269.<p>
 *
 * As an example, a lookup for "example.com" may return "im.example.com:5269".
 *
 * @param domain the domain.
 * @return List of HostAddress, which encompasses the hostname and port that the
 *      XMPP server can be reached at for the specified domain.
 */
public static List<HostAddress> resolveXMPPServerDomain(String domain) {
    return resolveDomain(domain, 's');
}