From c8ff954a16c157351250624d508d72e118106b60 Mon Sep 17 00:00:00 2001 From: agrgr Date: Mon, 18 Dec 2023 14:03:17 +0200 Subject: [PATCH] add scheduled reading of server version --- .../AerospikeDataConfigurationSupport.java | 2 +- .../server/version/ServerVersionSupport.java | 25 +++++++++++++++---- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/src/main/java/org/springframework/data/aerospike/config/AerospikeDataConfigurationSupport.java b/src/main/java/org/springframework/data/aerospike/config/AerospikeDataConfigurationSupport.java index b4504ce52..3c7b99fd1 100644 --- a/src/main/java/org/springframework/data/aerospike/config/AerospikeDataConfigurationSupport.java +++ b/src/main/java/org/springframework/data/aerospike/config/AerospikeDataConfigurationSupport.java @@ -124,7 +124,7 @@ public AerospikeIndexResolver aerospikeIndexResolver() { @Bean(name = "aerospikeServerVersionSupport") public ServerVersionSupport serverVersionSupport(IAerospikeClient aerospikeClient) { ServerVersionSupport serverSupport = new ServerVersionSupport(aerospikeClient); - log.debug("Found server version {}", serverSupport.getServerVersion()); + serverSupport.scheduleServerVersionRefresh(); return serverSupport; } diff --git a/src/main/java/org/springframework/data/aerospike/server/version/ServerVersionSupport.java b/src/main/java/org/springframework/data/aerospike/server/version/ServerVersionSupport.java index c240ad9df..0771f8e89 100644 --- a/src/main/java/org/springframework/data/aerospike/server/version/ServerVersionSupport.java +++ b/src/main/java/org/springframework/data/aerospike/server/version/ServerVersionSupport.java @@ -2,30 +2,45 @@ import com.aerospike.client.IAerospikeClient; import com.aerospike.client.Info; +import lombok.Getter; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.data.aerospike.query.cache.IndexRefresher; import java.lang.module.ModuleDescriptor; +import java.util.concurrent.Executors; +import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.TimeUnit; public class ServerVersionSupport { + private final Logger log = LoggerFactory.getLogger(IndexRefresher.class); private static final ModuleDescriptor.Version SERVER_VERSION_6_0_0_0 = ModuleDescriptor.Version.parse("6.0.0.0"); private static final ModuleDescriptor.Version SERVER_VERSION_6_1_0_0 = ModuleDescriptor.Version.parse("6.1.0.0"); private static final ModuleDescriptor.Version SERVER_VERSION_6_1_0_1 = ModuleDescriptor.Version.parse("6.1.0.1"); private static final ModuleDescriptor.Version SERVER_VERSION_6_3_0_0 = ModuleDescriptor.Version.parse("6.3.0.0"); private final IAerospikeClient client; + @Getter private final String serverVersion; + private final ScheduledExecutorService executorService; + private final long intervalSeconds = 1800; public ServerVersionSupport(IAerospikeClient client) { this.client = client; this.serverVersion = findServerVersion(); + this.executorService = Executors.newSingleThreadScheduledExecutor(); } - private String findServerVersion() { - String versionString = Info.request(client.getCluster().getRandomNode(), "version"); - return versionString.substring(versionString.lastIndexOf(' ') + 1); + public void scheduleServerVersionRefresh() { + executorService.scheduleWithFixedDelay(this::findServerVersion, intervalSeconds, intervalSeconds, + TimeUnit.SECONDS); } - public String getServerVersion() { - return serverVersion; + private String findServerVersion() { + String versionString = Info.request(client.getCluster().getRandomNode(), "version"); + versionString = versionString.substring(versionString.lastIndexOf(' ') + 1); + log.debug("Found server version {}", versionString); + return versionString; } /**