skoppu22 commented on code in PR #189:
URL:
https://github.com/apache/cassandra-analytics/pull/189#discussion_r3065100548
##########
cassandra-analytics-cdc/src/main/java/org/apache/cassandra/bridge/CdcBridgeFactory.java:
##########
@@ -165,6 +168,51 @@ private static VersionSpecificBridge create(@NotNull
String label)
}
}
+ /**
+ * Returns whether the shutdown hook has been registered.
+ */
+ @VisibleForTesting
+ static boolean isShutdownHookRegistered()
+ {
+ return SHUTDOWN_HOOK_REGISTERED.get();
+ }
+
+ /**
+ * Registers a JVM shutdown hook that calls {@link #close()} to release
classloader resources.
+ * Clears the {@link TypeCache} first so type references are released
before classloaders close.
+ * Uses CAS to ensure the hook is registered at most once.
+ */
+ @VisibleForTesting
+ static void maybeRegisterShutdownHook()
+ {
+ if (SHUTDOWN_HOOK_REGISTERED.compareAndSet(false, true))
+ {
+ Runtime.getRuntime().addShutdownHook(new Thread(() -> {
+ try
+ {
+ TypeCache.clear();
+ close();
+ }
+ catch (Exception e)
+ {
+ // best-effort cleanup during JVM shutdown
+ }
+ }, CdcBridgeFactory.class.getSimpleName() + "-shutdown"));
+ }
+ }
+
+ /**
+ * Closes all cached bridge classloaders and clears the cache. Call during
application shutdown
+ * to release classloader resources and delete temp JAR files.
+ *
+ * Do not use this method outside testing; rely on the shutdown hook logic
to clean things up in prod.
Review Comment:
Do we need to add this comment for CassandraBridgeFactory's close as well?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]