+ @RequiredArgsConstructor
+ static class LocalStateStoreSettings
+ {
+ final Optional<File> file;
+ final int interval;
+ }
+
+ @Bean
+ LocalStateStoreSettings localStateStoreSettings(TransferServiceProperties properties)
+ {
+ if (properties.getStateStoreInterval() < 1)
+ {
+ log.info("juplo.transfer.state-store-interval is < 1: local storage of state is deactivated");
+ return new LocalStateStoreSettings(Optional.empty(), 0);
+ }
+
+ if (!StringUtils.hasText(properties.getLocalStateStorePath()))
+ {
+ log.info("juplo.transfer.local-state-store-path is not set: local storage of state is deactivated!");
+ return new LocalStateStoreSettings(Optional.empty(), 0);
+ }
+
+ Path path = Path.of(properties.getLocalStateStorePath());
+ log.info("using {} as local state store", path.toAbsolutePath());
+
+ if (Files.notExists(path))
+ {
+ try
+ {
+ Files.createFile(path);
+ }
+ catch (IOException e)
+ {
+ throw new IllegalArgumentException("Could not create local state store: " + path.toAbsolutePath());
+ }
+ }
+
+ if (!(Files.isReadable(path) && Files.isWritable(path)))
+ {
+ throw new IllegalArgumentException("No R/W-access on local state store: " + path.toAbsolutePath());
+ }
+
+ return new LocalStateStoreSettings(Optional.of(path.toFile()), properties.getStateStoreInterval());
+ }
+