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


Java DCAwareRoundRobinPolicy类代码示例

本文整理汇总了Java中com.datastax.driver.core.policies.DCAwareRoundRobinPolicy的典型用法代码示例。如果您正苦于以下问题:Java DCAwareRoundRobinPolicy类的具体用法?Java DCAwareRoundRobinPolicy怎么用?Java DCAwareRoundRobinPolicy使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: getCluster

import com.datastax.driver.core.policies.DCAwareRoundRobinPolicy; //导入依赖的package包/类
/**
 * Get a Cassandra cluster using hosts and port.
 */
private Cluster getCluster(List<String> hosts, int port, String username, String password,
                           String localDc, String consistencyLevel) {
  Cluster.Builder builder = Cluster.builder()
      .addContactPoints(hosts.toArray(new String[0]))
      .withPort(port);

  if (username != null) {
    builder.withAuthProvider(new PlainTextAuthProvider(username, password));
  }

  if (localDc != null) {
    builder.withLoadBalancingPolicy(
        new TokenAwarePolicy(new DCAwareRoundRobinPolicy.Builder().withLocalDc(localDc).build()));
  } else {
    builder.withLoadBalancingPolicy(new TokenAwarePolicy(new RoundRobinPolicy()));
  }

  if (consistencyLevel != null) {
    builder.withQueryOptions(
        new QueryOptions().setConsistencyLevel(ConsistencyLevel.valueOf(consistencyLevel)));
  }

  return builder.build();
}
 
开发者ID:apache,项目名称:beam,代码行数:28,代码来源:CassandraServiceImpl.java

示例2: startComponent

import com.datastax.driver.core.policies.DCAwareRoundRobinPolicy; //导入依赖的package包/类
@Override
public void startComponent() {
  if (cluster == null) {
    // Configure and build up the Cassandra cluster.
    cluster = Cluster.builder()
            .withClusterName(clusterName)
            .withPort(port)
            .withRetryPolicy(DefaultRetryPolicy.INSTANCE)
            // TokenAware requires query has routing info (e.g. BoundStatement with all PK value bound).
            .withLoadBalancingPolicy(new TokenAwarePolicy(DCAwareRoundRobinPolicy.builder().build()))
            .addContactPoints(contactPoints.toArray(new String[contactPoints.size()]))
            .build();

    // Register any codecs.
    cluster.getConfiguration().getCodecRegistry()
            .register(new CassandraEnumCodec<>(AccessMode.class, AccessMode.getValueMap()))
            .register(new CassandraEnumCodec<>(Direction.class, Direction.getValueMap()))
            .register(new CassandraEnumCodec<>(SourceEntity.Type.class, SourceEntity.Type.getValueMap()));

    // Create a session.
    manager = new MappingManager(cluster.connect());
  }
}
 
开发者ID:mnemonic-no,项目名称:act-platform,代码行数:24,代码来源:ClusterManager.java

示例3: connect

import com.datastax.driver.core.policies.DCAwareRoundRobinPolicy; //导入依赖的package包/类
static Session connect() {
	String contactPoint = "localhost";
	String keySpace = "ks1";
	
	if(session == null) {
		
		DCAwareRoundRobinPolicy dcAwarePolicy = new DCAwareRoundRobinPolicy.Builder().build();
		LoadBalancingPolicy policy = new TokenAwarePolicy(dcAwarePolicy);
		
		cluster = Cluster.builder().addContactPoint(contactPoint)
				.withLoadBalancingPolicy(policy).build();
		cluster.init();
		for (Host host : cluster.getMetadata().getAllHosts()) {
			System.out.printf("Address: %s, Rack: %s, Datacenter: %s, Tokens: %s\n", host.getAddress(),
					host.getDatacenter(), host.getRack(), host.getTokens());
		}
	}
	return session;
}
 
开发者ID:abulbasar,项目名称:cassandra-java-driver-examples,代码行数:20,代码来源:LoadBalancingPolicyExample.java

