本文整理汇总了Java中com.datastax.driver.core.policies.LatencyAwarePolicy类的典型用法代码示例。如果您正苦于以下问题:Java LatencyAwarePolicy类的具体用法?Java LatencyAwarePolicy怎么用?Java LatencyAwarePolicy使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
LatencyAwarePolicy类属于com.datastax.driver.core.policies包,在下文中一共展示了LatencyAwarePolicy类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: buildCluster
import com.datastax.driver.core.policies.LatencyAwarePolicy; //导入依赖的package包/类
static Cluster buildCluster(Cassandra3Storage cassandra) {
Cluster.Builder builder = Cluster.builder();
List<InetSocketAddress> contactPoints = parseContactPoints(cassandra);
int defaultPort = findConnectPort(contactPoints);
builder.addContactPointsWithPorts(contactPoints);
builder.withPort(defaultPort); // This ends up protocolOptions.port
if (cassandra.username != null && cassandra.password != null) {
builder.withCredentials(cassandra.username, cassandra.password);
}
builder.withRetryPolicy(ZipkinRetryPolicy.INSTANCE);
builder.withLoadBalancingPolicy(new TokenAwarePolicy(new LatencyAwarePolicy.Builder(
cassandra.localDc != null
? DCAwareRoundRobinPolicy.builder().withLocalDc(cassandra.localDc).build()
: new RoundRobinPolicy()
// This can select remote, but LatencyAwarePolicy will prefer local
).build()));
builder.withPoolingOptions(new PoolingOptions().setMaxConnectionsPerHost(
HostDistance.LOCAL, cassandra.maxConnections
));
return builder.build();
}
示例2: buildCluster
import com.datastax.driver.core.policies.LatencyAwarePolicy; //导入依赖的package包/类
static Cluster buildCluster(CassandraStorage cassandra) {
Cluster.Builder builder = Cluster.builder();
List<InetSocketAddress> contactPoints = parseContactPoints(cassandra);
int defaultPort = findConnectPort(contactPoints);
builder.addContactPointsWithPorts(contactPoints);
builder.withPort(defaultPort); // This ends up protocolOptions.port
if (cassandra.username != null && cassandra.password != null) {
builder.withCredentials(cassandra.username, cassandra.password);
}
builder.withRetryPolicy(ZipkinRetryPolicy.INSTANCE);
builder.withLoadBalancingPolicy(new TokenAwarePolicy(new LatencyAwarePolicy.Builder(
cassandra.localDc != null
? DCAwareRoundRobinPolicy.builder().withLocalDc(cassandra.localDc).build()
: new RoundRobinPolicy()
// This can select remote, but LatencyAwarePolicy will prefer local
).build()));
builder.withPoolingOptions(new PoolingOptions().setMaxConnectionsPerHost(
HostDistance.LOCAL, cassandra.maxConnections
));
return builder.build();
}
示例3: build
import com.datastax.driver.core.policies.LatencyAwarePolicy; //导入依赖的package包/类
@Override
public LoadBalancingPolicy build() {
LatencyAwarePolicy.Builder builder = LatencyAwarePolicy.builder(subPolicy.build());
if (exclusionThreshold != null) {
builder.withExclusionThreshold(exclusionThreshold);
}
if (minimumMeasurements != null) {
builder.withMininumMeasurements(minimumMeasurements);
}
if (retryPeriod != null) {
builder.withRetryPeriod(retryPeriod.getQuantity(), retryPeriod.getUnit());
}
if (scale != null) {
builder.withScale(scale.getQuantity(), scale.getUnit());
}
if (updateRate != null) {
builder.withUpdateRate(updateRate.getQuantity(), updateRate.getUnit());
}
return builder.build();
}
示例4: toRoundRobinPolicy
import com.datastax.driver.core.policies.LatencyAwarePolicy; //导入依赖的package包/类
RoundRobinPolicy toRoundRobinPolicy(Cassandra3Storage storage) {
return (RoundRobinPolicy) ((LatencyAwarePolicy) ((TokenAwarePolicy) buildCluster(storage)
.getConfiguration()
.getPolicies()
.getLoadBalancingPolicy())
.getChildPolicy()).getChildPolicy();
}
示例5: toDCAwareRoundRobinPolicy
import com.datastax.driver.core.policies.LatencyAwarePolicy; //导入依赖的package包/类
DCAwareRoundRobinPolicy toDCAwareRoundRobinPolicy(Cassandra3Storage storage) {
return (DCAwareRoundRobinPolicy) ((LatencyAwarePolicy) ((TokenAwarePolicy) buildCluster(storage)
.getConfiguration()
.getPolicies()
.getLoadBalancingPolicy())
.getChildPolicy()).getChildPolicy();
}
示例6: toRoundRobinPolicy
import com.datastax.driver.core.policies.LatencyAwarePolicy; //导入依赖的package包/类
RoundRobinPolicy toRoundRobinPolicy(CassandraStorage storage) {
return (RoundRobinPolicy) ((LatencyAwarePolicy) ((TokenAwarePolicy) buildCluster(storage)
.getConfiguration()
.getPolicies()
.getLoadBalancingPolicy())
.getChildPolicy()).getChildPolicy();
}
示例7: toDCAwareRoundRobinPolicy
import com.datastax.driver.core.policies.LatencyAwarePolicy; //导入依赖的package包/类
DCAwareRoundRobinPolicy toDCAwareRoundRobinPolicy(CassandraStorage storage) {
return (DCAwareRoundRobinPolicy) ((LatencyAwarePolicy) ((TokenAwarePolicy) buildCluster(storage)
.getConfiguration()
.getPolicies()
.getLoadBalancingPolicy())
.getChildPolicy()).getChildPolicy();
}
示例8: testLoadBalancingPolicyParsing
import com.datastax.driver.core.policies.LatencyAwarePolicy; //导入依赖的package包/类
@Test
public void testLoadBalancingPolicyParsing() throws Exception
{
String lbPolicyStr = "RoundRobinPolicy()";
System.out.println(lbPolicyStr);
assertTrue(Utils.parseLbPolicy(lbPolicyStr) instanceof RoundRobinPolicy);
System.out.println("====================");
lbPolicyStr = "TokenAwarePolicy(RoundRobinPolicy())";
System.out.println(lbPolicyStr);
assertTrue(Utils.parseLbPolicy(lbPolicyStr) instanceof TokenAwarePolicy);
System.out.println("====================");
lbPolicyStr = "DCAwareRoundRobinPolicy(\"dc1\")";
System.out.println(lbPolicyStr);
assertTrue(Utils.parseLbPolicy(lbPolicyStr) instanceof DCAwareRoundRobinPolicy);
System.out.println("====================");
lbPolicyStr = "TokenAwarePolicy(DCAwareRoundRobinPolicy(\"dc1\"))";
System.out.println(lbPolicyStr);
assertTrue(Utils.parseLbPolicy(lbPolicyStr) instanceof TokenAwarePolicy);
System.out.println("====================");
lbPolicyStr = "TokenAwarePolicy";
System.out.println(lbPolicyStr);
assertTrue(Utils.parseLbPolicy(lbPolicyStr)==null);
System.out.println("====================");
lbPolicyStr = "LatencyAwarePolicy(TokenAwarePolicy(RoundRobinPolicy()),(double) 10.5,(long) 1,(long) 10,(long)1,10)";
System.out.println(lbPolicyStr);
assertTrue(Utils.parseLbPolicy(lbPolicyStr) instanceof LatencyAwarePolicy);
System.out.println("====================");
}
示例9: setUp
import com.datastax.driver.core.policies.LatencyAwarePolicy; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
when(subPolicyFactory.build()).thenReturn(subPolicy);
mockStatic(LatencyAwarePolicy.class);
when(LatencyAwarePolicy.builder(subPolicy)).thenReturn(policyBuilder);
when(policyBuilder.build()).thenReturn(resultingPolicy);
}
示例10: build
import com.datastax.driver.core.policies.LatencyAwarePolicy; //导入依赖的package包/类
private static Cluster build(List<String> addresses, int port) {
Cluster.Builder builder = Cluster.builder();
for (String address : addresses) {
builder.addContactPoint(address);
}
builder
.withPort(port)
.withCompression(Compression.LZ4)
.withRetryPolicy(DowngradingConsistencyRetryPolicy.INSTANCE)
.withLoadBalancingPolicy(LatencyAwarePolicy.builder(new RoundRobinPolicy()).build());
Cluster cluster = builder.build();
try {
// Attempt to init the cluster to make sure it's usable. I'd prefer to remove this and leave it on the
// client to retry when the connect method throws an exception.
cluster.init();
return cluster;
} catch(NoHostAvailableException e) {
LOGGER.warn("Unable to connect to Cassandra, will retry contact points next time",
cluster, e);
cluster = builder.build();
cluster.init();
}
return cluster;
}