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/09/04 18:05:19 UTC

[isis] branch master updated (8619eb6 -> 967dcce)

This is an automated email from the ASF dual-hosted git repository.

ahuber pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/isis.git.


    from 8619eb6  ISIS-1976: minor cleanup
     new 682091b  ISIS-1895: fix class-loader initialization for skinny-war scenario
     new 967dcce  ISIS-1974: fixes concurrent PersistenceSessionFactory initialization for 2.0.0-M2-SNAPSHOT

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../persistence/PersistenceSessionFactory5.java    | 73 ++++++++++++----------
 .../core/webapp/IsisWebAppContextListener.java     | 13 ++--
 .../wicket/viewer/IsisWicketApplication.java       | 10 ++-
 3 files changed, 55 insertions(+), 41 deletions(-)


[isis] 02/02: ISIS-1974: fixes concurrent PersistenceSessionFactory initialization for 2.0.0-M2-SNAPSHOT

Posted by ah...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

ahuber pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/isis.git

commit 967dccee967fb329fb76f3443305f9c9477d3847
Author: Andi Huber <ah...@apache.org>
AuthorDate: Tue Sep 4 20:04:19 2018 +0200

    ISIS-1974: fixes concurrent PersistenceSessionFactory initialization for
    2.0.0-M2-SNAPSHOT
    
    Task-Url: https://issues.apache.org/jira/browse/ISIS-1974
---
 .../persistence/PersistenceSessionFactory5.java    | 73 ++++++++++++----------
 1 file changed, 39 insertions(+), 34 deletions(-)

diff --git a/core/plugins/jdo-datanucleus-5/src/main/java/org/apache/isis/core/runtime/system/persistence/PersistenceSessionFactory5.java b/core/plugins/jdo-datanucleus-5/src/main/java/org/apache/isis/core/runtime/system/persistence/PersistenceSessionFactory5.java
index 457632d..93a450c 100644
--- a/core/plugins/jdo-datanucleus-5/src/main/java/org/apache/isis/core/runtime/system/persistence/PersistenceSessionFactory5.java
+++ b/core/plugins/jdo-datanucleus-5/src/main/java/org/apache/isis/core/runtime/system/persistence/PersistenceSessionFactory5.java
@@ -20,6 +20,7 @@
 package org.apache.isis.core.runtime.system.persistence;
 
 import java.util.Map;
+import java.util.Objects;
 import java.util.Set;
 
 import javax.jdo.PersistenceManagerFactory;
@@ -30,6 +31,7 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 import org.apache.isis.applib.annotation.Programmatic;
+import org.apache.isis.commons.internal.base._LazyThreadSafe;
 import org.apache.isis.core.commons.authentication.AuthenticationSession;
 import org.apache.isis.core.commons.components.ApplicationScopedComponent;
 import org.apache.isis.core.commons.config.IsisConfiguration;
@@ -53,57 +55,41 @@ implements PersistenceSessionFactory, ApplicationScopedComponent, FixturesInstal
 
     private static final Logger LOG = LoggerFactory.getLogger(PersistenceSessionFactory5.class);
 
-//    private final ConfigurationServiceInternal configuration;
-//
-//    public PersistenceSessionFactory5(final ConfigurationServiceInternal isisConfiguration) {
-//        this.configuration = isisConfiguration;
-//    }
-
     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
 
 
-    private DataNucleusApplicationComponents5 applicationComponents;
+    private final _LazyThreadSafe<DataNucleusApplicationComponents5> applicationComponents = 
+            _LazyThreadSafe.of(this::createDataNucleusApplicationComponents);
 
+    private IsisConfiguration configuration;
+    
     @Programmatic
     @Override
     public void init(final IsisConfigurationDefault configuration) {
-        this.applicationComponents = createDataNucleusApplicationComponents(configuration);
+        this.configuration = configuration;
     }
 
     @Programmatic
     @Override
     public boolean isInitialized() {
-        return this.applicationComponents != null;
+        return this.configuration != null;
     }
 