示例4: setup

import com.datastax.driver.core.policies.DCAwareRoundRobinPolicy; //导入依赖的package包/类
private void setup()
throws IOException, KeyStoreException, NoSuchAlgorithmException, KeyManagementException,
              CertificateException, UnrecoverableKeyException  {
// Connect to Cassandra
Cluster.Builder clusterBuilder = Cluster.builder()
    .addContactPoint(host)
    .withPort(port)
    .withLoadBalancingPolicy(new TokenAwarePolicy(DCAwareRoundRobinPolicy.builder().build()));
if (null != username)
    clusterBuilder = clusterBuilder.withCredentials(username, password);
       if (null != truststorePath)
           clusterBuilder = clusterBuilder.withSSL(createSSLOptions());

cluster = clusterBuilder.build();
       if (null == cluster) {
           throw new IOException("Could not create cluster");
       }
session = cluster.connect();
   }
 
开发者ID:brianmhess,项目名称:cassandra-count,代码行数:20,代码来源:CqlCount.java

示例5: buildCluster

import com.datastax.driver.core.policies.DCAwareRoundRobinPolicy; //导入依赖的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();
}
 
开发者ID:liaominghua,项目名称:zipkin,代码行数:22,代码来源:DefaultSessionFactory.java

示例6: buildCluster

import com.datastax.driver.core.policies.DCAwareRoundRobinPolicy; //导入依赖的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();
}
 
开发者ID:liaominghua,项目名称:zipkin,代码行数:22,代码来源:SessionFactory.java

示例7: GenericRepair

import com.datastax.driver.core.policies.DCAwareRoundRobinPolicy; //导入依赖的package包/类
public GenericRepair(String inputFile) throws IOException {
    properties =  new HashMap<String, String>();
    loadProperties(inputFile);
    cluster = Cluster.builder()
            .addContactPoint(properties.get("contact_point"))
            .withQueryOptions(new QueryOptions().setFetchSize(Integer.parseInt(properties.get("fetch_size"))))
            .withCredentials(properties.get("username"), properties.get("password"))
            .withSocketOptions(new SocketOptions().setConnectTimeoutMillis(1000000).setReadTimeoutMillis(1000000))
            .withLoadBalancingPolicy(DCAwareRoundRobinPolicy.builder().withLocalDc(properties.get("local_dc"))
                    .build()).build();
    session = cluster.connect();
    scanConsistencyLevel = ConsistencyLevel.valueOf(properties.get("scan_consistency"));
    fetchConsistencyLevel = ConsistencyLevel.ALL;
    this.keyspace = properties.get("keyspace");
    this.tableName = properties.get("table_name");
    this.partitionKey = getPartitionKey();
    this.individualFetchStatement = initializeIndividualFetchStatement();
    this.partitionKeyColumnsToDataTypeName = new DataType.Name[partitionKey.split(",").length];
    queue = new LinkedBlockingQueue<>(Integer.parseInt(properties.get("queue_size")));
    sleepForFailedFetchStatement = Integer.parseInt(properties.get("sleep_millisconds"));
    boundStatement = new BoundStatement(session.prepare("select distinct "+partitionKey+" from "+keyspace+"."+tableName));;
}
 
开发者ID:siddv29,项目名称:eleventh-hour-repair,代码行数:23,代码来源:GenericRepair.java

示例8: setup

