本文整理汇总了Java中com.datastax.driver.core.ProtocolOptions类的典型用法代码示例。如果您正苦于以下问题:Java ProtocolOptions类的具体用法?Java ProtocolOptions怎么用?Java ProtocolOptions使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ProtocolOptions类属于com.datastax.driver.core包,在下文中一共展示了ProtocolOptions类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: configureHosts
import com.datastax.driver.core.ProtocolOptions; //导入依赖的package包/类
private void configureHosts() {
final String hostConfiguration = (String) configuration.get(TRIDENT_CASSANDRA_CQL_HOSTS);
final String[] hosts = hostConfiguration.split(",");
final List<InetSocketAddress> sockets = new ArrayList<InetSocketAddress>();
for (final String host : hosts) {
if(StringUtils.contains(host, ":")) {
final String hostParts [] = StringUtils.split(host, ":");
sockets.add(new InetSocketAddress(hostParts[0], Integer.valueOf(hostParts[1])));
LOG.debug("Configuring [" + host + "] with port [" + hostParts[1] + "]");
} else {
sockets.add(new InetSocketAddress(host, ProtocolOptions.DEFAULT_PORT));
LOG.debug("Configuring [" + host + "] with port [" + ProtocolOptions.DEFAULT_PORT + "]");
}
}
builder = builder.addContactPointsWithPorts(sockets);
}
示例2: testSaveToCassandra
import com.datastax.driver.core.ProtocolOptions; //导入依赖的package包/类
@Test
public void testSaveToCassandra() throws Exception {
LOGGER.debug("Connecting to Cassandra Quorum: " + conf.getStringList("cassandra.hosts").toString());
SaveToCassandraActionExecutionFunction func = new SaveToCassandraActionExecutionFunction(
getHostsStringFromList(conf.getStringList("cassandra.hosts")), ProtocolOptions.DEFAULT_PORT, 50, BatchStatement.Type.UNLOGGED);
List<StratioStreamingMessage> list = new ArrayList<StratioStreamingMessage>();
message.setColumns(StreamsHelper.COLUMNS3);
list.add(message);
Exception ex = null;
try {
func.process(list);
} catch (Exception e) {
ex = e;
ex.printStackTrace();
}
assertNull("Expected null value", ex);
}
示例3: setCompression
import com.datastax.driver.core.ProtocolOptions; //导入依赖的package包/类
/**
* Sets compression algorithm to use for the transport.
*
* @param compression Compression algorithm.
*/
@SuppressWarnings("UnusedDeclaration")
public void setCompression(String compression) {
this.compression = compression == null || compression.trim().isEmpty() ? null : compression.trim();
try {
if (this.compression != null) {
ProtocolOptions.Compression.valueOf(this.compression);
}
}
catch (Throwable e) {
throw new IgniteException("Incorrect compression '" + compression + "' specified for Cassandra connection", e);
}
invalidate();
}
示例4: CassandraConfiguration
import com.datastax.driver.core.ProtocolOptions; //导入依赖的package包/类
protected CassandraConfiguration() {
try {
seed = JavaConversions.asScalaBuffer(Arrays.asList(InetAddress.getByName("localhost")));
} catch (UnknownHostException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
CassandraCluster cc = new CassandraCluster(seed, 9042,null, 8000, 120000, 1000,6000,
new ProtocolOptions().getCompression().LZ4, ConsistencyLevel.ONE);
session = cc.session();
}
示例5: getInputCluster
import com.datastax.driver.core.ProtocolOptions; //导入依赖的package包/类
public static Cluster getInputCluster(String[] hosts, Configuration conf)
{
int port = getInputNativePort(conf);
Optional<AuthProvider> authProvider = getAuthProvider(conf);
Optional<SSLOptions> sslOptions = getSSLOptions(conf);
Optional<Integer> protocolVersion = getProtocolVersion(conf);
LoadBalancingPolicy loadBalancingPolicy = getReadLoadBalancingPolicy(conf, hosts);
SocketOptions socketOptions = getReadSocketOptions(conf);
QueryOptions queryOptions = getReadQueryOptions(conf);
PoolingOptions poolingOptions = getReadPoolingOptions(conf);
Cluster.Builder builder = Cluster.builder()
.addContactPoints(hosts)
.withPort(port)
.withCompression(ProtocolOptions.Compression.NONE);
if (authProvider.isPresent())
builder.withAuthProvider(authProvider.get());
if (sslOptions.isPresent())
builder.withSSL(sslOptions.get());
if (protocolVersion.isPresent()) {
builder.withProtocolVersion(protocolVersion.get());
}
builder.withLoadBalancingPolicy(loadBalancingPolicy)
.withSocketOptions(socketOptions)
.withQueryOptions(queryOptions)
.withPoolingOptions(poolingOptions);
return builder.build();
}
示例6: ConstructorConfiguredCqlClientFactory
import com.datastax.driver.core.ProtocolOptions; //导入依赖的package包/类
public ConstructorConfiguredCqlClientFactory(String hosts, String clusterName, ConsistencyLevel clusterConsistency,
ConsistencyLevel conditionalUpdateConsistency, ProtocolOptions.Compression compression) {
this.hosts = hosts.split(",");
this.clusterConsistencyLevel = clusterConsistency;
if (conditionalUpdateConsistency != null){
this.serialConsistencyLevel = conditionalUpdateConsistency;
}
if (clusterName != null) {
this.clusterName = clusterName;
}
this.compression = compression;
}
示例7: getClusterBuilder
import com.datastax.driver.core.ProtocolOptions; //导入依赖的package包/类
public Cluster.Builder getClusterBuilder() {
final List<InetSocketAddress> sockets = new ArrayList<InetSocketAddress>();
for (String host : hosts) {
if(StringUtils.contains(host, ":")) {
String hostParts [] = StringUtils.split(host, ":");
sockets.add(new InetSocketAddress(hostParts[0], Integer.valueOf(hostParts[1])));
LOG.debug("Connecting to [" + host + "] with port [" + hostParts[1] + "]");
} else {
sockets.add(new InetSocketAddress(host, ProtocolOptions.DEFAULT_PORT));
LOG.debug("Connecting to [" + host + "] with port [" + ProtocolOptions.DEFAULT_PORT + "]");
}
}
Cluster.Builder builder = Cluster.builder().addContactPointsWithPorts(sockets).withCompression(compression);
QueryOptions queryOptions = new QueryOptions();
queryOptions.setConsistencyLevel(clusterConsistencyLevel);
queryOptions.setSerialConsistencyLevel(serialConsistencyLevel);
builder = builder.withQueryOptions(queryOptions);
if (StringUtils.isNotEmpty(clusterName)) {
builder = builder.withClusterName(clusterName);
}
return builder;
}
示例8: testGetClusterBuilder
import com.datastax.driver.core.ProtocolOptions; //导入依赖的package包/类
@Test
public void testGetClusterBuilder() throws Exception {
final Map<Object, Object> configuration = new HashMap<Object,Object>();
configuration.put(MapConfiguredCqlClientFactory.TRIDENT_CASSANDRA_CQL_HOSTS, HOSTS);
configuration.put(MapConfiguredCqlClientFactory.TRIDENT_CASSANDRA_CLUSTER_NAME, CLUSTER_NAME);
configuration.put(MapConfiguredCqlClientFactory.TRIDENT_CASSANDRA_READ_TIMEOUT, READ_TIMEOUT);
configuration.put(MapConfiguredCqlClientFactory.TRIDENT_CASSANDRA_CONNECT_TIMEOUT, CONNECT_TIMEOUT);
configuration.put(MapConfiguredCqlClientFactory.TRIDENT_CASSANDRA_LOCAL_DATA_CENTER_NAME, DATA_CENTER_NAME);
configuration.put(MapConfiguredCqlClientFactory.TRIDENT_CASSANDRA_CONSISTENCY, DEFAULT_CONSISTENCY_LEVEL.name());
configuration.put(MapConfiguredCqlClientFactory.TRIDENT_CASSANDRA_SERIAL_CONSISTENCY, DEFAULT_SERIAL_CONSISTENCY_LEVEL.name());
final CqlClientFactory factory =
new MapConfiguredCqlClientFactory(configuration);
final Cluster.Builder clusterBuilder = factory.getClusterBuilder();
Assert.assertEquals(CLUSTER_NAME, clusterBuilder.getClusterName());
final InetSocketAddress first = clusterBuilder.getContactPoints().get(0);
final InetSocketAddress second = clusterBuilder.getContactPoints().get(1);
Assert.assertEquals("localhost", first.getHostName());
Assert.assertEquals(9042, first.getPort());
Assert.assertEquals("remotehost", second.getHostName());
Assert.assertEquals(1234, second.getPort());
Assert.assertEquals(Integer.parseInt(CONNECT_TIMEOUT), clusterBuilder.getConfiguration().getSocketOptions().getConnectTimeoutMillis());
Assert.assertEquals(Integer.parseInt(READ_TIMEOUT), clusterBuilder.getConfiguration().getSocketOptions().getReadTimeoutMillis());
Assert.assertEquals(DEFAULT_CONSISTENCY_LEVEL, clusterBuilder.getConfiguration().getQueryOptions().getConsistencyLevel());
Assert.assertEquals(DEFAULT_SERIAL_CONSISTENCY_LEVEL, clusterBuilder.getConfiguration().getQueryOptions().getSerialConsistencyLevel());
Assert.assertEquals(ProtocolOptions.Compression.NONE, clusterBuilder.getConfiguration().getProtocolOptions().getCompression());
}
示例9: setCompression
import com.datastax.driver.core.ProtocolOptions; //导入依赖的package包/类
/**
* Sets compression algorithm to use for the transport.
*
* @param compression Compression algorithm.
*/
@SuppressWarnings("UnusedDeclaration")
public void setCompression(String compression) {
this.compression = compression == null || compression.trim().isEmpty() ? null : compression.trim();
try {
if (this.compression != null)
ProtocolOptions.Compression.valueOf(this.compression);
}
catch (Throwable e) {
throw new IgniteException("Incorrect compression '" + compression + "' specified for Cassandra connection", e);
}
invalidate();
}
示例10: getCluster
import com.datastax.driver.core.ProtocolOptions; //导入依赖的package包/类
public static Cluster getCluster(String[] hosts, Configuration conf, int port)
{
Optional<AuthProvider> authProvider = getAuthProvider(conf);
Optional<SSLOptions> sslOptions = getSSLOptions(conf);
Optional<Integer> protocolVersion = getProtocolVersion(conf);
LoadBalancingPolicy loadBalancingPolicy = getReadLoadBalancingPolicy(hosts);
SocketOptions socketOptions = getReadSocketOptions(conf);
QueryOptions queryOptions = getReadQueryOptions(conf);
PoolingOptions poolingOptions = getReadPoolingOptions(conf);
Cluster.Builder builder = Cluster.builder()
.addContactPoints(hosts)
.withPort(port)
.withCompression(ProtocolOptions.Compression.NONE);
if (authProvider.isPresent())
builder.withAuthProvider(authProvider.get());
if (sslOptions.isPresent())
builder.withSSL(sslOptions.get());
if (protocolVersion.isPresent()) {
builder.withProtocolVersion(ProtocolVersion.fromInt(protocolVersion.get()));
}
builder.withLoadBalancingPolicy(loadBalancingPolicy)
.withSocketOptions(socketOptions)
.withQueryOptions(queryOptions)
.withPoolingOptions(poolingOptions);
return builder.build();
}
示例11: CassandraMetricBatch
import com.datastax.driver.core.ProtocolOptions; //导入依赖的package包/类
public CassandraMetricBatch(Metadata metadata, ProtocolOptions protocol, CodecRegistry codec,
TokenAwarePolicy lbPolicy, int batchLimit) {
this.protocol = protocol;
this.codec = codec;
this.metadata = metadata;
this.policy = lbPolicy;
metricQueries = new HashMap<>();
this.batchLimit = batchLimit;
metricQueries = new HashMap<>();
dimensionQueries = new HashMap<>();
dimensionMetricQueries = new HashMap<>();
metricDimensionQueries = new HashMap<>();
measurementQueries = new HashMap<>();
}
示例12: getInputCluster
import com.datastax.driver.core.ProtocolOptions; //导入依赖的package包/类
public static Cluster getInputCluster(String[] hosts, Configuration conf)
{
int port = getInputNativePort(conf);
Optional<AuthProvider> authProvider = getAuthProvider(conf);
Optional<SSLOptions> sslOptions = getSSLOptions(conf);
LoadBalancingPolicy loadBalancingPolicy = getReadLoadBalancingPolicy(conf, hosts);
SocketOptions socketOptions = getReadSocketOptions(conf);
QueryOptions queryOptions = getReadQueryOptions(conf);
PoolingOptions poolingOptions = getReadPoolingOptions(conf);
Cluster.Builder builder = Cluster.builder()
.addContactPoints(hosts)
.withPort(port)
.withCompression(ProtocolOptions.Compression.NONE);
if (authProvider.isPresent())
builder.withAuthProvider(authProvider.get());
if (sslOptions.isPresent())
builder.withSSL(sslOptions.get());
builder.withLoadBalancingPolicy(loadBalancingPolicy)
.withSocketOptions(socketOptions)
.withQueryOptions(queryOptions)
.withPoolingOptions(poolingOptions);
return builder.build();
}
示例13: getInputCluster
import com.datastax.driver.core.ProtocolOptions; //导入依赖的package包/类
public static Cluster getInputCluster(String host, Configuration conf)
{
int port = getInputNativePort(conf);
Optional<AuthProvider> authProvider = getAuthProvider(conf);
Optional<SSLOptions> sslOptions = getSSLOptions(conf);
LoadBalancingPolicy loadBalancingPolicy = getReadLoadBalancingPolicy(conf, host);
SocketOptions socketOptions = getReadSocketOptions(conf);
QueryOptions queryOptions = getReadQueryOptions(conf);
PoolingOptions poolingOptions = getReadPoolingOptions(conf);
Cluster.Builder builder = Cluster.builder()
.addContactPoint(host)
.withPort(port)
.withCompression(ProtocolOptions.Compression.NONE);
if (authProvider.isPresent())
builder.withAuthProvider(authProvider.get());
if (sslOptions.isPresent())
builder.withSSL(sslOptions.get());
builder.withLoadBalancingPolicy(loadBalancingPolicy)
.withSocketOptions(socketOptions)
.withQueryOptions(queryOptions)
.withPoolingOptions(poolingOptions);
return builder.build();
}
示例14: setCompression
import com.datastax.driver.core.ProtocolOptions; //导入依赖的package包/类
/**
* Derive the compression option from the enum based on the given string. Defaults to NONE.
*
* @param compression
* The name of the compression chosen (either NONE, SNAPPY or LZ4)
*/
public void setCompression(String compression) {
try {
this.compression = ProtocolOptions.Compression.valueOf(compression);
} catch(Exception e) {
this.compression = ProtocolOptions.Compression.NONE;
}
}
示例15: shouldCreateClusterWithConfig
import com.datastax.driver.core.ProtocolOptions; //导入依赖的package包/类
@Test
public void shouldCreateClusterWithConfig() throws Exception {
CassandraServiceInfo info = new CassandraServiceInfo("local",
Collections.singletonList("127.0.0.1"), 9142);
CassandraClusterConfig config = new CassandraClusterConfig();
config.setCompression(ProtocolOptions.Compression.NONE);
config.setPoolingOptions(new PoolingOptions().setPoolTimeoutMillis(1234));
config.setQueryOptions(new QueryOptions());
config.setProtocolVersion(ProtocolVersion.NEWEST_SUPPORTED);
config.setLoadBalancingPolicy(new RoundRobinPolicy());
config.setReconnectionPolicy(new ConstantReconnectionPolicy(1));
config.setRetryPolicy(DowngradingConsistencyRetryPolicy.INSTANCE);
config.setSocketOptions(new SocketOptions());
Cluster cluster = creator.create(info, config);
Configuration configuration = cluster.getConfiguration();
assertThat(configuration.getProtocolOptions().getCompression(),
is(config.getCompression()));
assertThat(configuration.getQueryOptions(), is(config.getQueryOptions()));
assertThat(configuration.getSocketOptions(), is(config.getSocketOptions()));
Policies policies = configuration.getPolicies();
assertThat(policies.getLoadBalancingPolicy(),
is(config.getLoadBalancingPolicy()));
assertThat(policies.getReconnectionPolicy(), is(config.getReconnectionPolicy()));
assertThat(policies.getRetryPolicy(), is(config.getRetryPolicy()));
}