From 07b4574a323a2a73ce706ccddcee847010f9fdcc Mon Sep 17 00:00:00 2001 From: Pawel Mazurek Date: Fri, 17 Nov 2023 08:29:09 +0100 Subject: [PATCH] HeapCache shutdown method --- .../here/naksha/lib/heapcache/HeapCache.java | 39 +++++++++++++++---- 1 file changed, 32 insertions(+), 7 deletions(-) diff --git a/here-naksha-lib-heapcache/src/main/java/com/here/naksha/lib/heapcache/HeapCache.java b/here-naksha-lib-heapcache/src/main/java/com/here/naksha/lib/heapcache/HeapCache.java index 811d23693..fffaef9b2 100644 --- a/here-naksha-lib-heapcache/src/main/java/com/here/naksha/lib/heapcache/HeapCache.java +++ b/here-naksha-lib-heapcache/src/main/java/com/here/naksha/lib/heapcache/HeapCache.java @@ -19,14 +19,19 @@ package com.here.naksha.lib.heapcache; import com.here.naksha.lib.core.NakshaContext; +import com.here.naksha.lib.core.lambdas.Fe1; import com.here.naksha.lib.core.lambdas.Pe1; import com.here.naksha.lib.core.models.TxSignalSet; import com.here.naksha.lib.core.models.geojson.implementation.XyzFeature; import com.here.naksha.lib.core.storage.*; import com.here.naksha.lib.core.util.fib.FibSet; + import java.lang.ref.WeakReference; import java.util.ArrayList; import java.util.List; +import java.util.concurrent.Executors; +import java.util.concurrent.Future; + import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -101,7 +106,8 @@ public void removeCacheEntry(String key) { protected final @NotNull FibSet cache = new FibSet<>(CacheEntry::new); @Override - public void init() {} + public void init() { + } @Override public void maintain(@NotNull List collectionInfoList) { @@ -128,7 +134,8 @@ public void maintain(@NotNull List collectionInfoList) { } @Override - public void addListener(@NotNull Pe1<@NotNull TxSignalSet> listener) {} + public void addListener(@NotNull Pe1<@NotNull TxSignalSet> listener) { + } @Override public boolean removeListener(@NotNull Pe1<@NotNull TxSignalSet> listener) { @@ -136,31 +143,36 @@ public boolean removeListener(@NotNull Pe1<@NotNull TxSignalSet> listener) { } @Override - public void close() {} + public void close() { + } /** * Initializes the storage, create the transaction table, install needed scripts and extensions. */ @Override - public void initStorage() {} + public void initStorage() { + } /** * Starts the maintainer thread that will take about history garbage collection, sequencing and other background jobs. */ @Override - public void startMaintainer() {} + public void startMaintainer() { + } /** * Blocking call to perform maintenance tasks right now. One-time maintenance. */ @Override - public void maintainNow() {} + public void maintainNow() { + } /** * Stops the maintainer thread. */ @Override - public void stopMaintainer() {} + public void stopMaintainer() { + } /** * Open a new write-session, optionally to a master-node (when being in a multi-writer cluster). @@ -185,4 +197,17 @@ public void stopMaintainer() {} public @NotNull IReadSession newReadSession(@Nullable NakshaContext context, boolean useMaster) { return IStorage.super.newReadSession(context, useMaster); } + + /** + * Shutdown the storage instance asynchronously. This method returns asynchronously whatever the given {@code onShutdown} handler returns. + * If no shutdown handler given, then {@code null} is returned. + * + * @param onShutdown The (optional) method to call when the shutdown is done. + * @return The future when the shutdown will be done. + */ + @Override + public @NotNull Future shutdown(@Nullable Fe1 onShutdown) { + // actually the method is never called in HeapCache, but I don't want to return null in @NotNull tagged method. + return Executors.newSingleThreadExecutor().submit(() -> null); + } }