import com.datastax.driver.core.policies.DCAwareRoundRobinPolicy; //导入依赖的package包/类
private void setup()
    throws IOException, KeyStoreException, NoSuchAlgorithmException, KeyManagementException,
           CertificateException, UnrecoverableKeyException  {
    // Connect to Cassandra
    PoolingOptions pOpts = new PoolingOptions();
    pOpts.setCoreConnectionsPerHost(HostDistance.LOCAL, 4);
    pOpts.setMaxConnectionsPerHost(HostDistance.LOCAL, 4);
    Cluster.Builder clusterBuilder = Cluster.builder()
        .addContactPoint(host)
        .withPort(port)
        .withPoolingOptions(pOpts)
        .withLoadBalancingPolicy(new TokenAwarePolicy( DCAwareRoundRobinPolicy.builder().build()));
    if (null != username)
        clusterBuilder = clusterBuilder.withCredentials(username, password);
    if (null != truststorePath)
        clusterBuilder = clusterBuilder.withSSL(createSSLOptions());

    cluster = clusterBuilder.build();
    if (null == cluster) {
        throw new IOException("Could not create cluster");
    }
    session = cluster.connect();
}
 
开发者ID:brianmhess,项目名称:cassandra-loader,代码行数:24,代码来源:CqlDelimUnload.java

示例9: createCache

import com.datastax.driver.core.policies.DCAwareRoundRobinPolicy; //导入依赖的package包/类
protected void createCache(Map<String, String> mapParams) throws Exception {
    final Cluster.Builder bluePrint = Cluster.builder().withClusterName("BluePrint")
            .withQueryOptions(new QueryOptions().setConsistencyLevel(ConsistencyLevel.LOCAL_QUORUM))
            .withRetryPolicy(DefaultRetryPolicy.INSTANCE)
            .withLoadBalancingPolicy(new TokenAwarePolicy(new DCAwareRoundRobinPolicy()))
            .addContactPoint(mapParams.get("cassandra.server.ip.address")).withPort(9042);

    cache1 = mache(String.class, CassandraTestEntity.class)
            .cachedBy(guava())
            .storedIn(cassandra()
                    .withCluster(bluePrint)
                    .withKeyspace(mapParams.get("keyspace.name"))
                    .withSchemaOptions(SchemaOptions.CREATE_SCHEMA_IF_NEEDED)
                    .build())
            .withMessaging(kafka()
                    .withKafkaMqConfig(KafkaMqConfigBuilder.builder()
                            .withZkHost(mapParams.get("kafka.connection"))
                            .build())
                    .withTopic(mapParams.get("kafka.topic"))
                    .build())
            .macheUp();
}
 
开发者ID:Excelian,项目名称:Mache,代码行数:23,代码来源:MacheAbstractCassandraKafkaSamplerClient.java

示例10: build

import com.datastax.driver.core.policies.DCAwareRoundRobinPolicy; //导入依赖的package包/类
@Override
public LoadBalancingPolicy build() {
    DCAwareRoundRobinPolicy.Builder builder = DCAwareRoundRobinPolicy.builder();

    if (allowRemoteDCsForLocalConsistencyLevel == Boolean.TRUE) {
        builder.allowRemoteDCsForLocalConsistencyLevel();
    }

    if (localDC != null) {
        builder.withLocalDc(localDC);
    }

    if (usedHostsPerRemoteDC != null) {
        builder.withUsedHostsPerRemoteDc(usedHostsPerRemoteDC);
    }

    return builder.build();
}
 
开发者ID:composable-systems,项目名称:dropwizard-cassandra,代码行数:19,代码来源:DCAwareRoundRobinPolicyFactory.java

示例11: main

import com.datastax.driver.core.policies.DCAwareRoundRobinPolicy; //导入依赖的package包/类
public static void main(String[] args){
    Cluster cluster;
    Session session;
    cluster = Cluster
            .builder()
            .addContactPoint("127.0.0.1")
            .withRetryPolicy(DefaultRetryPolicy.INSTANCE) //Other option: DowngradingConsistencyRetryPolicy
            .withLoadBalancingPolicy(new TokenAwarePolicy(DCAwareRoundRobinPolicy.builder().build()))
            .build();
    session = cluster.connect("demo");


    PreparedStatement statement = session.prepare("INSERT INTO user (id, name) VALUES (?, ?)");
    Statement boundStatement = statement
            .bind(1, "user 1")
            .enableTracing();

    long startTime = System.currentTimeMillis();
    ResultSet resultSet = session.execute(boundStatement);
    long duration = System.currentTimeMillis() - startTime;
    System.out.format("Time taken: %d", duration);

    ExecutionInfo executionInfo = resultSet.getExecutionInfo();
    printQueryTrace(executionInfo.getQueryTrace());
    cluster.close();

}
 
