Skip to content

Commit

Permalink
move ServerVersionSupport to common configuration, update client bean…
Browse files Browse the repository at this point in the history
…s return type, add CacheKeyProcessor bean, un-deprecate properties
  • Loading branch information
agrgr committed Sep 24, 2024
1 parent 05ded3b commit 6be772c
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,14 @@
import com.aerospike.client.async.NioEventLoops;
import com.aerospike.client.policy.*;
import com.aerospike.client.reactor.AerospikeReactorClient;
import com.aerospike.client.reactor.IAerospikeReactorClient;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.autoconfigure.data.aerospike.AerospikeDataProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.data.aerospike.server.version.ServerVersionSupport;
import reactor.core.publisher.Flux;

import java.util.Optional;
Expand All @@ -50,28 +49,12 @@ public class AerospikeAutoConfiguration {

@Bean(name = "aerospikeClient", destroyMethod = "close")
@ConditionalOnMissingBean(IAerospikeClient.class)
public AerospikeClient aerospikeClient(AerospikeProperties properties,
ClientPolicy aerospikeClientPolicy) {
public IAerospikeClient aerospikeClient(AerospikeProperties properties,
ClientPolicy aerospikeClientPolicy) {
Host[] hosts = Host.parseHosts(properties.getHosts(), properties.getDefaultPort());
return new AerospikeClient(aerospikeClientPolicy, hosts);
}

@Bean(name = "aerospikeServerVersionSupport")
@ConditionalOnMissingBean(ServerVersionSupport.class)
public ServerVersionSupport serverVersionSupport(IAerospikeClient aerospikeClient,
AerospikeDataProperties properties) {
ServerVersionSupport serverVersionSupport = new ServerVersionSupport(aerospikeClient);
processServerVersionRefreshFrequency(properties.getServerVersionRefreshSeconds(), serverVersionSupport);
return serverVersionSupport;
}

private void processServerVersionRefreshFrequency(int serverVersionRefreshSeconds,
ServerVersionSupport serverVersionSupport) {
if (serverVersionRefreshSeconds > 0) {
serverVersionSupport.scheduleServerVersionRefresh(serverVersionRefreshSeconds);
}
}

@Bean(name = "aerospikeClientPolicy")
@ConditionalOnMissingBean
public ClientPolicy aerospikeClientPolicy(AerospikeProperties properties,
Expand Down Expand Up @@ -108,8 +91,8 @@ public static class AerospikeReactiveAutoConfiguration {
@Bean(name = "aerospikeReactorClient", destroyMethod = "")
@ConditionalOnMissingBean
//disable destroy method, because we do not want AerospikeReactorClient to close AerospikeClient
public AerospikeReactorClient aerospikeReactorClient(IAerospikeClient aerospikeClient,
EventLoops eventLoops) {
public IAerospikeReactorClient aerospikeReactorClient(IAerospikeClient aerospikeClient,
EventLoops eventLoops) {
return new AerospikeReactorClient(aerospikeClient, eventLoops);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,21 +38,15 @@ public class AerospikeProperties {
* <p>
* See {@link com.aerospike.client.Host#parseHosts} documentation for more details.
*
* @deprecated since 0.14.0, {@link AerospikeDataSettings} with the prefix "spring-data-aerospike.connection".
* will be used instead to read from application.properties
*/
@Deprecated(since = "0.14.0", forRemoval = true)
private String hosts;

/**
* Port is used if no port specified in AerospikeProperties#hosts.
* <p>
* See {@link com.aerospike.client.Host#parseHosts} documentation for more details.
*
* @deprecated since 0.14.0, {@link AerospikeDataSettings} with the prefix "spring-data-aerospike.connection".
* will be used instead to read from application.properties
*/
@Deprecated(since = "0.14.0", forRemoval = true)
private int defaultPort = 3000;

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
package org.springframework.boot.autoconfigure.data.aerospike;

import com.aerospike.client.IAerospikeClient;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.domain.EntityScanner;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.data.aerospike.cache.AerospikeCacheKeyProcessor;
import org.springframework.data.aerospike.cache.AerospikeCacheKeyProcessorImpl;
import org.springframework.data.aerospike.config.AerospikeConnectionSettings;
import org.springframework.data.aerospike.config.AerospikeDataSettings;
import org.springframework.data.aerospike.config.AerospikeSettings;
Expand All @@ -22,6 +25,7 @@
import org.springframework.data.aerospike.query.StatementBuilder;
import org.springframework.data.aerospike.query.cache.IndexesCache;
import org.springframework.data.aerospike.query.cache.IndexesCacheHolder;
import org.springframework.data.aerospike.server.version.ServerVersionSupport;
import org.springframework.data.annotation.Persistent;
import org.springframework.data.mapping.model.FieldNamingStrategy;

Expand All @@ -31,6 +35,22 @@
@AutoConfiguration
class AerospikeCommonDataConfiguration {

@Bean(name = "aerospikeServerVersionSupport")
@ConditionalOnMissingBean(ServerVersionSupport.class)
public ServerVersionSupport serverVersionSupport(IAerospikeClient aerospikeClient,
AerospikeDataProperties properties) {
ServerVersionSupport serverVersionSupport = new ServerVersionSupport(aerospikeClient);
processServerVersionRefreshFrequency(properties.getServerVersionRefreshSeconds(), serverVersionSupport);
return serverVersionSupport;
}

private void processServerVersionRefreshFrequency(int serverVersionRefreshSeconds,
ServerVersionSupport serverVersionSupport) {
if (serverVersionRefreshSeconds > 0) {
serverVersionSupport.scheduleServerVersionRefresh(serverVersionRefreshSeconds);
}
}

@Bean(name = "aerospikeFilterExpressionsBuilder")
@ConditionalOnMissingBean(name = "aerospikeFilterExpressionsBuilder")
public FilterExpressionsBuilder aerospikeFilterExpressionsBuilder() {
Expand All @@ -55,6 +75,11 @@ public IndexesCacheHolder aerospikeIndexCache() {
return new IndexesCacheHolder();
}

@Bean(name = "aerospikeCacheKeyProcessor")
public AerospikeCacheKeyProcessor cacheKeyProcessor() {
return new AerospikeCacheKeyProcessorImpl();
}

@Bean(name = "mappingAerospikeConverter")
@ConditionalOnMissingBean(name = "mappingAerospikeConverter")
public MappingAerospikeConverter mappingAerospikeConverter(AerospikeMappingContext aerospikeMappingContext,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,10 @@

/**
* Configuration properties for Spring Data Aerospike.
* @deprecated since 0.14.0, {@link AerospikeDataSettings} with the prefix "spring-data-aerospike.data".
* will be used instead to read from application.properties.
*
* @author Igor Ermolenko
* @author Anastasiia Smirnova
*/
@Deprecated(since = "0.14.0", forRemoval = true)
@ConfigurationProperties(prefix = "spring.data.aerospike")
@Getter
@Setter
Expand Down

0 comments on commit 6be772c

Please sign in to comment.