本文整理汇总了Java中org.jivesoftware.smack.util.dns.HostAddress类的典型用法代码示例。如果您正苦于以下问题:Java HostAddress类的具体用法?Java HostAddress怎么用?Java HostAddress使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
HostAddress类属于org.jivesoftware.smack.util.dns包,在下文中一共展示了HostAddress类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: sortSRVdistributeOverWeights
import org.jivesoftware.smack.util.dns.HostAddress; //导入依赖的package包/类
@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);
}
示例2: sortSRVdistributeZeroWeights
import org.jivesoftware.smack.util.dns.HostAddress; //导入依赖的package包/类
@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);
}
示例3: from
import org.jivesoftware.smack.util.dns.HostAddress; //导入依赖的package包/类
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);
}
示例4: ConnectionException
import org.jivesoftware.smack.util.dns.HostAddress; //导入依赖的package包/类
public ConnectionException(Throwable wrappedThrowable) {
super(wrappedThrowable);
failedAddresses = new ArrayList<HostAddress>(0);
}
示例5: getFailedAddresses
import org.jivesoftware.smack.util.dns.HostAddress; //导入依赖的package包/类
public List<HostAddress> getFailedAddresses() {
return failedAddresses;
}
示例6: resolveDomain
import org.jivesoftware.smack.util.dns.HostAddress; //导入依赖的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;
}
示例7: sortSRVlowestPrioFirstTest
import org.jivesoftware.smack.util.dns.HostAddress; //导入依赖的package包/类
@Test
public void sortSRVlowestPrioFirstTest() {
List<HostAddress> sortedRecords = DNSUtil.sortSRVRecords(createSRVRecords());
assertTrue(sortedRecords.get(0).getFQDN().equals("0.20.foo.bar"));
}
示例8: xmppClientDomainTest
import org.jivesoftware.smack.util.dns.HostAddress; //导入依赖的package包/类
private void xmppClientDomainTest() {
List<HostAddress> hostAddresses = DNSUtil.resolveXMPPDomain(igniterealtimeDomain);
HostAddress ha = hostAddresses.get(0);
assertEquals(ha.getFQDN(), igniterealtimeXMPPServer);
assertEquals(ha.getPort(), igniterealtimeClientPort);
}
示例9: xmppServerDomainTest
import org.jivesoftware.smack.util.dns.HostAddress; //导入依赖的package包/类
private void xmppServerDomainTest() {
List<HostAddress> hostAddresses = DNSUtil.resolveXMPPServerDomain(igniterealtimeDomain);
HostAddress ha = hostAddresses.get(0);
assertEquals(ha.getFQDN(), igniterealtimeXMPPServer);
assertEquals(ha.getPort(), igniterealtimeServerPort);
}
示例10: setUsedHostAddress
import org.jivesoftware.smack.util.dns.HostAddress; //导入依赖的package包/类
public void setUsedHostAddress(HostAddress hostAddress) {
this.host = hostAddress.getFQDN();
this.port = hostAddress.getPort();
}
示例11: getHostAddresses
import org.jivesoftware.smack.util.dns.HostAddress; //导入依赖的package包/类
public List<HostAddress> getHostAddresses() {
return Collections.unmodifiableList(hostAddresses);
}
示例12: resolveXMPPDomain
import org.jivesoftware.smack.util.dns.HostAddress; //导入依赖的package包/类
/**
* 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);
}
示例13: resolveXMPPServerDomain
import org.jivesoftware.smack.util.dns.HostAddress; //导入依赖的package包/类
/**
* 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);
}
示例14: resolveXMPPDomain
import org.jivesoftware.smack.util.dns.HostAddress; //导入依赖的package包/类
/**
* 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');
}
示例15: resolveXMPPServerDomain
import org.jivesoftware.smack.util.dns.HostAddress; //导入依赖的package包/类
/**
* 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');
}