本文整理汇总了Java中com.datastax.driver.core.ProtocolVersion类的典型用法代码示例。如果您正苦于以下问题:Java ProtocolVersion类的具体用法?Java ProtocolVersion怎么用?Java ProtocolVersion使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ProtocolVersion类属于com.datastax.driver.core包,在下文中一共展示了ProtocolVersion类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testShouldFailToConnectWithOlderProtocolVersion
import com.datastax.driver.core.ProtocolVersion; //导入依赖的package包/类
@Test
public void testShouldFailToConnectWithOlderProtocolVersion() {
try (BoundNode node = server.register(NodeSpec.builder().build());
Cluster cluster = defaultBuilder(node).withProtocolVersion(ProtocolVersion.V2).build()) {
// Since simulacron does not support < V3, an exception should be thrown if we try to force
// an older version.
try {
cluster.connect();
} catch (UnsupportedProtocolVersionException e) {
// expected
}
// Should get a query log indicating invalid protocol version was used.
assertThat(node.getLogs().getQueryLogs()).hasSize(1);
QueryLog log = node.getLogs().getQueryLogs().get(0);
Frame frame = log.getFrame();
assertThat(frame.protocolVersion).isEqualTo(2);
assertThat(frame.warnings).hasSize(1);
assertThat(frame.warnings.get(0))
.isEqualTo(
"This message contains a non-supported protocol version by this node. STARTUP is inferred, but may not reflect the actual message sent.");
assertThat(frame.message).isInstanceOf(Startup.class);
}
}
示例2: buildCluster
import com.datastax.driver.core.ProtocolVersion; //导入依赖的package包/类
/**
* Creates a cluster object.
*/
public void buildCluster()
{
try {
if (protocolVersion != null && protocolVersion.length() != 0) {
ProtocolVersion version = getCassandraProtocolVersion();
cluster = Cluster.builder().addContactPoint(node).withCredentials(userName, password).withProtocolVersion(version).build();
} else {
cluster = Cluster.builder().addContactPoint(node).withCredentials(userName, password).build();
}
} catch (DriverException ex) {
throw new RuntimeException("closing database resource", ex);
} catch (Throwable t) {
DTThrowable.rethrow(t);
}
}
示例3: call
import com.datastax.driver.core.ProtocolVersion; //导入依赖的package包/类
@Override
public Session call() throws Exception {
try {
return new Cluster.Builder()
.addContactPoints(nodes.split(","))
.withPort(new Integer(cqlPort))
.withProtocolVersion(ProtocolVersion.V3)
.withoutJMXReporting()
.build().connect();
} catch (Exception e) {
if (attempts != 0) {
logger.attemptToConnectToCassandraFailed(attempts, e);
attempts--;
Thread.sleep(interval);
return call();
} else {
logger.cannotConnectToCassandra(e);
return null;
}
}
}
示例4: applyMicroBatching
import com.datastax.driver.core.ProtocolVersion; //导入依赖的package包/类
private Observable.Transformer<BoundStatement, Integer> applyMicroBatching() {
return tObservable -> tObservable
.groupBy(b -> {
ByteBuffer routingKey = b.getRoutingKey(ProtocolVersion.NEWEST_SUPPORTED,
codecRegistry);
Token token = metadata.newToken(routingKey);
for (TokenRange tokenRange : session.getCluster().getMetadata().getTokenRanges()) {
if (tokenRange.contains(token)) {
return tokenRange;
}
}
log.warn("Unable to find any Cassandra node to insert token " + token.toString());
return session.getCluster().getMetadata().getTokenRanges().iterator().next();
})
.flatMap(g -> g.compose(new BoundBatchStatementTransformer()))
.flatMap(batch -> rxSession
.execute(batch)
.compose(applyInsertRetryPolicy())
.map(resultSet -> batch.size())
);
}
示例5: doSendMessage
import com.datastax.driver.core.ProtocolVersion; //导入依赖的package包/类
private <T extends Serializable> void doSendMessage( T body, List<String> regions ) throws IOException {
createQueueIfNecessary();
ByteArrayOutputStream bos = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(bos);
oos.writeObject(body);
oos.flush();
oos.close();
ByteBuffer byteBuffer = ByteBuffer.wrap( bos.toByteArray() );
queueMessageManager.sendMessages(
scope.getName(),
regions,
null, // delay millis
null, // expiration seconds
"application/octet-stream",
DataType.serializeValue( byteBuffer, ProtocolVersion.NEWEST_SUPPORTED ));
}
示例6: newSession
import com.datastax.driver.core.ProtocolVersion; //导入依赖的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);
}
示例7: testSerialize
import com.datastax.driver.core.ProtocolVersion; //导入依赖的package包/类
@Test
public void testSerialize() {
Address address = randomAddress();
AddressCodec codec = new AddressCodec();
ByteBuffer buffer = codec.serialize(address, ProtocolVersion.NEWEST_SUPPORTED);
Address address1 = codec.deserialize(buffer, ProtocolVersion.NEWEST_SUPPORTED);
Assert.assertEquals(address, address1);
}
示例8: createCluster
import com.datastax.driver.core.ProtocolVersion; //导入依赖的package包/类
/**
* @param ip String
* @param port String
* @param poolingOptions PoolingOptions
* @return Cluster Cluster
*/
private static Cluster createCluster(String ip, String port, PoolingOptions poolingOptions) {
return Cluster.builder().addContactPoint(ip).withPort(Integer.parseInt(port))
.withProtocolVersion(ProtocolVersion.V3).withRetryPolicy(DefaultRetryPolicy.INSTANCE)
.withTimestampGenerator(new AtomicMonotonicTimestampGenerator())
.withPoolingOptions(poolingOptions).build();
}
示例9: init
import com.datastax.driver.core.ProtocolVersion; //导入依赖的package包/类
@Before
public void init() throws Exception {
initCassandraFS();
Cluster cluster = Cluster.builder().addContactPoints("localhost").withProtocolVersion(ProtocolVersion.V4)
.build();
session = cluster.connect();
session.execute("USE test;");
}
示例10: init
import com.datastax.driver.core.ProtocolVersion; //导入依赖的package包/类
@Before
public void init() throws Exception {
String cassandraServer = System.getProperty("CassandraNode");
if (cassandraServer == null || cassandraServer.length() == 0) {
cassandraServer = "localhost";
}
Cluster cluster = Cluster.builder().addContactPoints(cassandraServer).withProtocolVersion(ProtocolVersion.V4)
.build();
session = cluster.connect();
session.execute("USE test;");
}
示例11: handleInvocation
import com.datastax.driver.core.ProtocolVersion; //导入依赖的package包/类
@Override protected Object handleInvocation(Object proxy, Method method, Object[] args)
throws Throwable {
// Only join traces, don't start them. This prevents LocalCollector's thread from amplifying.
if (brave.serverSpanThreadBinder().getCurrentServerSpan() != null &&
brave.serverSpanThreadBinder().getCurrentServerSpan().getSpan() != null
// Only trace named statements for now, since that's what we use
&& method.getName().equals("executeAsync") && args[0] instanceof NamedBoundStatement) {
NamedBoundStatement statement = (NamedBoundStatement) args[0];
SpanId spanId = brave.clientTracer().startNewSpan(statement.name);
// o.a.c.tracing.Tracing.newSession must use the same format for the key zipkin
if (version.compareTo(ProtocolVersion.V4) >= 0) {
statement.enableTracing();
statement.setOutgoingPayload(singletonMap("zipkin", ByteBuffer.wrap(spanId.bytes())));
}
brave.clientTracer().setClientSent(); // start the span and store it
brave.clientTracer()
.submitBinaryAnnotation("cql.query", statement.preparedStatement().getQueryString());
cache.put(statement, brave.clientSpanThreadBinder().getCurrentClientSpan());
// let go of the client span as it is only used for the RPC (will have no local children)
brave.clientSpanThreadBinder().setCurrentSpan(null);
return new BraveResultSetFuture(target.executeAsync(statement), brave);
}
try {
return method.invoke(target, args);
} catch (InvocationTargetException e) {
if (e.getCause() instanceof RuntimeException) throw e.getCause();
throw e;
}
}
示例12: handleInvocation
import com.datastax.driver.core.ProtocolVersion; //导入依赖的package包/类
@Override protected Object handleInvocation(Object proxy, Method method, Object[] args)
throws Throwable {
// Only join traces, don't start them. This prevents LocalCollector's thread from amplifying.
if (brave.serverSpanThreadBinder().getCurrentServerSpan() != null &&
brave.serverSpanThreadBinder().getCurrentServerSpan().getSpan() != null
&& method.getName().equals("executeAsync") && args[0] instanceof BoundStatement) {
BoundStatement statement = (BoundStatement) args[0];
// via an internal class z.s.cassandra3.NamedBoundStatement, toString() is a nice name
SpanId spanId = brave.clientTracer().startNewSpan(statement.toString());
// o.a.c.tracing.Tracing.newSession must use the same format for the key zipkin
if (version.compareTo(ProtocolVersion.V4) >= 0) {
statement.enableTracing();
statement.setOutgoingPayload(singletonMap("zipkin", ByteBuffer.wrap(spanId.bytes())));
}
brave.clientTracer().setClientSent(); // start the span and store it
brave.clientTracer()
.submitBinaryAnnotation("cql.query", statement.preparedStatement().getQueryString());
cache.put(statement, brave.clientSpanThreadBinder().getCurrentClientSpan());
// let go of the client span as it is only used for the RPC (will have no local children)
brave.clientSpanThreadBinder().setCurrentSpan(null);
return new BraveResultSetFuture(target.executeAsync(statement), brave);
}
try {
return method.invoke(target, args);
} catch (InvocationTargetException e) {
if (e.getCause() instanceof RuntimeException) throw e.getCause();
throw e;
}
}
示例13: CqlDeltaIterator
import com.datastax.driver.core.ProtocolVersion; //导入依赖的package包/类
public CqlDeltaIterator(Iterator<Row> iterator, final int blockIndex, final int changeIdIndex, final int contentIndex, boolean reversed, int prefixLength,
ProtocolVersion protocolVersion, CodecRegistry codecRegistry) {
super(iterator, reversed, prefixLength);
_blockIndex = blockIndex;
_changeIdIndex = changeIdIndex;
_contentIndex = contentIndex;
_protocolVersion = protocolVersion;
_codecRegistry = codecRegistry;
}
示例14: deserializeNoBoxing
import com.datastax.driver.core.ProtocolVersion; //导入依赖的package包/类
@Override
public long deserializeNoBoxing(ByteBuffer bytes, ProtocolVersion protocolVersion) {
if (bytes == null || bytes.remaining() == 0) {
return 0;
}
if (bytes.remaining() != 8) {
throw new InvalidTypeException("Invalid 64-bits long value, expecting 8 bytes but got " + bytes.remaining());
}
return bytes.getLong(bytes.position());
}
示例15: getCassandraProtocolVersion
import com.datastax.driver.core.ProtocolVersion; //导入依赖的package包/类
private ProtocolVersion getCassandraProtocolVersion()
{
switch (protocolVersion.toUpperCase()) {
case "V1":
return ProtocolVersion.V1;
case "V2":
return ProtocolVersion.V2;
case "V3":
return ProtocolVersion.V3;
default:
throw new RuntimeException("Unsupported Cassandra Protocol Version.");
}
}