Skip to content

Commit

Permalink
HeapCache shutdown method
Browse files Browse the repository at this point in the history
  • Loading branch information
Pawel Mazurek authored and Pawel Mazurek committed Nov 17, 2023
1 parent 5f7f92a commit 07b4574
Showing 1 changed file with 32 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -101,7 +106,8 @@ public void removeCacheEntry(String key) {
protected final @NotNull FibSet<String, CacheEntry> cache = new FibSet<>(CacheEntry::new);

@Override
public void init() {}
public void init() {
}

@Override
public void maintain(@NotNull List<CollectionInfo> collectionInfoList) {
Expand All @@ -128,39 +134,45 @@ public void maintain(@NotNull List<CollectionInfo> 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) {
return false;
}

@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).
Expand All @@ -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 <T> Future<T> shutdown(@Nullable Fe1<T, IStorage> 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);
}
}

0 comments on commit 07b4574

Please sign in to comment.