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


Java RoundRobinPolicy类代码示例

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


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

示例1: getCluster

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

import com.datastax.driver.core.policies.RoundRobinPolicy; //导入依赖的package包/类
public CassandraConfigDb(List<String> contactPoints, int port) {
	
	this.contactPoints = new ArrayList<InetAddress> (contactPoints.size());
	
	for (String contactPoint : contactPoints) {
		try {
			this.contactPoints.add(InetAddress.getByName(contactPoint));
		} catch (UnknownHostException e) {
               throw new IllegalArgumentException(e.getMessage());
		}
	}
	
	this.port = port;
	
	cluster = (new Cluster.Builder()).withPort (this.port)
			.addContactPoints(this.contactPoints)
			.withSocketOptions(new SocketOptions().setReadTimeoutMillis(60000).setKeepAlive(true).setReuseAddress(true))
			.withLoadBalancingPolicy(new RoundRobinPolicy())
			.withReconnectionPolicy(new ConstantReconnectionPolicy(500L))
			.withQueryOptions(new QueryOptions().setConsistencyLevel(ConsistencyLevel.ONE))
			.build ();
	
	session = cluster.newSession();
	preparedStatements = new ConcurrentHashMap<StatementName, PreparedStatement> ();
	prepareStatementCreateLock = new Object();
}
 
开发者ID:att,项目名称:dmaap-framework,代码行数:27,代码来源:CassandraConfigDb.java

示例3: buildCluster

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

示例4: buildCluster

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

示例5: connect

import com.datastax.driver.core.policies.RoundRobinPolicy; //导入依赖的package包/类
/**
 * Connect to a cassandra cluster at a given host/port
 */
public void connect() {
    try {
        lock.lock();
    } catch (IOException e) {
        throw new IllegalStateException("There appears to be another health check running", e);
    }
    final List<InetSocketAddress> whiteList= new ArrayList<>();
    whiteList.add(new InetSocketAddress(host, port));

    final LoadBalancingPolicy loadBalancingPolicy = new WhiteListPolicy(new RoundRobinPolicy(), whiteList);
    final Cluster.Builder cb = Cluster.builder()
            .addContactPoint(host)
            .withPort(port)
            .withLoadBalancingPolicy(loadBalancingPolicy)
            .withRetryPolicy(retryPolicy);
    if (username != null) {
        cb.withCredentials(username, password);
    }
    cluster = cb.build();
    session = cluster.connect();
    hosts = cluster.getMetadata().getAllHosts();
}
 
开发者ID:lookout,项目名称:cassandra-health-check,代码行数:26,代码来源:CassandraHealthCheck.java

示例6: cluster

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

示例7: cassandraSessionWithConfiguration

import com.datastax.driver.core.policies.RoundRobinPolicy; //导入依赖的package包/类
@Test
public void cassandraSessionWithConfiguration() throws Exception {
	ApplicationContext testContext = getTestApplicationContext(
			"cloud-cassandra-with-config.xml", createService("my-service"));
	Cluster cluster = testContext.getBean("cassandra-full-config",
			getConnectorType());

	assertNotNull(cluster.getConfiguration().getSocketOptions());
	assertEquals(15000,
			cluster.getConfiguration().getSocketOptions().getConnectTimeoutMillis());
	assertTrue(DefaultRetryPolicy.class.isAssignableFrom(
			cluster.getConfiguration().getPolicies().getRetryPolicy().getClass()));
	assertTrue(RoundRobinPolicy.class.isAssignableFrom(cluster.getConfiguration()
			.getPolicies().getLoadBalancingPolicy().getClass()));
	assertTrue(ConstantReconnectionPolicy.class.isAssignableFrom(cluster
			.getConfiguration().getPolicies().getReconnectionPolicy().getClass()));
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-connectors,代码行数:18,代码来源:CassandraClusterXmlConfigTest.java

示例8: connect

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

示例9: createDataSource

import com.datastax.driver.core.policies.RoundRobinPolicy; //导入依赖的package包/类
@Bean("cassandraDataSource")
@Primary
public DataSource createDataSource() {
    DataSource dataSource = new DataSource();
    dataSource.setContactPoints("127.0.0.1");
    dataSource.setPort(9042);
    dataSource.setReadConsistency(ConsistencyLevel.ONE.name());
    dataSource.setWriteConsistency(ConsistencyLevel.ONE.name());
    dataSource.setLoadBalancingPolicy(new RoundRobinPolicy());
    return dataSource;
}
 
开发者ID:kloiasoft,项目名称:eventapis,代码行数:12,代码来源:StoreConfiguration.java

示例10: loadBalancing_defaultsToRoundRobin

import com.datastax.driver.core.policies.RoundRobinPolicy; //导入依赖的package包/类
@Test
public void loadBalancing_defaultsToRoundRobin() {
  RoundRobinPolicy policy = toRoundRobinPolicy(Cassandra3Storage.builder().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.LOCAL);
  assertThat(policy.distance(bar)).isEqualTo(HostDistance.LOCAL);
}
 
开发者ID:liaominghua,项目名称:zipkin,代码行数:14,代码来源:SessionFactoryTest.java

示例11: toRoundRobinPolicy

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

示例12: loadBalancing_defaultsToRoundRobin

import com.datastax.driver.core.policies.RoundRobinPolicy; //导入依赖的package包/类
@Test
public void loadBalancing_defaultsToRoundRobin() {
  RoundRobinPolicy policy = toRoundRobinPolicy(CassandraStorage.builder().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.LOCAL);
  assertThat(policy.distance(bar)).isEqualTo(HostDistance.LOCAL);
}
 
开发者ID:liaominghua,项目名称:zipkin,代码行数:14,代码来源:SessionFactoryTest.java

示例13: toRoundRobinPolicy

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

示例14: construct

import com.datastax.driver.core.policies.RoundRobinPolicy; //导入依赖的package包/类
public AsyncFuture<Connection> construct() {
    AsyncFuture<Session> session = async.call(() -> {
        // @formatter:off
        final PoolingOptions pooling = new PoolingOptions();

        final QueryOptions queryOptions = new QueryOptions()
            .setFetchSize(fetchSize)
            .setConsistencyLevel(consistencyLevel);

        final SocketOptions socketOptions = new SocketOptions()
            .setReadTimeoutMillis((int) readTimeout.toMilliseconds());

        final Cluster.Builder cluster = Cluster.builder()
            .addContactPointsWithPorts(seeds)
            .withRetryPolicy(retryPolicy)
            .withPoolingOptions(pooling)
            .withQueryOptions(queryOptions)
            .withSocketOptions(socketOptions)
            .withLoadBalancingPolicy(new TokenAwarePolicy(new RoundRobinPolicy()));
        // @formatter:on

        authentication.accept(cluster);
        return cluster.build().connect();
    });

    if (configure) {
        session = session.lazyTransform(s -> {
            return schema.configure(s).directTransform(i -> s);
        });
    }

    return session.lazyTransform(s -> {
        return schema.instance(s).directTransform(schema -> {
            return new Connection(s, schema);
        });
    });
}
 
开发者ID:spotify,项目名称:heroic,代码行数:38,代码来源:ManagedSetupConnection.java

示例15: testLoadBalancingPolicyParsing

import com.datastax.driver.core.policies.RoundRobinPolicy; //导入依赖的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("====================");    	    	
	
}
 
开发者ID:adejanovski,项目名称:cassandra-jdbc-wrapper,代码行数:30,代码来源:UtilsUnitTest.java


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