當前位置: 首頁>>代碼示例>>Java>>正文


Java Cluster.Builder方法代碼示例

本文整理匯總了Java中com.datastax.driver.core.Cluster.Builder方法的典型用法代碼示例。如果您正苦於以下問題:Java Cluster.Builder方法的具體用法?Java Cluster.Builder怎麽用?Java Cluster.Builder使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.datastax.driver.core.Cluster的用法示例。


在下文中一共展示了Cluster.Builder方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getCluster

import com.datastax.driver.core.Cluster; //導入方法依賴的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: getClientSession

import com.datastax.driver.core.Cluster; //導入方法依賴的package包/類
public static Session getClientSession(String hostAddr) {
    if(REGISTRY.containsKey(hostAddr)) {
        return REGISTRY.get(hostAddr);
    } else {
        Cluster.Builder clientClusterBuilder = new Cluster.Builder()
                .addContactPoint(hostAddr)
                .withQueryOptions(new QueryOptions()
                        .setConsistencyLevel(ConsistencyLevel.ONE)
                        .setSerialConsistencyLevel(ConsistencyLevel.LOCAL_SERIAL))
                .withoutJMXReporting()
                .withoutMetrics()
                .withReconnectionPolicy(new ConstantReconnectionPolicy(RECONNECT_DELAY_IN_MS));
        long startTimeInMillis = System.currentTimeMillis();
        Cluster clientCluster = clientClusterBuilder.build();
        Session clientSession = clientCluster.connect();

        LOG.info("Client session established after {} ms.", System.currentTimeMillis() - startTimeInMillis);
        REGISTRY.putIfAbsent(hostAddr, clientSession);
        return clientSession;
    }
}
 
開發者ID:mcfongtw,項目名稱:flink-cassandra-connector-examples,代碼行數:22,代碼來源:ClientSessionProvider.java

示例3: adminSession

import com.datastax.driver.core.Cluster; //導入方法依賴的package包/類
/** */
private static synchronized Session adminSession() {
    if (adminSes != null) {
        return adminSes;
    }
    try {
        Cluster.Builder builder = Cluster.builder();
        builder = builder.withCredentials(getAdminUser(), getAdminPassword());
        builder.addContactPoints(getContactPoints());
        builder.addContactPointsWithPorts(getContactPointsWithPorts());
        adminCluster = builder.build();
        return adminSes = adminCluster.connect();
    }
    catch (Throwable e) {
        throw new RuntimeException("Failed to create admin session to Cassandra database", e);
    }
}
 
開發者ID:epam,項目名稱:Lagerta,代碼行數:18,代碼來源:CassandraHelper.java

示例4: regularSession

import com.datastax.driver.core.Cluster; //導入方法依賴的package包/類
/** */
private static synchronized Session regularSession() {
    if (regularSes != null) {
        return regularSes;
    }
    try {
        Cluster.Builder builder = Cluster.builder();
        builder = builder.withCredentials(getRegularUser(), getRegularPassword());
        builder.addContactPoints(getContactPoints());
        builder.addContactPointsWithPorts(getContactPointsWithPorts());
        regularCluster = builder.build();
        return regularSes = regularCluster.connect();
    }
    catch (Throwable e) {
        throw new RuntimeException("Failed to create regular session to Cassandra database", e);
    }
}
 
開發者ID:epam,項目名稱:Lagerta,代碼行數:18,代碼來源:CassandraHelper.java

示例5: setup

import com.datastax.driver.core.Cluster; //導入方法依賴的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

示例6: init

import com.datastax.driver.core.Cluster; //導入方法依賴的package包/類
public void init(Class<T> tClass) {
    try {
        Cluster.Builder builder = Cluster.builder();
        final String[] nodesList = nodes.split(",");
        for (String node : nodesList) {
            builder.addContactPoint(node).withPort(Integer.parseInt(port));
            LOGGER.info(String.format("Added cassandra node : %s", node + ":" + port));
        }
        cluster = builder.build();
        session = null;
        if (keyspace != null) {
            session = cluster.connect(keyspace);
        } else {
            session = cluster.connect();
        }
        MappingManager mappingManager = new MappingManager(session);
        mapper = mappingManager.mapper(tClass);
    } catch (Exception e) {
        LOGGER.error("Error initializing CassandraDao");
        throw e;
    }
}
 
