Refine search
@Override public void init(Cluster cluster, Collection<Host> hosts) { clusterMetadata = cluster.getMetadata(); protocolVersion = cluster.getConfiguration().getProtocolOptions().getProtocolVersion(); codecRegistry = cluster.getConfiguration().getCodecRegistry(); childPolicy.init(cluster, hosts); }
ProtocolOptions protocolOptions = factory.configuration.getProtocolOptions(); bootstrap.handler( new Initializer( this, protocolVersion, protocolOptions.getCompression().compressor(), protocolOptions.getSSLOptions(), factory.configuration.getPoolingOptions().getHeartbeatIntervalSeconds(), factory.configuration.getNettyOptions(), factory.configuration.getCodecRegistry(), factory.configuration.getMetricsOptions().isEnabled()
/** * The configuration that will be used for the new cluster. * * <p>You <b>should not</b> modify this object directly because changes made to the returned * object may not be used by the cluster build. Instead, you should use the other methods of * this {@code Builder}. * * @return the configuration to use for the new cluster. */ @Override public Configuration getConfiguration() { ProtocolOptions protocolOptions = new ProtocolOptions( port, protocolVersion, maxSchemaAgreementWaitSeconds, sslOptions, authProvider, noCompact) .setCompression(compression); MetricsOptions metricsOptions = new MetricsOptions(metricsEnabled, jmxEnabled); return configurationBuilder .withProtocolOptions(protocolOptions) .withMetricsOptions(metricsOptions) .withPolicies(policiesBuilder.build()) .build(); }
/** @jira_ticket JAVA-1209 */ @Test(groups = "unit") public void getProtocolVersion_should_return_null_if_not_connected() { Cluster cluster = Cluster.builder().addContactPoint("127.0.0.1").build(); assertThat(cluster.getConfiguration().getProtocolOptions().getProtocolVersion()).isNull(); }
void compressionTest(ProtocolOptions.Compression compression) { cluster().getConfiguration().getProtocolOptions().setCompression(compression); try { Session compressedSession = cluster().connect(keyspace); compressedSession.execute( String.format( Locale.US, checkExecuteResultSet(compressedSession.execute(SELECT_ALL), key); checkExecuteResultSet( compressedSession.execute( new SimpleStatement(SELECT_ALL).setConsistencyLevel(ConsistencyLevel.ONE)), key); .getConfiguration() .getProtocolOptions() .setCompression(ProtocolOptions.Compression.NONE);
public void should_not_use_keyspace_if_set_and_protocol_does_not_support() { ProtocolVersion protocolVersion = cluster().getConfiguration().getProtocolOptions().getProtocolVersion(); while (ProtocolFeature.KEYSPACE_ON_QUERY.isSupportedBy(protocolVersion)) { for (String keyspace : sessionKeyspaces) { Session session = cluster.connect(keyspace); PreparedStatement prepared = session.prepare(statement); Row row = session.execute(bound).one(); cluster.close();
Cluster.Builder builder = Cluster.builder() .addContactPoints(contactPoints.toArray(new String[0])) .withPort(port) .withLoadBalancingPolicy(config.getPolicies().getLoadBalancingPolicy()) .withReconnectionPolicy(config.getPolicies().getReconnectionPolicy()) .withRetryPolicy(config.getPolicies().getRetryPolicy()) .withCompression(config.getProtocolOptions().getCompression()) .withPoolingOptions(config.getPoolingOptions()) .withSocketOptions(config.getSocketOptions()) this.cluster.getMetrics().getRegistry().addListener((MetricRegistryListener) this.metricsRegListener); session = cluster.connect(); Logger.info("Done connecting to cluster, session object created");
@Test(groups = "short") public void should_measure_inbound_and_outbound_traffic() { Metrics metrics = session().getCluster().getMetrics(); Meter bytesReceived = metrics.getBytesReceived(); Meter bytesSent = metrics.getBytesSent(); int requestSize = statement.requestSizeInBytes( cluster().getConfiguration().getProtocolOptions().getProtocolVersion(), cluster().getConfiguration().getCodecRegistry()); session().execute(statement);
private ProtocolVersion protocolVersion() { // Since the QueryLogger can be registered before the Cluster was initialized, we can't retrieve // it at construction time. Cache it field at first use (a volatile field is good enough since // we // don't need mutual exclusion). if (protocolVersion == null) { protocolVersion = cluster.getConfiguration().getProtocolOptions().getProtocolVersion(); // At least one connection was established when QueryLogger is invoked assert protocolVersion != null : "protocol version should be defined"; } return protocolVersion; }
CodecRegistry cr = conf != null ? conf.getCodecRegistry() : null; if (cr != null) { builder.withCodecRegistry(cr); MetricsOptions mOpt = conf != null ? conf.getMetricsOptions() : null; if (mOpt != null) { if (!mOpt.isEnabled()) { NettyOptions nOpt = conf != null ? conf.getNettyOptions() : null; if (nOpt != null) { builder.withNettyOptions(nOpt); ProtocolOptions proOpt = conf != null ? conf.getProtocolOptions() : null; if (proOpt != null) { if (proOpt.getCompression() != null) { builder.withCompression(proOpt.getCompression()); if (proOpt.getMaxSchemaAgreementWaitSeconds() > 0) { builder.withMaxSchemaAgreementWaitSeconds( proOpt.getMaxSchemaAgreementWaitSeconds()); if (proOpt.getProtocolVersion() != null) { builder.withProtocolVersion(proOpt.getProtocolVersion()); if (proOpt.getSSLOptions() != null) { builder.withSSL(proOpt.getSSLOptions());
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();
@Test public void shouldCreateClusterWithAuthentication() throws Exception { CassandraServiceInfo info = new CassandraServiceInfo("local", Collections.singletonList("127.0.0.1"), 9142, "walter", "white"); Cluster cluster = creator.create(info, null); Configuration configuration = cluster.getConfiguration(); assertThat(configuration.getProtocolOptions().getAuthProvider(), is(instanceOf(PlainTextAuthProvider.class))); }
Factory(Cluster.Manager manager, Configuration configuration) { this.defaultHandler = manager; this.manager = manager; this.reaper = manager.reaper; this.configuration = configuration; this.authProvider = configuration.getProtocolOptions().getAuthProvider(); this.protocolVersion = configuration.getProtocolOptions().initialProtocolVersion; this.nettyOptions = configuration.getNettyOptions(); this.eventLoopGroup = nettyOptions.eventLoopGroup( manager .configuration .getThreadingOptions() .createThreadFactory(manager.clusterName, "nio-worker")); this.channelClass = nettyOptions.channelClass(); this.timer = nettyOptions.timer( manager .configuration .getThreadingOptions() .createThreadFactory(manager.clusterName, "timeouter")); }
int getPort() { return configuration.getProtocolOptions().getPort(); }
ResultSetFuture executeQuery(Message.Request msg, Statement statement) { DefaultResultSetFuture future = new DefaultResultSetFuture( this, configuration().getProtocolOptions().getProtocolVersion(), msg); execute(future, statement); return future; }
ProtocolOptions protocolOptions = factory.configuration.getProtocolOptions(); int protocolVersion = factory.protocolVersion == 1 ? 1 : 2; bootstrap.setPipelineFactory(new PipelineFactory(this, protocolVersion, protocolOptions.getCompression().compressor, protocolOptions.getSSLOptions()));
Factory(Cluster.Manager manager, Configuration configuration) { this.defaultHandler = manager; this.manager = manager; this.configuration = configuration; this.authProvider = configuration.getProtocolOptions().getAuthProvider(); this.protocolVersion = configuration.getProtocolOptions().initialProtocolVersion; }
private void initializeTransport(int version) throws ConnectionException, InterruptedException, UnsupportedProtocolVersionException { try { ProtocolOptions.Compression compression = factory.configuration.getProtocolOptions().getCompression(); Message.Response response = write(new Requests.Startup(compression)).get(); switch (response.type) {
/** * Builds the final object from this builder. * * <p>Any field that hasn't been set explicitly will get its default value. * * @return the object. */ public Configuration build() { return new Configuration( policies != null ? policies : Policies.builder().build(), protocolOptions != null ? protocolOptions : new ProtocolOptions(), poolingOptions != null ? poolingOptions : new PoolingOptions(), socketOptions != null ? socketOptions : new SocketOptions(), metricsOptions != null ? metricsOptions : new MetricsOptions(), queryOptions != null ? queryOptions : new QueryOptions(), threadingOptions != null ? threadingOptions : new ThreadingOptions(), nettyOptions != null ? nettyOptions : NettyOptions.DEFAULT_INSTANCE, codecRegistry != null ? codecRegistry : CodecRegistry.DEFAULT_INSTANCE); } }
/** * The configuration that will be used for the new cluster. * <p> * You <b>should not</b> modify this object directly because changes made * to the returned object may not be used by the cluster build. * Instead, you should use the other methods of this {@code Builder}. * * @return the configuration to use for the new cluster. */ @Override public Configuration getConfiguration() { Policies policies = new Policies( loadBalancingPolicy == null ? Policies.defaultLoadBalancingPolicy() : loadBalancingPolicy, reconnectionPolicy == null ? Policies.defaultReconnectionPolicy() : reconnectionPolicy, retryPolicy == null ? Policies.defaultRetryPolicy() : retryPolicy, addressTranslater == null ? Policies.defaultAddressTranslater() : addressTranslater ); return new Configuration(policies, new ProtocolOptions(port, protocolVersion, sslOptions, authProvider).setCompression(compression), poolingOptions == null ? new PoolingOptions() : poolingOptions, socketOptions == null ? new SocketOptions() : socketOptions, metricsEnabled ? new MetricsOptions(jmxEnabled) : null, queryOptions == null ? new QueryOptions() : queryOptions); }