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

fire BeforeShutdown event to trigger @PreDestroy methods on CDI beans #68

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
<weld.version>2.4.4.Final</weld.version>
<hibernate.validator.version>5.4.1.Final</hibernate.validator.version>
<jersey.version>2.25.1</jersey.version>
<jackson.version>2.8.10</jackson.version>
<jackson.version>2.9.10</jackson.version>
<metro.version>2.3.1</metro.version>
<hibernate.version>5.2.10.Final</hibernate.version>
<eclipselink.version>2.6.4</eclipselink.version>
Expand Down
8 changes: 8 additions & 0 deletions tools/loader/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,12 @@
<description>KumuluzEE custom class loader implementation</description>

<artifactId>kumuluzee-loader</artifactId>

<dependencies>
<dependency>
<groupId>javax.enterprise</groupId>
<artifactId>cdi-api</artifactId>
<scope>provided</scope>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
import com.kumuluz.ee.loader.jar.JarEntryInfo;
import com.kumuluz.ee.loader.jar.JarFileInfo;

import javax.enterprise.inject.spi.BeforeShutdown;
import javax.enterprise.inject.spi.CDI;
import java.io.*;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
Expand All @@ -35,7 +37,6 @@
import java.util.*;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
import java.util.logging.Logger;

/**
* @author Benjamin Kastelic
Expand Down Expand Up @@ -135,6 +136,8 @@ public EeClassLoader(ClassLoader parent) {
shutdown();
} catch (InterruptedException e) {
debug("Failed to shutdown and clean up gracefully.");
} catch (NoClassDefFoundError e) {

}
}));

Expand Down Expand Up @@ -308,12 +311,18 @@ private Class<?> findJarClass(String className) throws EeClassLoaderException {
}

/**
* Called on shutdown to cleanup temporary files.
* Called on shutdown to cleanup CDI beans and temporary files.
*/
private void shutdown() {

debug("Shutting down and cleaning up ...");

try {
CDI.current().getBeanManager().fireEvent(BeforeShutdown.class);
} catch (Exception e) {
// do nothing
}

for (JarFileInfo jarFileInfo : jarFiles) {
try {
jarFileInfo.getJarFile().close();
Expand Down