開發者ID:echauchot,項目名稱:bigDataRocks,代碼行數:23,代碼來源:ACassandraDao.java

示例7: buildCluster

import com.datastax.driver.core.Cluster; //導入方法依賴的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

示例8: buildCluster

import com.datastax.driver.core.Cluster; //導入方法依賴的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

示例9: getClusterBuilderConfigurer

import com.datastax.driver.core.Cluster; //導入方法依賴的package包/類
@Override
protected ClusterBuilderConfigurer getClusterBuilderConfigurer() {
	return new ClusterBuilderConfigurer() {

		@Override
		public Cluster.Builder configure(Cluster.Builder clusterBuilder) {
			if (CassandraConfiguration.this.cassandraProperties.isUseSsl()) {
				JdkSSLOptions.Builder optsBuilder = JdkSSLOptions.builder();
				if (CassandraConfiguration.this.cassandraProperties.isSkipSslValidation()) {
					try {
						optsBuilder.withSSLContext(TrustAllSSLContextFactory.getSslContext());
					}
					catch (NoSuchAlgorithmException | KeyManagementException e) {
						throw new RuntimeException("Unable to configure a Cassandra cluster using SSL.", e);
					}
				}
				return clusterBuilder.withSSL(optsBuilder.build());
			}
			else {
				return clusterBuilder;
			}
		}
	};
}
 
開發者ID:spring-cloud-stream-app-starters,項目名稱:cassandra,代碼行數:25,代碼來源:CassandraConfiguration.java

示例10: testHostNotFoundErrorHandling

import com.datastax.driver.core.Cluster; //導入方法依賴的package包/類
@Test(expected = NoHostAvailableException.class)
public void testHostNotFoundErrorHandling() throws Exception {
	CassandraSinkBase base = new CassandraSinkBase(new ClusterBuilder() {
		@Override
		protected Cluster buildCluster(Cluster.Builder builder) {
			return builder
				.addContactPoint("127.0.0.1")
				.withoutJMXReporting()
				.withoutMetrics().build();
		}
	}) {
		@Override
		public ListenableFuture send(Object value) {
			return null;
		}
	};

	base.open(new Configuration());
}
 
開發者ID:axbaretto,項目名稱:flink,代碼行數:20,代碼來源:CassandraSinkBaseTest.java

示例11: createClusterBuilder

import com.datastax.driver.core.Cluster; //導入方法依賴的package包/類
protected Cluster.Builder createClusterBuilder() throws Exception {
    CassandraLoadBalancingPolicies cassLoadBalancingPolicies = new CassandraLoadBalancingPolicies();
    Cluster.Builder clusterBuilder = Cluster.builder();
    for (String host : hosts.split(",")) {
        clusterBuilder = clusterBuilder.addContactPoint(host);
    }
    if (port != null) {
        clusterBuilder = clusterBuilder.withPort(port);
    }
    if (clusterName != null) {
        clusterBuilder = clusterBuilder.withClusterName(clusterName);
    }
    if (username != null && !username.isEmpty() && password != null) {
        clusterBuilder.withCredentials(username, password);
    }
    if (loadBalancingPolicy != null && !loadBalancingPolicy.isEmpty()) {
        clusterBuilder.withLoadBalancingPolicy(cassLoadBalancingPolicies.getLoadBalancingPolicy(loadBalancingPolicy));
    }
    return clusterBuilder;
}
 
開發者ID:HydAu,項目名稱:Camel,代碼行數:21,代碼來源:CassandraEndpoint.java

示例12: newSession

