Skip to content

Commit

Permalink
Remove resolvers on db shutdown
Browse files Browse the repository at this point in the history
  • Loading branch information
gem-neo4j committed Jan 28, 2025
1 parent 4ecc788 commit c45d0bb
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
8 changes: 8 additions & 0 deletions common/src/main/java/apoc/ApocExtensionFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,14 @@ public void stop() {
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

0 comments on commit c45d0bb

Please sign in to comment.