本文整理汇总了Java中com.datastax.driver.core.Host.getDatacenter方法的典型用法代码示例。如果您正苦于以下问题:Java Host.getDatacenter方法的具体用法?Java Host.getDatacenter怎么用?Java Host.getDatacenter使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.datastax.driver.core.Host
的用法示例。
在下文中一共展示了Host.getDatacenter方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: buildNetworkTopologyStrategyString
import com.datastax.driver.core.Host; //导入方法依赖的package包/类
static String buildNetworkTopologyStrategyString(Cluster cluster) {
Map<String, Integer> ntsMap = Maps.newHashMap();
for (Host host : cluster.getMetadata().getAllHosts()) {
String dc = host.getDatacenter();
ntsMap.put(dc, 1 + ntsMap.getOrDefault(dc, 0));
}
StringBuilder builder = new StringBuilder("'class':'NetworkTopologyStrategy',");
for (Map.Entry<String, Integer> e : ntsMap.entrySet()) {
builder.append("'").append(e.getKey()).append("':").append(e.getValue()).append(",");
}
return builder.substring(0, builder.length() - 1);
}
示例2: prettyHost
import com.datastax.driver.core.Host; //导入方法依赖的package包/类
public static String prettyHost(final Host host) {
Preconditions.checkNotNull(host);
InetAddress address = host.getAddress();
VersionNumber v = host.getCassandraVersion();
String datacenter = host.getDatacenter();
String rack = host.getRack();
InetSocketAddress socketAddress = host.getSocketAddress();
int port = socketAddress.getPort();
InetAddress sockAddress = socketAddress.getAddress();
StringBuilder b = new StringBuilder();
b.append("\n\tHost (" + address.getCanonicalHostName() + ") [");
b.append("\n\t\tHostAddress:\t\t" + address.getHostAddress());
b.append("\n\t\tHostName:\t\t" + address.getHostName());
b.append("\n\t\tSocket Canonical:\t" + sockAddress.getCanonicalHostName());
b.append("\n\t\tSocket HostAddress:\t" + sockAddress.getHostAddress());
b.append("\n\t\tSocket HostName:\t" + sockAddress.getHostName());
b.append("\n\t\tSocket Port:\t\t" + port);
b.append("\n\t\tDataCenter:\t\t" + datacenter);
b.append("\n\t\tRack:\t\t\t" + rack);
b.append("\n\t\tIs Up:\t\t\t" + host.isUp());
b.append("\n\t\tCassandra Version:\t" + v.getMajor() + "." + v.getMinor() + "." + v.getPatch());
b.append("\n\t\tDSE Patch:\t\t" + v.getDSEPatch());
b.append("\n\t]");
return b.toString();
}