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


Java TokenAwarePolicy类代码示例

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


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

示例1: getCluster

import com.datastax.driver.core.policies.TokenAwarePolicy; //导入依赖的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.TokenAwarePolicy; //导入依赖的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.TokenAwarePolicy; //导入依赖的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.TokenAwarePolicy; //导入依赖的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.TokenAwarePolicy; //导入依赖的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.TokenAwarePolicy; //导入依赖的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: setup

import com.datastax.driver.core.policies.TokenAwarePolicy; //导入依赖的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

示例8: createCache

import com.datastax.driver.core.policies.TokenAwarePolicy; //导入依赖的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

示例9: cluster

import com.datastax.driver.core.policies.TokenAwarePolicy; //导入依赖的package包/类
public Cluster cluster() {

        if (cluster != null) return cluster;
        String[] entryPoints = System.getProperty("cassandra.servers", "localhost").split(",");
        String clusterName = System.getProperty("cassandra.cluster-name", "Test Cluster");
        int port = Integer.getInteger("cassandra.port", 9042);
        log.info("Connecting the cluster {} via hosts {} with port {}", clusterName, Arrays.toString(entryPoints), port);
        Cluster.Builder builder = Cluster.builder()
                .addContactPoints(entryPoints)
                .withClusterName(clusterName)
                .withPort(port)
                .withLoadBalancingPolicy(new TokenAwarePolicy(new RoundRobinPolicy()));
        cluster = builder.build();
        return cluster;

    }
 
开发者ID:cugni,项目名称:FastCSVLoader,代码行数:17,代码来源:CqlFrameLoader.java

示例10: connect

import com.datastax.driver.core.policies.TokenAwarePolicy; //导入依赖的package包/类
/**
 * Currently we connect just once and then reuse the connection.
 * We do not bother with closing the connection.
 *
 * It is normal to use one Session per DB. The Session is thread safe.
 */
private void connect() {

    if (cluster == null) {

        log.info("Connecting to Cassandra server on " + this.dbHost + " at port " + this.dbPort);

        // allow fetching as much data as present in the DB
        QueryOptions queryOptions = new QueryOptions();
        queryOptions.setFetchSize(Integer.MAX_VALUE);
        queryOptions.setConsistencyLevel(ConsistencyLevel.ONE);

        cluster = Cluster.builder()
                         .addContactPoint(this.dbHost)
                         .withPort(this.dbPort)
                         .withLoadBalancingPolicy(new TokenAwarePolicy(new RoundRobinPolicy()))
                         .withReconnectionPolicy(new ExponentialReconnectionPolicy(500, 30000))
                         .withQueryOptions(queryOptions)
                         .withCredentials(this.dbUser, this.dbPassword)
                         .build();

    }

    if (session == null) {

        log.info("Connecting to Cassandra DB with name " + this.dbName);
        session = cluster.connect(dbName);
    }
}
 
开发者ID:Axway,项目名称:ats-framework,代码行数:35,代码来源:CassandraDbProvider.java

示例11: main

import com.datastax.driver.core.policies.TokenAwarePolicy; //导入依赖的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: toRoundRobinPolicy

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

示例13: toDCAwareRoundRobinPolicy

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

示例14: toRoundRobinPolicy

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

示例15: toDCAwareRoundRobinPolicy

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