Skip to content

Commit 5daf310

Browse files
Steffen Folman Qvistgaardwilkinsona
authored andcommitted
Provide control over how a Cassandra Cluster is created
See gh-16702
1 parent 81af0f2 commit 5daf310

File tree

3 files changed

+80
-2
lines changed

3 files changed

+80
-2
lines changed

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/cassandra/CassandraAutoConfiguration.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,17 +40,25 @@
4040
* @author Phillip Webb
4141
* @author Eddú Meléndez
4242
* @author Stephane Nicoll
43+
* @auther Steffen F. Qvistgaard
4344
* @since 1.3.0
4445
*/
4546
@Configuration(proxyBeanMethods = false)
4647
@ConditionalOnClass({ Cluster.class })
4748
@EnableConfigurationProperties(CassandraProperties.class)
4849
public class CassandraAutoConfiguration {
4950

51+
@Bean
52+
@ConditionalOnMissingBean
53+
public CassandraClusterFactory cassandraClusterFactory() {
54+
return new CassandraClusterFactoryImpl();
55+
}
56+
5057
@Bean
5158
@ConditionalOnMissingBean
5259
public Cluster cassandraCluster(CassandraProperties properties,
53-
ObjectProvider<ClusterBuilderCustomizer> builderCustomizers) {
60+
ObjectProvider<ClusterBuilderCustomizer> builderCustomizers,
61+
CassandraClusterFactory clusterFactory) {
5462
PropertyMapper map = PropertyMapper.get();
5563
Cluster.Builder builder = Cluster.builder()
5664
.withClusterName(properties.getClusterName())
@@ -71,7 +79,8 @@ public Cluster cassandraCluster(CassandraProperties properties,
7179
.toCall(builder::withoutJMXReporting);
7280
builderCustomizers.orderedStream()
7381
.forEach((customizer) -> customizer.customize(builder));
74-
return builder.build();
82+
83+
return clusterFactory.build(builder);
7584
}
7685

7786
private QueryOptions getQueryOptions(CassandraProperties properties) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* Copyright 2012-2019 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.boot.autoconfigure.cassandra;
18+
19+
import com.datastax.driver.core.Cluster;
20+
import com.datastax.driver.core.Cluster.Initializer;
21+
22+
/**
23+
* Cassandra Cluster Factory Interface.
24+
*
25+
* This interface allows the default cassandra cluster builder to be overwritten
26+
*
27+
* @auther Steffen F. Qvistgaard
28+
* @since 2.2.0
29+
*/
30+
public interface CassandraClusterFactory {
31+
32+
Cluster build(Initializer initializer);
33+
34+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
* Copyright 2012-2019 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.boot.autoconfigure.cassandra;
18+
19+
import com.datastax.driver.core.Cluster;
20+
import com.datastax.driver.core.Cluster.Initializer;
21+
22+
/**
23+
* Default Cassandra Cluster Factory Implementation.
24+
*
25+
* @auther Steffen F. Qvistgaard
26+
* @since 2.2.0
27+
*/
28+
public class CassandraClusterFactoryImpl implements CassandraClusterFactory {
29+
30+
@Override
31+
public Cluster build(final Initializer initializer) {
32+
return Cluster.buildFrom(initializer);
33+
}
34+
35+
}

0 commit comments

Comments
 (0)