You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@isis.apache.org by ah...@apache.org on 2018/02/19 17:10:34 UTC
[isis] branch dev/2.0.0-M2 updated: ISIS-1756 backporting proper
life-cycling from jax-rs-2 branch
This is an automated email from the ASF dual-hosted git repository.
ahuber pushed a commit to branch dev/2.0.0-M2
in repository https://gitbox.apache.org/repos/asf/isis.git
The following commit(s) were added to refs/heads/dev/2.0.0-M2 by this push:
new 058b998 ISIS-1756 backporting proper life-cycling from jax-rs-2 branch
058b998 is described below
commit 058b998b0c0e5a6dbbdc8075836aa75c79954d99
Author: Andi Huber <ah...@apache.org>
AuthorDate: Mon Feb 19 18:10:12 2018 +0100
ISIS-1756 backporting proper life-cycling from jax-rs-2 branch
---
.../core/runtime/system/context/IsisContext.java | 15 +++++
.../DataNucleusApplicationComponents.java | 15 +++++
.../persistence/PersistenceSessionFactory.java | 29 +++------
.../datanucleus/DataNucleusLifeCycleHelper.java | 69 ++--------------------
4 files changed, 41 insertions(+), 87 deletions(-)
diff --git a/core/runtime/src/main/java/org/apache/isis/core/runtime/system/context/IsisContext.java b/core/runtime/src/main/java/org/apache/isis/core/runtime/system/context/IsisContext.java
index 40929e2..9763ff5 100644
--- a/core/runtime/src/main/java/org/apache/isis/core/runtime/system/context/IsisContext.java
+++ b/core/runtime/src/main/java/org/apache/isis/core/runtime/system/context/IsisContext.java
@@ -65,6 +65,7 @@ public interface IsisContext {
*/
public static void clear() {
_Context.clear();
+ resetLogging();
}
// -- DEPRECATIONS
@@ -79,5 +80,19 @@ public interface IsisContext {
clear();
}
+ // -- HELPER
+
+ /**
+ * TODO [andi-huber] not sure if required, initial idea was to force log4j
+ * re-configuration on an undeploy/deploy cycle
+ */
+ static void resetLogging() {
+ try {
+ org.apache.log4j.BasicConfigurator.resetConfiguration();
+ org.apache.log4j.Logger.getRootLogger().removeAllAppenders();
+ } catch (Exception e) {
+ // at least we tried
+ }
+ }
}
diff --git a/core/runtime/src/main/java/org/apache/isis/core/runtime/system/persistence/DataNucleusApplicationComponents.java b/core/runtime/src/main/java/org/apache/isis/core/runtime/system/persistence/DataNucleusApplicationComponents.java
index 8fafca8..9cd3f7f 100644
--- a/core/runtime/src/main/java/org/apache/isis/core/runtime/system/persistence/DataNucleusApplicationComponents.java
+++ b/core/runtime/src/main/java/org/apache/isis/core/runtime/system/persistence/DataNucleusApplicationComponents.java
@@ -32,6 +32,7 @@ import org.apache.isis.core.metamodel.spec.ObjectSpecification;
import org.apache.isis.core.metamodel.specloader.SpecificationLoader;
import org.apache.isis.core.runtime.system.context.IsisContext;
import org.apache.isis.objectstore.jdo.datanucleus.CreateSchemaObjectFromClassMetadata;
+import org.apache.isis.objectstore.jdo.datanucleus.DataNucleusLifeCycleHelper;
import org.apache.isis.objectstore.jdo.datanucleus.DataNucleusPropertiesAware;
import org.apache.isis.objectstore.jdo.metamodel.facets.object.query.JdoNamedQuery;
import org.apache.isis.objectstore.jdo.metamodel.facets.object.query.JdoQueryFacet;
@@ -109,6 +110,20 @@ public class DataNucleusApplicationComponents implements ApplicationScopedCompon
namedQueryByName = catalogNamedQueries(persistableClassNameSet);
}
+
+ /**
+ * Marks the end of DataNucleus' life-cycle. Purges any state associated with DN.
+ * Subsequent calls have no effect.
+ *
+ * @since 2.0.0
+ */
+ public void shutdown() {
+ instance = null;
+ if(persistenceManagerFactory != null) {
+ DataNucleusLifeCycleHelper.cleanUp(persistenceManagerFactory);
+ persistenceManagerFactory = null;
+ }
+ }
private static boolean isSchemaAwareStoreManager(Map<String,String> datanucleusProps) {
diff --git a/core/runtime/src/main/java/org/apache/isis/core/runtime/system/persistence/PersistenceSessionFactory.java b/core/runtime/src/main/java/org/apache/isis/core/runtime/system/persistence/PersistenceSessionFactory.java
index 92f950d..146f16a 100644
--- a/core/runtime/src/main/java/org/apache/isis/core/runtime/system/persistence/PersistenceSessionFactory.java
+++ b/core/runtime/src/main/java/org/apache/isis/core/runtime/system/persistence/PersistenceSessionFactory.java
@@ -53,18 +53,12 @@ public class PersistenceSessionFactory implements ApplicationScopedComponent, Fi
private static final Logger LOG = LoggerFactory.getLogger(PersistenceSessionFactory.class);
- //region > constructor
-
private final IsisConfigurationDefault configuration;
public PersistenceSessionFactory(final IsisConfigurationDefault isisConfiguration) {
this.configuration = isisConfiguration;
}
- //endregion
-
- //region > init, createDataNucleusApplicationComponents
-
public static final String JDO_OBJECTSTORE_CONFIG_PREFIX = "isis.persistor.datanucleus"; // specific to the JDO objectstore
public static final String DATANUCLEUS_CONFIG_PREFIX = "isis.persistor.datanucleus.impl"; // reserved for datanucleus' own config props
@@ -159,19 +153,18 @@ public class PersistenceSessionFactory implements ApplicationScopedComponent, Fi
props.put(key, value);
}
}
- //endregion
- //region > shutdown
@Programmatic
public final void shutdown() {
- // no-op
+ if(!isInitialized()) {
+ return;
+ }
+ if(applicationComponents != null) {
+ applicationComponents.shutdown();
+ applicationComponents = null;
+ }
}
- //endregion
-
-
- //region > createPersistenceSession
-
/**
* Called by {@link org.apache.isis.core.runtime.system.session.IsisSessionFactory#openSession(AuthenticationSession)}.
*/
@@ -190,12 +183,6 @@ public class PersistenceSessionFactory implements ApplicationScopedComponent, Fi
fixturesInstalledFlag);
}
-
-
- //endregion
-
- //region > FixturesInstalledFlag impl
-
private Boolean fixturesInstalled;
@Programmatic
@@ -210,7 +197,5 @@ public class PersistenceSessionFactory implements ApplicationScopedComponent, Fi
this.fixturesInstalled = fixturesInstalled;
}
- //endregion
-
}
diff --git a/core/runtime/src/main/java/org/apache/isis/objectstore/jdo/datanucleus/DataNucleusLifeCycleHelper.java b/core/runtime/src/main/java/org/apache/isis/objectstore/jdo/datanucleus/DataNucleusLifeCycleHelper.java
index 398c30f..570e18f 100644
--- a/core/runtime/src/main/java/org/apache/isis/objectstore/jdo/datanucleus/DataNucleusLifeCycleHelper.java
+++ b/core/runtime/src/main/java/org/apache/isis/objectstore/jdo/datanucleus/DataNucleusLifeCycleHelper.java
@@ -18,60 +18,29 @@
*/
package org.apache.isis.objectstore.jdo.datanucleus;
-import java.lang.invoke.MethodHandle;
-import java.lang.invoke.MethodHandles;
-import java.lang.reflect.Field;
-import java.util.Map;
-import java.util.function.Consumer;
-
import javax.jdo.PersistenceManagerFactory;
-import org.datanucleus.enhancer.EnhancementHelper;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
import org.apache.isis.core.runtime.system.context.IsisContext;
+import org.datanucleus.enhancer.EnhancementHelper;
/**
*
* Purges any state associated with DataNucleus.
+ * <br/><br/>
+ * (requires datanucleus-core >= 5.1.5)
*
- * @author ahuber@apache.org
* @since 2.0.0
*
*/
public class DataNucleusLifeCycleHelper {
- private static final Logger LOG = LoggerFactory.getLogger(DataNucleusLifeCycleHelper.class);
+ //private static final Logger LOG = LoggerFactory.getLogger(DataNucleusLifeCycleHelper.class);
public static void cleanUp(PersistenceManagerFactory persistenceManagerFactory) {
try {
final ClassLoader cl = IsisContext.getClassLoader();
-
-// XXX not needed according to https://github.com/datanucleus/datanucleus-core/issues/272
-//
-// if(persistenceManagerFactory instanceof JDOPersistenceManagerFactory) {
-//
-// final JDOPersistenceManagerFactory jdoPMF =
-// (JDOPersistenceManagerFactory) persistenceManagerFactory;
-// final PersistenceNucleusContext nucleusContext = jdoPMF.getNucleusContext();
-// final AbstractStoreManager storeManager =
-// (AbstractStoreManager)nucleusContext.getStoreManager();
-//
-//
-// persistenceManagerFactory.getManagedClasses()
-// .forEach(clazz->{
-// final ClassLoaderResolver clr = nucleusContext.getClassLoaderResolver(cl);
-//
-// // Un-manage from the store
-// storeManager.unmanageClass(clr, clazz.getName(), false);
-//
-// // Unload the meta-data for this class
-// nucleusContext.getMetaDataManager().unloadMetaDataForClass(clazz.getName());
-// });
-// }
persistenceManagerFactory.close();
@@ -84,35 +53,5 @@ public class DataNucleusLifeCycleHelper {
}
}
-
-
- // -- LOW LEVEL REFLECTION
-
- // TODO remove once DN v5.1.5 is released
- private final static MethodHandle getRegisteredClassesMH;
- static {
- MethodHandle mh;
- try {
- Field registeredClasses = EnhancementHelper.class.getDeclaredField("registeredClasses");
- registeredClasses.setAccessible(true);
- mh = MethodHandles.lookup().unreflectGetter(registeredClasses);
- registeredClasses.setAccessible(false);
- } catch (Exception e) {
- mh = null;
- e.printStackTrace();
- }
- getRegisteredClassesMH = mh;
- }
-
- // TODO remove once DN v5.1.5 is released
- private static void visitDNRegisteredClasses(Consumer<Map<Class<?>, ?>> visitor){
- try {
- visitor.accept( (Map<Class<?>, ?>) getRegisteredClassesMH.invoke() );
- } catch (Throwable e) {
- LOG.warn("Failed to access DataNucleus' EnhancementHelper via reflection.", e);
- }
- }
-
-
}
--
To stop receiving notification emails like this one, please contact
ahuber@apache.org.