开发者ID:abulbasar,项目名称:cassandra-java-driver-examples,代码行数:28,代码来源:TracingExample.java

示例12: loadBalancing_settingLocalDcIgnoresOtherDatacenters

import com.datastax.driver.core.policies.DCAwareRoundRobinPolicy; //导入依赖的package包/类
@Test
public void loadBalancing_settingLocalDcIgnoresOtherDatacenters() {
  DCAwareRoundRobinPolicy policy = toDCAwareRoundRobinPolicy(
      Cassandra3Storage.builder().localDc("bar").build());

  Host foo = mock(Host.class);
  when(foo.getDatacenter()).thenReturn("foo");
  Host bar = mock(Host.class);
  when(bar.getDatacenter()).thenReturn("bar");
  policy.init(mock(Cluster.class), asList(foo, bar));

  assertThat(policy.distance(foo)).isEqualTo(HostDistance.IGNORED);
  assertThat(policy.distance(bar)).isEqualTo(HostDistance.LOCAL);
}
 
开发者ID:liaominghua,项目名称:zipkin,代码行数:15,代码来源:SessionFactoryTest.java

示例13: toDCAwareRoundRobinPolicy

import com.datastax.driver.core.policies.DCAwareRoundRobinPolicy; //导入依赖的package包/类
DCAwareRoundRobinPolicy toDCAwareRoundRobinPolicy(Cassandra3Storage storage) {
  return (DCAwareRoundRobinPolicy) ((LatencyAwarePolicy) ((TokenAwarePolicy) buildCluster(storage)
      .getConfiguration()
      .getPolicies()
      .getLoadBalancingPolicy())
      .getChildPolicy()).getChildPolicy();
}
 
开发者ID:liaominghua,项目名称:zipkin,代码行数:8,代码来源:SessionFactoryTest.java

示例14: loadBalancing_settingLocalDcIgnoresOtherDatacenters

import com.datastax.driver.core.policies.DCAwareRoundRobinPolicy; //导入依赖的package包/类
@Test
public void loadBalancing_settingLocalDcIgnoresOtherDatacenters() {
  DCAwareRoundRobinPolicy policy = toDCAwareRoundRobinPolicy(
      CassandraStorage.builder().localDc("bar").build());

  Host foo = mock(Host.class);
  when(foo.getDatacenter()).thenReturn("foo");
  Host bar = mock(Host.class);
  when(bar.getDatacenter()).thenReturn("bar");
  policy.init(mock(Cluster.class), asList(foo, bar));

  assertThat(policy.distance(foo)).isEqualTo(HostDistance.IGNORED);
  assertThat(policy.distance(bar)).isEqualTo(HostDistance.LOCAL);
}
 
开发者ID:liaominghua,项目名称:zipkin,代码行数:15,代码来源:SessionFactoryTest.java

示例15: toDCAwareRoundRobinPolicy

import com.datastax.driver.core.policies.DCAwareRoundRobinPolicy; //导入依赖的package包/类
DCAwareRoundRobinPolicy toDCAwareRoundRobinPolicy(CassandraStorage storage) {
  return (DCAwareRoundRobinPolicy) ((LatencyAwarePolicy) ((TokenAwarePolicy) buildCluster(storage)
      .getConfiguration()
      .getPolicies()
      .getLoadBalancingPolicy())
      .getChildPolicy()).getChildPolicy();
}
 
开发者ID:liaominghua,项目名称:zipkin,代码行数:8,代码来源:SessionFactoryTest.java


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