import com.datastax.driver.core.Cluster; //導入方法依賴的package包/類
@Override
public CassandraSession newSession(CassandraSinkConnectorConfig config) {
  Cluster.Builder clusterBuilder = Cluster.builder()
      .withPort(config.port)
      .addContactPoints(config.contactPoints)
      .withProtocolVersion(ProtocolVersion.NEWEST_SUPPORTED);
  if (config.securityEnabled) {
    clusterBuilder.withCredentials(config.username, config.password);
  }
  if (config.sslEnabled) {
    final SslContextBuilder sslContextBuilder = SslContextBuilder.forClient();
    sslContextBuilder.sslProvider(config.sslProvider);
    final SslContext context;
    try {
      context = sslContextBuilder.build();
    } catch (SSLException e) {
      throw new ConnectException(e);
    }
    final SSLOptions sslOptions = new RemoteEndpointAwareNettySSLOptions(context);
    clusterBuilder.withSSL(sslOptions);
  }
  clusterBuilder.withCompression(config.compression);
  Cluster cluster = clusterBuilder.build();
  log.info("Creating session");
  final Session session = cluster.newSession();
  return new CassandraSessionImpl(config, cluster, session);
}
 
開發者ID:jcustenborder,項目名稱:kafka-connect-cassandra,代碼行數:28,代碼來源:CassandraSessionFactoryImpl.java

示例13: provideCluster

import com.datastax.driver.core.Cluster; //導入方法依賴的package包/類
/**
 * Creates a cluster to use for connecting to Cassandra.
 *
 * @return The cluster singleton to use within the Injector
 */
@Provides
@Singleton
Cluster provideCluster() {
    final Cluster.Builder builder = Cluster.builder().withClusterName(this.name);

    // Contact points are required
    final String contactPointsString = this.configuration.get(CONTACT_POINTS_KEY);
    if (contactPointsString == null) {
        throw new IllegalArgumentException(CONTACT_POINTS_KEY + " value is missing and is required.");
    }
    final String[] contactPoints = contactPointsString.split(",");
    final ImmutableList.Builder<InetAddress> contactAddresses = ImmutableList.builder();
    for (final String contactPoint : contactPoints) {
        try {
            contactAddresses.add(InetAddress.getByName(contactPoint));
        } catch (final UnknownHostException uhe) {
            throw new IllegalArgumentException("Can't parse contact point " + contactPoint, uhe);
        }
    }
    builder.addContactPoints(contactAddresses.build());
    final String port = this.configuration.get(PORT_KEY);
    if (port != null) {
        builder.withPort(Integer.parseInt(port));
    }

    final String username = this.configuration.get(USERNAME_KEY);
    final String password = this.configuration.get(PASSWORD_KEY);
    if (username != null && password != null) {
        builder.withCredentials(username, password);
    }
    return builder.build();
}
 
開發者ID:Netflix,項目名稱:metacat,代碼行數:38,代碼來源:CassandraConnectorModule.java

示例14: dropTestKeyspace

import com.datastax.driver.core.Cluster; //導入方法依賴的package包/類
public static void dropTestKeyspace( String keyspace, String[] hosts, int port ) {

        Cluster.Builder builder = Cluster.builder();
        for ( String host : hosts ) {
            builder = builder.addContactPoint( host ).withPort( port );
        }

        final QueryOptions queryOptions = new QueryOptions().setConsistencyLevel( ConsistencyLevel.LOCAL_QUORUM );
        builder.withQueryOptions( queryOptions );
        Cluster cluster = builder.build();

        Session session = cluster.connect();
        logger.info("Dropping test keyspace: {}", keyspace);
        session.execute( "DROP KEYSPACE IF EXISTS " + keyspace );
    }
 
開發者ID:apache,項目名稱:usergrid-qakka,代碼行數:16,代碼來源:KeyspaceDropper.java

示例15: setHost

import com.datastax.driver.core.Cluster; //導入方法依賴的package包/類
/**
 * Sets the cassandra host/port to connect to.
 *
 * @param host host to connect to
 * @param port port to connect to
 * @return this builder
 */
public CassandraSinkBuilder<IN> setHost(final String host, final int port) {
	if (this.builder != null) {
		throw new IllegalArgumentException("Builder was already set. You must use either setHost() or setClusterBuilder().");
	}
	this.builder = new ClusterBuilder() {
		@Override
		protected Cluster buildCluster(Cluster.Builder builder) {
			return builder.addContactPoint(host).withPort(port).build();
		}
	};
	return this;
}
 
開發者ID:axbaretto,項目名稱:flink,代碼行數:20,代碼來源:CassandraSink.java


注:本文中的com.datastax.driver.core.Cluster.Builder方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。