-    private DataNucleusApplicationComponents5 createDataNucleusApplicationComponents(
-            final IsisConfiguration configuration) {
+    private DataNucleusApplicationComponents5 createDataNucleusApplicationComponents() {
 
         final RegisterEntities registerEntities = new RegisterEntities();
         final Set<String> classesToBePersisted = registerEntities.getEntityTypes();
         
-        if (shouldCreate(this.applicationComponents)) {
+        final IsisConfiguration jdoObjectstoreConfig = configuration.createSubset(
+                JDO_OBJECTSTORE_CONFIG_PREFIX);
 
-            final IsisConfiguration jdoObjectstoreConfig = configuration.createSubset(
-                    JDO_OBJECTSTORE_CONFIG_PREFIX);
+        final IsisConfiguration dataNucleusConfig = configuration.createSubset(DATANUCLEUS_CONFIG_PREFIX);
+        final Map<String, String> datanucleusProps = dataNucleusConfig.asMap();
+        addDataNucleusPropertiesIfRequired(datanucleusProps);
 
-            final IsisConfiguration dataNucleusConfig = configuration.createSubset(DATANUCLEUS_CONFIG_PREFIX);
-            final Map<String, String> datanucleusProps = dataNucleusConfig.asMap();
-            addDataNucleusPropertiesIfRequired(datanucleusProps);
-
-            DataNucleusApplicationComponents5 applicationComponents1 = 
-                    new DataNucleusApplicationComponents5(jdoObjectstoreConfig,
-                            datanucleusProps, classesToBePersisted);
-            
-            this.applicationComponents = applicationComponents1;
-        }
-
-        return applicationComponents;
-    }
-    
-    private boolean shouldCreate(final DataNucleusApplicationComponents5 applicationComponents) {
-        return applicationComponents == null || applicationComponents.isStale();
+        return new DataNucleusApplicationComponents5(jdoObjectstoreConfig,
+                        datanucleusProps, classesToBePersisted);
     }
 
     private static void addDataNucleusPropertiesIfRequired(
@@ -169,10 +155,11 @@ implements PersistenceSessionFactory, ApplicationScopedComponent, FixturesInstal
         if(!isInitialized()) {
             return;
         }
-        if(applicationComponents != null) {
-            applicationComponents.shutdown();
-            applicationComponents = null;
+        if(applicationComponents.isMemoized()) {
+            applicationComponents.get().shutdown();
+            applicationComponents.clear();
         }
+        this.configuration = null;
     }
 
     /**
@@ -184,9 +171,15 @@ implements PersistenceSessionFactory, ApplicationScopedComponent, FixturesInstal
             final ServicesInjector servicesInjector,
             final AuthenticationSession authenticationSession) {
 
+        Objects.requireNonNull(applicationComponents, "PersistenceSession5 requires initialization. "+this.hashCode());
+        
         final FixturesInstalledFlag fixturesInstalledFlag = this;
+        
+        //[ahuber] if stale force recreate
+        guardAgainstStaleState();
+        
         final PersistenceManagerFactory persistenceManagerFactory =
-                applicationComponents.getPersistenceManagerFactory();
+                applicationComponents.get().getPersistenceManagerFactory();
 
         return new PersistenceSession5(
                 servicesInjector,
@@ -207,6 +200,18 @@ implements PersistenceSessionFactory, ApplicationScopedComponent, FixturesInstal
     public void setFixturesInstalled(final Boolean fixturesInstalled) {
         this.fixturesInstalled = fixturesInstalled;
     }
+    
+    // [ahuber] JRebel support, not tested at all
+    private void guardAgainstStaleState() {
+        if(applicationComponents.get().isStale()) {
+            try {
+                applicationComponents.get().shutdown();
+            } catch (Exception e) {
+                // ignore
+            }
+            applicationComponents.clear();
+        }
+    }
 
 
 }


[isis] 01/02: ISIS-1895: fix class-loader initialization for skinny-war scenario

Posted by ah...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

ahuber pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/isis.git

commit 682091b20cb67aee4c56c014506cdb86afe61359
Author: Andi Huber <ah...@apache.org>
AuthorDate: Tue Sep 4 20:01:57 2018 +0200

    ISIS-1895: fix class-loader initialization for skinny-war scenario
    
    also removes the @WebListener annotation, to not force the underlying
    WebContextListener upon users
    
    Task-Url: https://issues.apache.org/jira/browse/ISIS-1895
---
 .../apache/isis/core/webapp/IsisWebAppContextListener.java  | 13 ++++++++-----
 .../isis/viewer/wicket/viewer/IsisWicketApplication.java    | 10 ++++++++--
 2 files changed, 16 insertions(+), 7 deletions(-)

diff --git a/core/runtime/src/main/java/org/apache/isis/core/webapp/IsisWebAppContextListener.java b/core/runtime/src/main/java/org/apache/isis/core/webapp/IsisWebAppContextListener.java
index a0bc0ee..b882ce9 100644
--- a/core/runtime/src/main/java/org/apache/isis/core/webapp/IsisWebAppContextListener.java
+++ b/core/runtime/src/main/java/org/apache/isis/core/webapp/IsisWebAppContextListener.java
@@ -19,7 +19,6 @@
 package org.apache.isis.core.webapp;
 
 import static org.apache.isis.commons.internal.base._With.acceptIfPresent;
-import static org.apache.isis.commons.internal.context._Context.setDefaultClassLoader;
 import static org.apache.isis.commons.internal.resources._Resource.putContextPathIfPresent;
 
 import java.util.ArrayList;
@@ -30,11 +29,11 @@ import javax.servlet.ServletContext;
 import javax.servlet.ServletContextEvent;
 import javax.servlet.ServletContextListener;
 import javax.servlet.ServletException;
-import javax.servlet.annotation.WebListener;
 
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import org.apache.isis.commons.internal.context._Context;
 import org.apache.isis.core.webapp.modules.WebModule;
 
 /**
@@ -47,10 +46,11 @@ import org.apache.isis.core.webapp.modules.WebModule;
  * Installs {@link WebModule}s on the ServletContext. 
  * </p>   
  *  
- * @since 2.0.0
+ * @since 2.0.0-M2
  *
  */
-@WebListener
+//@WebListener //[ahuber] to support Servlet 3.0 annotations @WebFilter, @WebListener or others 
+//with skinny war deployment requires additional configuration, so for now we disable this annotation
 public class IsisWebAppContextListener implements ServletContextListener {
     
     private static final Logger LOG = LoggerFactory.getLogger(IsisWebAppContextListener.class);
@@ -65,8 +65,11 @@ public class IsisWebAppContextListener implements ServletContextListener {
         final ServletContext servletContext = event.getServletContext();
         
         LOG.info("=== PHASE 1 === Setting up ServletContext parameters");
+  
+        //[ahuber] set the ServletContext initializing thread as preliminary default until overridden by
+        // IsisWicketApplication#init() or others that better know what ClassLoader to use as application default.
+        _Context.setDefaultClassLoader(Thread.currentThread().getContextClassLoader(), false);
         
-        setDefaultClassLoader(this.getClass().getClassLoader(), true);
         putContextPathIfPresent(servletContext.getContextPath());
         
         final IsisWebAppConfigProvider configProvider = new IsisWebAppConfigProvider();
diff --git a/core/viewer-wicket-impl/src/main/java/org/apache/isis/viewer/wicket/viewer/IsisWicketApplication.java b/core/viewer-wicket-impl/src/main/java/org/apache/isis/viewer/wicket/viewer/IsisWicketApplication.java
index 66de39a..7f64bcc 100644
--- a/core/viewer-wicket-impl/src/main/java/org/apache/isis/viewer/wicket/viewer/IsisWicketApplication.java
+++ b/core/viewer-wicket-impl/src/main/java/org/apache/isis/viewer/wicket/viewer/IsisWicketApplication.java
@@ -75,6 +75,7 @@ import org.slf4j.LoggerFactory;
 import org.wicketstuff.select2.ApplicationSettings;
 
 import org.apache.isis.commons.internal.collections._Lists;
+import org.apache.isis.commons.internal.context._Context;
 import org.apache.isis.core.commons.authentication.AuthenticationSession;
 import org.apache.isis.core.commons.config.IsisConfiguration;
 import org.apache.isis.core.commons.config.IsisConfigurationDefault;
@@ -133,7 +134,7 @@ import net.ftlines.wicketsource.WicketSource;
  *
  * <p>
  * Its main responsibility is to allow the set of {@link ComponentFactory}s used
- * to render the domain objects to be registered. This type of customisation is
+ * to render the domain objects to be registered. This type of customization is
  * common place. At a more fundamental level, also allows the {@link Page}
  * implementation for each {@link PageType page type} to be overridden. This is
  * probably less common, because CSS can also be used for this purpose.
@@ -147,7 +148,7 @@ import net.ftlines.wicketsource.WicketSource;
  * make the {@link ComponentFactory} defined within it available.
  *
  * <p>
- * Alternatively, {@link ComponentFactory}s can be specified by overridding {@link #newIsisWicketModule()}.
+ * Alternatively, {@link ComponentFactory}s can be specified by overriding {@link #newIsisWicketModule()}.
  * This mechanism allows a number of other aspects to be customized.
  */
 public class IsisWicketApplication
@@ -302,6 +303,11 @@ implements ComponentFactoryRegistryAccessor, PageClassRegistryAccessor, WicketVi
      */
     @Override
     protected void init() {
+        
+        //[ahuber] the implementing class is assumed to be loaded be a class-loader
+        // that's suitable for the entire web-application to use as default.
+        _Context.setDefaultClassLoader(this.getClass().getClassLoader(), true);
+        
         List<Future<Object>> futures = null;
         try {
             super.init();