Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove resolvers on db shutdown #722

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions common/src/main/java/apoc/ApocExtensionFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,15 @@ public void stop() {
registeredListeners.forEach(availabilityGuard::removeListener);
registeredListeners.clear();
}

@Override
public void shutdown() throws Exception {
String databaseName = db.databaseName();
services.values().forEach(lifecycle -> dependencies
.registerComponentLifecycle()
.cleanUpResolver(databaseName, lifecycle.getClass()));
}


public Collection<AvailabilityListener> getRegisteredListeners() {
return registeredListeners;
Expand Down
18 changes: 16 additions & 2 deletions common/src/main/java/apoc/RegisterComponentFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,23 @@ public class RegisterComponentLifecycle extends LifecycleAdapter {

private final Map<Class, Map<String, Object>> resolvers = new ConcurrentHashMap<>();

public void addResolver(String databaseNamme, Class clazz, Object instance) {
public void addResolver(String databaseName, Class clazz, Object instance) {
Map<String, Object> classInstanceMap = resolvers.computeIfAbsent(clazz, s -> new ConcurrentHashMap<>());
classInstanceMap.put(databaseNamme, instance);
classInstanceMap.put(databaseName, instance);
}

public void cleanUpResolver(String databaseName, Class clazz) {
Map<String, Object> innerMap = resolvers.get(clazz);

if (innerMap != null) {
// Remove the database to instance value
innerMap.remove(databaseName);

// If the inner map is now empty, remove the key from the outer map
if (innerMap.isEmpty()) {
resolvers.remove(clazz);
}
}
}

@SuppressWarnings("unused") // used from extended
Expand Down
Loading