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 2019/05/10 09:11:19 UTC
[isis] branch 2112_SpringBoot updated (fe515a4 -> ef099bd)
This is an automated email from the ASF dual-hosted git repository.
ahuber pushed a change to branch 2112_SpringBoot
in repository https://gitbox.apache.org/repos/asf/isis.git.
from fe515a4 ISIS-2112: workaround events not working during bootstrapping
new 073e51a ISIS-2112: moving some services to 'runtime-services'
new ef099bd ISIS-2112: convert IsisSessionFactoryDefault to spring-managed singleton
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:
.../isis/applib/services/clock/ClockService.java | 18 +-
.../isis/tool/mavenplugin/IsisMojoAbstract.java | 6 +-
.../PersistenceSessionServiceInternal.java | 21 --
.../isis/core/runtime/headless/IsisSystem.java | 5 +-
.../bookmarks/BookmarkServiceInternalDefault.java | 2 +-
.../confmenu}/ConfigurationViewServiceDefault.java | 2 +-
.../factory/FactoryServiceInternalDefault.java | 9 +-
.../runtime/system/session/IsisSessionFactory.java | 3 +-
.../system/session/IsisSessionFactoryBuilder.java | 160 --------------
.../system/session/IsisSessionFactoryDefault.java | 230 ++++++++++++++-------
.../system/session/IsisSessionProducerBean.java | 101 ---------
.../session/SpecificationLoaderProducerBean.java | 57 +++++
12 files changed, 237 insertions(+), 377 deletions(-)
rename core/{metamodel/src/main/java/org/apache/isis/core/metamodel => runtime-services/src/main/java/org/apache/isis/core/runtime}/services/bookmarks/BookmarkServiceInternalDefault.java (99%)
rename core/{config/src/main/java/org/apache/isis/config/services/view => runtime-services/src/main/java/org/apache/isis/core/runtime/services/confmenu}/ConfigurationViewServiceDefault.java (98%)
rename core/{metamodel/src/main/java/org/apache/isis/core/metamodel => runtime-services/src/main/java/org/apache/isis/core/runtime}/services/factory/FactoryServiceInternalDefault.java (95%)
delete mode 100644 core/runtime/src/main/java/org/apache/isis/core/runtime/system/session/IsisSessionFactoryBuilder.java
delete mode 100644 core/runtime/src/main/java/org/apache/isis/core/runtime/system/session/IsisSessionProducerBean.java
create mode 100644 core/runtime/src/main/java/org/apache/isis/core/runtime/system/session/SpecificationLoaderProducerBean.java
[isis] 01/02: ISIS-2112: moving some services to 'runtime-services'
Posted by ah...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
ahuber pushed a commit to branch 2112_SpringBoot
in repository https://gitbox.apache.org/repos/asf/isis.git
commit 073e51a4443c9cf52f1d046a068e343fff3b39b9
Author: Andi Huber <ah...@apache.org>
AuthorDate: Fri May 10 10:19:48 2019 +0200
ISIS-2112: moving some services to 'runtime-services'
Task-Url: https://issues.apache.org/jira/browse/ISIS-2112
---
.../isis/applib/services/clock/ClockService.java | 18 +++---------------
.../PersistenceSessionServiceInternal.java | 21 ---------------------
.../bookmarks/BookmarkServiceInternalDefault.java | 2 +-
.../confmenu}/ConfigurationViewServiceDefault.java | 2 +-
.../factory/FactoryServiceInternalDefault.java | 9 ++++++---
5 files changed, 11 insertions(+), 41 deletions(-)
diff --git a/core/applib/src/main/java/org/apache/isis/applib/services/clock/ClockService.java b/core/applib/src/main/java/org/apache/isis/applib/services/clock/ClockService.java
index c1ef0bc..7359608 100644
--- a/core/applib/src/main/java/org/apache/isis/applib/services/clock/ClockService.java
+++ b/core/applib/src/main/java/org/apache/isis/applib/services/clock/ClockService.java
@@ -18,13 +18,12 @@ package org.apache.isis.applib.services.clock;
import java.sql.Timestamp;
+import javax.inject.Singleton;
+
import org.joda.time.DateTime;
import org.joda.time.LocalDate;
import org.joda.time.LocalDateTime;
-import org.apache.isis.applib.annotation.DomainService;
-import org.apache.isis.applib.annotation.NatureOfService;
-import org.apache.isis.applib.annotation.Programmatic;
import org.apache.isis.applib.clock.Clock;
/**
@@ -32,37 +31,26 @@ import org.apache.isis.applib.clock.Clock;
* testing scenarios, to "mock the clock". Use of this service also opens up the use of centralized
* co-ordinated time management through a centralized time service.
*
- * <p>
- * This service has only one implementation and so is automatically registered. and available for use; no further
- * configuration is required.
*/
-@DomainService(
- nature = NatureOfService.DOMAIN,
- menuOrder = "" + Integer.MAX_VALUE
- )
+@Singleton
public class ClockService {
- @Programmatic
public LocalDate now() {
return Clock.getTimeAsLocalDate();
}
- @Programmatic
public LocalDateTime nowAsLocalDateTime() {
return Clock.getTimeAsLocalDateTime();
}
- @Programmatic
public DateTime nowAsDateTime() {
return Clock.getTimeAsDateTime();
}
- @Programmatic
public Timestamp nowAsJavaSqlTimestamp() {
return Clock.getTimeAsJavaSqlTimestamp();
}
- @Programmatic
public long nowAsMillis() {
return Clock.getTime();
}
diff --git a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/services/persistsession/PersistenceSessionServiceInternal.java b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/services/persistsession/PersistenceSessionServiceInternal.java
index 11b2c98..1f60330 100644
--- a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/services/persistsession/PersistenceSessionServiceInternal.java
+++ b/core/metamodel/src/main/java/org/apache/isis/core/metamodel/services/persistsession/PersistenceSessionServiceInternal.java
@@ -20,7 +20,6 @@ import java.util.List;
import java.util.concurrent.CountDownLatch;
import java.util.function.Supplier;
-import org.apache.isis.applib.annotation.Programmatic;
import org.apache.isis.applib.query.Query;
import org.apache.isis.applib.services.bookmark.Bookmark;
import org.apache.isis.applib.services.bookmark.BookmarkService;
@@ -41,10 +40,8 @@ public interface PersistenceSessionServiceInternal extends ObjectAdapterProvider
* <p>
* Called by <tt>DomainObjectContainerDefault</tt>.
*/
- @Programmatic
ObjectAdapter createTransientInstance(ObjectSpecification spec);
- @Programmatic
ObjectAdapter createViewModelInstance(ObjectSpecification spec, String memento);
// -- retrieve
@@ -55,7 +52,6 @@ public interface PersistenceSessionServiceInternal extends ObjectAdapterProvider
* <p>
* Called by <tt>DomainObjectContainerDefault</tt>.
*/
- @Programmatic
void resolve(Object parent);
/**
@@ -65,21 +61,16 @@ public interface PersistenceSessionServiceInternal extends ObjectAdapterProvider
* Called by <tt>BookmarkServicesDefault</tt>.
* @return
*/
- @Programmatic
Object lookup(Bookmark bookmark, final BookmarkService.FieldResetPolicy fieldResetPolicy);
- @Programmatic
Bookmark bookmarkFor(Object domainObject);
- @Programmatic
Bookmark bookmarkFor(Class<?> cls, String identifier);
// -- beginTran, flush, commit, currentTransaction
- @Programmatic
void beginTran();
- @Programmatic
void beginTran(final Command commandIfAny);
/**
@@ -88,7 +79,6 @@ public interface PersistenceSessionServiceInternal extends ObjectAdapterProvider
* <p>
* Called by <tt>DomainObjectContainerDefault</tt>.
*/
- @Programmatic
boolean flush();
/**
@@ -97,19 +87,14 @@ public interface PersistenceSessionServiceInternal extends ObjectAdapterProvider
* <p>
* Called by <tt>DomainObjectContainerDefault</tt>.
*/
- @Programmatic
void commit();
- @Programmatic
void abortTransaction();
- @Programmatic
Transaction currentTransaction();
- @Programmatic
CountDownLatch currentTransactionLatch();
- @Programmatic
TransactionState getTransactionState();
// -- makePersistent, remove
@@ -121,7 +106,6 @@ public interface PersistenceSessionServiceInternal extends ObjectAdapterProvider
* Called by <tt>DomainObjectContainerDefault</tt> and also by
* <tt>DomainObjectInvocationHandler#handleSaveMethod()</tt>.
*/
- @Programmatic
void makePersistent(ObjectAdapter adapter);
/**
@@ -131,7 +115,6 @@ public interface PersistenceSessionServiceInternal extends ObjectAdapterProvider
* <p>
* Called by <tt>DomainObjectContainerDefault</tt>.
*/
- @Programmatic
void remove(ObjectAdapter adapter);
// -- allMatchingQuery, firstMatchingQuery
@@ -142,7 +125,6 @@ public interface PersistenceSessionServiceInternal extends ObjectAdapterProvider
* Called by <tt>DomainObjectContainerDefault</tt> and also by the choices
* facets.
*/
- @Programmatic
<T> List<ObjectAdapter> allMatchingQuery(Query<T> query);
/**
@@ -151,13 +133,10 @@ public interface PersistenceSessionServiceInternal extends ObjectAdapterProvider
* <p>
* Called by <tt>DomainObjectContainerDefault</tt>.
*/
- @Programmatic
<T> ObjectAdapter firstMatchingQuery(Query<T> query);
- @Programmatic
void executeWithinTransaction(Runnable task);
- @Programmatic
<T> T executeWithinTransaction(Supplier<T> task);
}
diff --git a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/services/bookmarks/BookmarkServiceInternalDefault.java b/core/runtime-services/src/main/java/org/apache/isis/core/runtime/services/bookmarks/BookmarkServiceInternalDefault.java
similarity index 99%
rename from core/metamodel/src/main/java/org/apache/isis/core/metamodel/services/bookmarks/BookmarkServiceInternalDefault.java
rename to core/runtime-services/src/main/java/org/apache/isis/core/runtime/services/bookmarks/BookmarkServiceInternalDefault.java
index 764448a..f06c467 100644
--- a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/services/bookmarks/BookmarkServiceInternalDefault.java
+++ b/core/runtime-services/src/main/java/org/apache/isis/core/runtime/services/bookmarks/BookmarkServiceInternalDefault.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.apache.isis.core.metamodel.services.bookmarks;
+package org.apache.isis.core.runtime.services.bookmarks;
import java.io.Serializable;
import java.math.BigDecimal;
diff --git a/core/config/src/main/java/org/apache/isis/config/services/view/ConfigurationViewServiceDefault.java b/core/runtime-services/src/main/java/org/apache/isis/core/runtime/services/confmenu/ConfigurationViewServiceDefault.java
similarity index 98%
rename from core/config/src/main/java/org/apache/isis/config/services/view/ConfigurationViewServiceDefault.java
rename to core/runtime-services/src/main/java/org/apache/isis/core/runtime/services/confmenu/ConfigurationViewServiceDefault.java
index e68100c..d02a05c 100644
--- a/core/config/src/main/java/org/apache/isis/config/services/view/ConfigurationViewServiceDefault.java
+++ b/core/runtime-services/src/main/java/org/apache/isis/core/runtime/services/confmenu/ConfigurationViewServiceDefault.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.apache.isis.config.services.view;
+package org.apache.isis.core.runtime.services.confmenu;
import java.util.HashMap;
import java.util.Map;
diff --git a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/services/factory/FactoryServiceInternalDefault.java b/core/runtime-services/src/main/java/org/apache/isis/core/runtime/services/factory/FactoryServiceInternalDefault.java
similarity index 95%
rename from core/metamodel/src/main/java/org/apache/isis/core/metamodel/services/factory/FactoryServiceInternalDefault.java
rename to core/runtime-services/src/main/java/org/apache/isis/core/runtime/services/factory/FactoryServiceInternalDefault.java
index f1080b4..c13bc03 100644
--- a/core/metamodel/src/main/java/org/apache/isis/core/metamodel/services/factory/FactoryServiceInternalDefault.java
+++ b/core/runtime-services/src/main/java/org/apache/isis/core/runtime/services/factory/FactoryServiceInternalDefault.java
@@ -17,7 +17,7 @@
* under the License.
*/
-package org.apache.isis.core.metamodel.services.factory;
+package org.apache.isis.core.runtime.services.factory;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
@@ -34,11 +34,11 @@ import org.apache.isis.core.metamodel.facets.object.mixin.MixinFacet;
import org.apache.isis.core.metamodel.services.persistsession.PersistenceSessionServiceInternal;
import org.apache.isis.core.metamodel.spec.ObjectSpecification;
import org.apache.isis.core.metamodel.specloader.SpecificationLoader;
+import org.apache.isis.core.runtime.system.session.IsisSessionFactory;
-@Singleton
+@Singleton
public class FactoryServiceInternalDefault implements FactoryService {
-
@Override
@SuppressWarnings("unchecked")
public <T> T instantiate(final Class<T> domainClass) {
@@ -90,6 +90,9 @@ public class FactoryServiceInternalDefault implements FactoryService {
}
@javax.inject.Inject
+ IsisSessionFactory isisSessionFactory; // dependsOn
+
+ @javax.inject.Inject
SpecificationLoader specificationLoader;
@javax.inject.Inject
[isis] 02/02: ISIS-2112: convert IsisSessionFactoryDefault to
spring-managed singleton
Posted by ah...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
ahuber pushed a commit to branch 2112_SpringBoot
in repository https://gitbox.apache.org/repos/asf/isis.git
commit ef099bd4ae20245cf01a54fb07a0bb85ae84885a
Author: Andi Huber <ah...@apache.org>
AuthorDate: Fri May 10 11:11:12 2019 +0200
ISIS-2112: convert IsisSessionFactoryDefault to spring-managed singleton
Task-Url: https://issues.apache.org/jira/browse/ISIS-2112
---
.../isis/tool/mavenplugin/IsisMojoAbstract.java | 6 +-
.../isis/core/runtime/headless/IsisSystem.java | 5 +-
.../runtime/system/session/IsisSessionFactory.java | 3 +-
.../system/session/IsisSessionFactoryBuilder.java | 160 --------------
.../system/session/IsisSessionFactoryDefault.java | 230 ++++++++++++++-------
.../system/session/IsisSessionProducerBean.java | 101 ---------
.../session/SpecificationLoaderProducerBean.java | 57 +++++
7 files changed, 226 insertions(+), 336 deletions(-)
diff --git a/core/maven-plugin/src/main/java/org/apache/isis/tool/mavenplugin/IsisMojoAbstract.java b/core/maven-plugin/src/main/java/org/apache/isis/tool/mavenplugin/IsisMojoAbstract.java
index a2b0f43..eadd920 100644
--- a/core/maven-plugin/src/main/java/org/apache/isis/tool/mavenplugin/IsisMojoAbstract.java
+++ b/core/maven-plugin/src/main/java/org/apache/isis/tool/mavenplugin/IsisMojoAbstract.java
@@ -38,7 +38,6 @@ import org.apache.isis.core.plugins.environment.IsisSystemEnvironment;
import org.apache.isis.core.runtime.logging.IsisLoggingConfigurer;
import org.apache.isis.core.runtime.system.context.IsisContext;
import org.apache.isis.core.runtime.system.session.IsisSessionFactory;
-import org.apache.isis.core.runtime.system.session.IsisSessionProducerBean;
import org.apache.isis.tool.mavenplugin.util.MavenProjects;
import lombok.val;
@@ -69,10 +68,11 @@ public abstract class IsisMojoAbstract extends AbstractMojo {
final AppManifest appManifest = InstanceUtil.createInstance(this.appManifest, AppManifest.class);
IsisConfiguration.buildFromAppManifest(appManifest); // build and finalize config
- IsisSessionFactory isisSessionFactory = null;
+ val isisSessionFactory = IsisContext.getSessionFactory();
try {
- isisSessionFactory = new IsisSessionProducerBean().produceIsisSessionFactory();
+ isisSessionFactory.initServicesAndRunFixtures();
+
val metaModelDeficiencies = IsisContext.getMetaModelDeficienciesIfAny();
if(metaModelDeficiencies!=null) {
Set<String> validationErrors = metaModelDeficiencies.getValidationErrors();
diff --git a/core/runtime-extensions/src/main/java/org/apache/isis/core/runtime/headless/IsisSystem.java b/core/runtime-extensions/src/main/java/org/apache/isis/core/runtime/headless/IsisSystem.java
index a37ffcc..40c533d 100644
--- a/core/runtime-extensions/src/main/java/org/apache/isis/core/runtime/headless/IsisSystem.java
+++ b/core/runtime-extensions/src/main/java/org/apache/isis/core/runtime/headless/IsisSystem.java
@@ -31,7 +31,6 @@ import org.apache.isis.config.IsisConfiguration;
import org.apache.isis.core.runtime.headless.auth.AuthenticationRequestNameOnly;
import org.apache.isis.core.runtime.system.context.IsisContext;
import org.apache.isis.core.runtime.system.session.IsisSessionFactory;
-import org.apache.isis.core.runtime.system.session.IsisSessionProducerBean;
import org.apache.isis.core.security.authentication.AuthenticationRequest;
import org.apache.isis.core.security.authentication.AuthenticationSession;
import org.apache.isis.core.security.authentication.manager.AuthenticationManager;
@@ -127,7 +126,9 @@ public final class IsisSystem {
// as a side-effect bootstrap CDI, if the environment we are running on does not already have its own
_Blackhole.consume(AppConfigLocator.getAppConfig());
- isisSessionFactory = new IsisSessionProducerBean().produceIsisSessionFactory();
+ isisSessionFactory = IsisContext.getSessionFactory();
+
+ isisSessionFactory.initServicesAndRunFixtures();
// REVIEW: does no harm, but is this required?
closeSession();
diff --git a/core/runtime/src/main/java/org/apache/isis/core/runtime/system/session/IsisSessionFactory.java b/core/runtime/src/main/java/org/apache/isis/core/runtime/system/session/IsisSessionFactory.java
index c628105..2c950b4 100644
--- a/core/runtime/src/main/java/org/apache/isis/core/runtime/system/session/IsisSessionFactory.java
+++ b/core/runtime/src/main/java/org/apache/isis/core/runtime/system/session/IsisSessionFactory.java
@@ -24,11 +24,11 @@ import java.util.concurrent.Callable;
import javax.inject.Inject;
import org.apache.isis.applib.services.inject.ServiceInjector;
+import org.apache.isis.core.commons.components.ApplicationScopedComponent;
import org.apache.isis.core.metamodel.specloader.SpecificationLoader;
import org.apache.isis.core.runtime.system.internal.InitialisationSession;
import org.apache.isis.core.security.authentication.AuthenticationSession;
import org.apache.isis.core.security.authentication.manager.AuthenticationManager;
-import org.apache.isis.core.security.authorization.manager.AuthorizationManager;
/**
* Is the factory of {@link IsisSession}s, also holding a reference to the current session using
@@ -46,6 +46,7 @@ import org.apache.isis.core.security.authorization.manager.AuthorizationManager;
*/
public interface IsisSessionFactory {
+ public void initServicesAndRunFixtures();
public void destroyServicesAndShutdown();
public IsisSession openSession(final AuthenticationSession authenticationSession);
diff --git a/core/runtime/src/main/java/org/apache/isis/core/runtime/system/session/IsisSessionFactoryBuilder.java b/core/runtime/src/main/java/org/apache/isis/core/runtime/system/session/IsisSessionFactoryBuilder.java
deleted file mode 100644
index 362b998..0000000
--- a/core/runtime/src/main/java/org/apache/isis/core/runtime/system/session/IsisSessionFactoryBuilder.java
+++ /dev/null
@@ -1,160 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.isis.core.runtime.system.session;
-
-import java.io.File;
-import java.util.Arrays;
-import java.util.List;
-import java.util.concurrent.Callable;
-import java.util.concurrent.Future;
-
-import org.apache.isis.applib.clock.Clock;
-import org.apache.isis.applib.fixtures.FixtureClock;
-import org.apache.isis.commons.internal.context._Context;
-import org.apache.isis.config.IsisConfiguration;
-import org.apache.isis.config.internal._Config;
-import org.apache.isis.core.runtime.system.context.IsisContext;
-import org.apache.isis.core.runtime.system.context.session.RuntimeEventService;
-import org.apache.isis.core.runtime.system.internal.IsisLocaleInitializer;
-import org.apache.isis.core.runtime.system.internal.IsisTimeZoneInitializer;
-import org.apache.isis.core.runtime.threadpool.ThreadPoolSupport;
-import org.apache.isis.schema.utils.ChangesDtoUtils;
-import org.apache.isis.schema.utils.CommandDtoUtils;
-import org.apache.isis.schema.utils.InteractionDtoUtils;
-
-import lombok.val;
-import lombok.extern.slf4j.Slf4j;
-
-@Slf4j
-class IsisSessionFactoryBuilder {
-
- // -- constructors, accessors
-
- private final IsisLocaleInitializer localeInitializer;
- private final IsisTimeZoneInitializer timeZoneInitializer;
-
- public IsisSessionFactoryBuilder() {
- this.localeInitializer = new IsisLocaleInitializer();
- this.timeZoneInitializer = new IsisTimeZoneInitializer();
- }
-
- // -- buildSessionFactory
-
- public IsisSessionFactory buildSessionFactory() {
-
- log.info("initialising Isis System");
- log.info("working directory: {}", new File(".").getAbsolutePath());
-
- final IsisConfiguration configuration = _Config.getConfiguration();
- log.info("resource stream source: {}", configuration.getResourceStreamSource());
-
- localeInitializer.initLocale(configuration);
- timeZoneInitializer.initTimeZone(configuration);
-
- // a bit of a workaround, but required if anything in the metamodel (for example, a
- // ValueSemanticsProvider for a date value type) needs to use the Clock singleton
- // we do this after loading the services to allow a service to prime a different clock
- // implementation (eg to use an NTP time service).
- if (_Context.isPrototyping() && !Clock.isInitialized()) {
- FixtureClock.initialize();
- }
-
- val serviceRegistry = IsisContext.getServiceRegistry();
- val authenticationManager = IsisContext.getAuthenticationManager();
- val authorizationManager = IsisContext.getAuthorizationManager();
- val runtimeEventService = serviceRegistry.lookupServiceElseFail(RuntimeEventService.class);
-
- serviceRegistry.validateServices();
-
- val specificationLoader = IsisContext.getSpecificationLoader();
-
- // instantiate the IsisSessionFactory
- val isisSessionFactory = new IsisSessionFactoryDefault();
- isisSessionFactory.initDependencies(specificationLoader);
-
- // ... and make IsisSessionFactory available via the IsisContext static for those
- // places where we cannot yet inject.
-
- _Context.putSingleton(IsisSessionFactory.class, isisSessionFactory);
-
- runtimeEventService.fireAppPreMetamodel();
-
- val tasks = Arrays.asList(
- callableOf("SpecificationLoader.init()", ()->{
- // time to initialize...
- specificationLoader.init();
-
- // we need to do this before checking if the metamodel is valid.
- //
- // eg ActionChoicesForCollectionParameterFacetFactory metamodel validator requires a runtime...
- // at o.a.i.core.metamodel.specloader.specimpl.ObjectActionContributee.getServiceAdapter(ObjectActionContributee.java:287)
- // at o.a.i.core.metamodel.specloader.specimpl.ObjectActionContributee.determineParameters(ObjectActionContributee.java:138)
- // at o.a.i.core.metamodel.specloader.specimpl.ObjectActionDefault.getParameters(ObjectActionDefault.java:182)
- // at o.a.i.core.metamodel.facets.actions.action.ActionChoicesForCollectionParameterFacetFactory$1.validate(ActionChoicesForCollectionParameterFacetFactory.java:85)
- // at o.a.i.core.metamodel.facets.actions.action.ActionChoicesForCollectionParameterFacetFactory$1.visit(ActionChoicesForCollectionParameterFacetFactory.java:76)
- // at o.a.i.core.metamodel.specloader.validator.MetaModelValidatorVisiting.validate(MetaModelValidatorVisiting.java:47)
- //
- // also, required so that can still call isisSessionFactory#doInSession
- //
- // eg todoapp has a custom UserSettingsThemeProvider that is called when rendering any page
- // (including the metamodel invalid page)
- // at o.a.i.core.runtime.system.session.IsisSessionFactory.doInSession(IsisSessionFactory.java:327)
- // at todoapp.webapp.UserSettingsThemeProvider.getActiveTheme(UserSettingsThemeProvider.java:36)
-
- authenticationManager.init();
- authorizationManager.init();
- }),
- //callableOf("PersistenceSessionFactory.init()", persistenceSessionFactory::init),
- callableOf("ChangesDtoUtils.init()", ChangesDtoUtils::init),
- callableOf("InteractionDtoUtils.init()", InteractionDtoUtils::init),
- callableOf("CommandDtoUtils.init()", CommandDtoUtils::init)
- );
-
- // execute tasks using a thread-pool
- final List<Future<Object>> futures = ThreadPoolSupport.getInstance().invokeAll(tasks);
- // wait on this thread for tasks to complete
- ThreadPoolSupport.getInstance().joinGatherFailures(futures);
-
- runtimeEventService.fireAppPostMetamodel();
-
- isisSessionFactory.init();
-
- //runtimeEventService.fireAppPostConstruct();
-
- return isisSessionFactory;
- }
-
- // private static Collection<MetaModelRefiner> refiners(Object... possibleRefiners ) {
- // return ListExtensions.filtered(Arrays.asList(possibleRefiners), MetaModelRefiner.class);
- // }
-
- private static Callable<Object> callableOf(String label, Runnable action) {
- return new Callable<Object>() {
- @Override public Object call() throws Exception {
- action.run();
- return null;
- }
- public String toString() {
- return label;
- }
- };
- }
-
-}
diff --git a/core/runtime/src/main/java/org/apache/isis/core/runtime/system/session/IsisSessionFactoryDefault.java b/core/runtime/src/main/java/org/apache/isis/core/runtime/system/session/IsisSessionFactoryDefault.java
index 49ebb8c..3a66029 100644
--- a/core/runtime/src/main/java/org/apache/isis/core/runtime/system/session/IsisSessionFactoryDefault.java
+++ b/core/runtime/src/main/java/org/apache/isis/core/runtime/system/session/IsisSessionFactoryDefault.java
@@ -19,40 +19,53 @@
package org.apache.isis.core.runtime.system.session;
+import java.io.File;
+import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
import java.util.concurrent.Callable;
+import java.util.concurrent.Future;
import java.util.stream.Stream;
+import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
-import javax.enterprise.inject.Vetoed;
import javax.inject.Inject;
+import javax.inject.Singleton;
+import org.apache.isis.applib.clock.Clock;
+import org.apache.isis.applib.fixtures.FixtureClock;
import org.apache.isis.applib.services.i18n.TranslationService;
-import org.apache.isis.applib.services.inject.ServiceInjector;
import org.apache.isis.applib.services.registry.ServiceRegistry;
import org.apache.isis.applib.services.title.TitleService;
import org.apache.isis.commons.internal.base._Blackhole;
import org.apache.isis.commons.internal.context._Context;
import org.apache.isis.commons.ioc.BeanAdapter;
import org.apache.isis.config.IsisConfiguration;
+import org.apache.isis.config.internal._Config;
import org.apache.isis.core.commons.collections.Bin;
import org.apache.isis.core.metamodel.spec.ObjectSpecification;
import org.apache.isis.core.metamodel.specloader.ServiceInitializer;
import org.apache.isis.core.metamodel.specloader.SpecificationLoader;
import org.apache.isis.core.runtime.fixtures.FixturesInstallerFromConfiguration;
+import org.apache.isis.core.runtime.system.IsisSystemException;
import org.apache.isis.core.runtime.system.MessageRegistry;
import org.apache.isis.core.runtime.system.context.IsisContext;
import org.apache.isis.core.runtime.system.context.session.RuntimeEventService;
import org.apache.isis.core.runtime.system.internal.InitialisationSession;
+import org.apache.isis.core.runtime.system.internal.IsisLocaleInitializer;
+import org.apache.isis.core.runtime.system.internal.IsisTimeZoneInitializer;
import org.apache.isis.core.runtime.system.transaction.IsisTransactionManager;
import org.apache.isis.core.runtime.system.transaction.IsisTransactionManagerException;
+import org.apache.isis.core.runtime.threadpool.ThreadPoolSupport;
import org.apache.isis.core.security.authentication.AuthenticationSession;
import org.apache.isis.core.security.authentication.manager.AuthenticationManager;
-import org.apache.isis.core.security.authorization.manager.AuthorizationManager;
+import org.apache.isis.schema.utils.ChangesDtoUtils;
+import org.apache.isis.schema.utils.CommandDtoUtils;
+import org.apache.isis.schema.utils.InteractionDtoUtils;
import lombok.val;
+import lombok.extern.slf4j.Slf4j;
/**
* Is the factory of {@link IsisSession}s, also holding a reference to the current session using
@@ -63,36 +76,102 @@ import lombok.val;
* <code>PersistenceManagerFactory</code>.
* </p>
*
- * <p>
- * The class is only instantiated once; it is also registered with {@link ServiceInjector}, meaning that
- * it can be {@link Inject}'d into other domain services.
- * </p>
*/
-@Vetoed // has a producer
+@Singleton @Slf4j
public class IsisSessionFactoryDefault implements IsisSessionFactory {
- private IsisConfiguration configuration;
- private ServiceInjector serviceInjector;
- private ServiceRegistry serviceRegistry;
+ @Inject private IsisConfiguration configuration;
+ @Inject private ServiceRegistry serviceRegistry;
+ @Inject private AuthenticationManager authenticationManager;
+ @Inject private RuntimeEventService runtimeEventService;
+
+ private IsisLocaleInitializer localeInitializer;
+ private IsisTimeZoneInitializer timeZoneInitializer;
private SpecificationLoader specificationLoader;
- private AuthenticationManager authenticationManager;
- private AuthorizationManager authorizationManager;
private ServiceInitializer serviceInitializer;
- private RuntimeEventService runtimeEventService;
-
- // called by builder
- void initDependencies(SpecificationLoader specificationLoader) {
- this.configuration = IsisContext.getConfiguration();
- this.serviceInjector = IsisContext.getServiceInjector();
- this.serviceRegistry = IsisContext.getServiceRegistry();
- this.authorizationManager = IsisContext.getAuthorizationManager();
- this.authenticationManager = IsisContext.getAuthenticationManager();
- this.specificationLoader = specificationLoader;
- this.runtimeEventService = serviceRegistry.lookupServiceElseFail(RuntimeEventService.class);
+
+ @PostConstruct
+ public void init() throws IsisSystemException {
+ this.localeInitializer = new IsisLocaleInitializer();
+ this.timeZoneInitializer = new IsisTimeZoneInitializer();
+
+ log.info("initialising Isis System");
+ log.info("working directory: {}", new File(".").getAbsolutePath());
+
+ final IsisConfiguration configuration = _Config.getConfiguration();
+ log.info("resource stream source: {}", configuration.getResourceStreamSource());
+
+ localeInitializer.initLocale(configuration);
+ timeZoneInitializer.initTimeZone(configuration);
+
+ // a bit of a workaround, but required if anything in the metamodel (for example, a
+ // ValueSemanticsProvider for a date value type) needs to use the Clock singleton
+ // we do this after loading the services to allow a service to prime a different clock
+ // implementation (eg to use an NTP time service).
+ if (_Context.isPrototyping() && !Clock.isInitialized()) {
+ FixtureClock.initialize();
+ }
+
+ val serviceRegistry = IsisContext.getServiceRegistry();
+ val authenticationManager = IsisContext.getAuthenticationManager();
+ val authorizationManager = IsisContext.getAuthorizationManager();
+ val runtimeEventService = serviceRegistry.lookupServiceElseFail(RuntimeEventService.class);
+
+ serviceRegistry.validateServices();
+
+ this.specificationLoader = new SpecificationLoaderFactory().createSpecificationLoader();
+
+ // ... and make IsisSessionFactory available via the IsisContext static for those
+ // places where we cannot yet inject.
+
+ _Context.putSingleton(SpecificationLoader.class, specificationLoader);
+ _Context.putSingleton(IsisSessionFactory.class, this);
+
+ runtimeEventService.fireAppPreMetamodel();
+
+ val tasks = Arrays.asList(
+ callableOf("SpecificationLoader.init()", ()->{
+ // time to initialize...
+ specificationLoader.init();
+
+ // we need to do this before checking if the metamodel is valid.
+ //
+ // eg ActionChoicesForCollectionParameterFacetFactory metamodel validator requires a runtime...
+ // at o.a.i.core.metamodel.specloader.specimpl.ObjectActionContributee.getServiceAdapter(ObjectActionContributee.java:287)
+ // at o.a.i.core.metamodel.specloader.specimpl.ObjectActionContributee.determineParameters(ObjectActionContributee.java:138)
+ // at o.a.i.core.metamodel.specloader.specimpl.ObjectActionDefault.getParameters(ObjectActionDefault.java:182)
+ // at o.a.i.core.metamodel.facets.actions.action.ActionChoicesForCollectionParameterFacetFactory$1.validate(ActionChoicesForCollectionParameterFacetFactory.java:85)
+ // at o.a.i.core.metamodel.facets.actions.action.ActionChoicesForCollectionParameterFacetFactory$1.visit(ActionChoicesForCollectionParameterFacetFactory.java:76)
+ // at o.a.i.core.metamodel.specloader.validator.MetaModelValidatorVisiting.validate(MetaModelValidatorVisiting.java:47)
+ //
+ // also, required so that can still call isisSessionFactory#doInSession
+ //
+ // eg todoapp has a custom UserSettingsThemeProvider that is called when rendering any page
+ // (including the metamodel invalid page)
+ // at o.a.i.core.runtime.system.session.IsisSessionFactory.doInSession(IsisSessionFactory.java:327)
+ // at todoapp.webapp.UserSettingsThemeProvider.getActiveTheme(UserSettingsThemeProvider.java:36)
+
+ authenticationManager.init();
+ authorizationManager.init();
+ }),
+ //callableOf("PersistenceSessionFactory.init()", persistenceSessionFactory::init),
+ callableOf("ChangesDtoUtils.init()", ChangesDtoUtils::init),
+ callableOf("InteractionDtoUtils.init()", InteractionDtoUtils::init),
+ callableOf("CommandDtoUtils.init()", CommandDtoUtils::init)
+ );
+
+ // execute tasks using a thread-pool
+ final List<Future<Object>> futures = ThreadPoolSupport.getInstance().invokeAll(tasks);
+ // wait on this thread for tasks to complete
+ ThreadPoolSupport.getInstance().joinGatherFailures(futures);
+
+ runtimeEventService.fireAppPostMetamodel();
+
+ initServicesAndRunFixtures();
}
- // called by builder
- void init() {
+ @Override
+ public void initServicesAndRunFixtures() {
// do postConstruct. We store the initializer to do preDestroy on shutdown
serviceInitializer = new ServiceInitializer(configuration,
@@ -156,7 +235,7 @@ public class IsisSessionFactoryDefault implements IsisSessionFactory {
final TranslationService translationService =
serviceRegistry.lookupServiceElseFail(TranslationService.class);
- final String context = IsisSessionFactoryBuilder.class.getName();
+ final String context = IsisSessionFactory.class.getName();
final MessageRegistry messageRegistry = new MessageRegistry();
final List<String> messages = messageRegistry.listMessages();
for (String message : messages) {
@@ -180,44 +259,12 @@ public class IsisSessionFactoryDefault implements IsisSessionFactory {
}
@PreDestroy
+ @Override
public void destroyServicesAndShutdown() {
destroyServices();
shutdown();
}
- private void destroyServices() {
- // may not be set if the metamodel validation failed during initialization
- if (serviceInitializer == null) {
- return;
- }
-
- // call @PreDestroy (in a session)
- openSession(new InitialisationSession());
- IsisTransactionManager transactionManager = getTransactionManagerElseFail();
- try {
- transactionManager.startTransaction();
- try {
-
- serviceInitializer.preDestroy();
-
- } catch (RuntimeException ex) {
- transactionManager.getCurrentTransaction().setAbortCause(
- new IsisTransactionManagerException(ex));
- } finally {
- // will commit or abort
- transactionManager.endTransaction();
- }
- } finally {
- closeSession();
- }
- }
-
- private void shutdown() {
- runtimeEventService.fireAppPreDestroy();
- authenticationManager.shutdown();
- specificationLoader.shutdown();
- }
-
// --
@Override
@@ -240,11 +287,6 @@ public class IsisSessionFactoryDefault implements IsisSessionFactory {
existingSessionIfAny.close();
}
- private IsisTransactionManager getTransactionManagerElseFail() {
- return IsisContext.getTransactionManager()
- .orElseThrow(()->new IllegalStateException("there is no TransactionManager currently accessible"));
- }
-
@Override
public boolean isInSession() {
return getCurrentSession() != null;
@@ -272,10 +314,9 @@ public class IsisSessionFactoryDefault implements IsisSessionFactory {
}
return callable.call();
- } catch (Exception x) {
- throw new RuntimeException(
- String.format("An error occurred while executing code in %s session", noSession ? "a temporary" : "a"),
- x);
+ } catch (Exception cause) {
+ val msg = String.format("An error occurred while executing code in %s session", noSession ? "a temporary" : "a");
+ throw new RuntimeException(msg, cause);
} finally {
if (noSession) {
sessionFactory.closeSession();
@@ -295,7 +336,58 @@ public class IsisSessionFactoryDefault implements IsisSessionFactory {
return authenticationManager;
}
+ // -- HELPER
+ private IsisTransactionManager getTransactionManagerElseFail() {
+ return IsisContext.getTransactionManager()
+ .orElseThrow(()->new IllegalStateException("there is no TransactionManager currently accessible"));
+ }
+
+ private void destroyServices() {
+ // may not be set if the metamodel validation failed during initialization
+ if (serviceInitializer == null) {
+ return;
+ }
+
+ // call @PreDestroy (in a session)
+ openSession(new InitialisationSession());
+ IsisTransactionManager transactionManager = getTransactionManagerElseFail();
+ try {
+ transactionManager.startTransaction();
+ try {
+
+ serviceInitializer.preDestroy();
+
+ } catch (RuntimeException ex) {
+ transactionManager.getCurrentTransaction().setAbortCause(
+ new IsisTransactionManagerException(ex));
+ } finally {
+ // will commit or abort
+ transactionManager.endTransaction();
+ }
+ } finally {
+ closeSession();
+ }
+ }
+
+ private void shutdown() {
+ runtimeEventService.fireAppPreDestroy();
+ authenticationManager.shutdown();
+ specificationLoader.shutdown();
+ }
+
+
+ private static Callable<Object> callableOf(String label, Runnable action) {
+ return new Callable<Object>() {
+ @Override public Object call() throws Exception {
+ action.run();
+ return null;
+ }
+ public String toString() {
+ return label;
+ }
+ };
+ }
}
diff --git a/core/runtime/src/main/java/org/apache/isis/core/runtime/system/session/IsisSessionProducerBean.java b/core/runtime/src/main/java/org/apache/isis/core/runtime/system/session/IsisSessionProducerBean.java
deleted file mode 100644
index 1a5bdd5..0000000
--- a/core/runtime/src/main/java/org/apache/isis/core/runtime/system/session/IsisSessionProducerBean.java
+++ /dev/null
@@ -1,101 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.isis.core.runtime.system.session;
-
-import javax.enterprise.inject.Produces;
-import javax.inject.Inject;
-import javax.inject.Singleton;
-
-import org.springframework.context.annotation.Bean;
-
-import org.apache.isis.applib.services.registry.ServiceRegistry;
-import org.apache.isis.commons.internal.base._Lazy;
-import org.apache.isis.commons.internal.context._Context;
-import org.apache.isis.commons.internal.debug._Probe;
-import org.apache.isis.commons.internal.exceptions._Exceptions;
-import org.apache.isis.core.metamodel.specloader.SpecificationLoader;
-import org.apache.isis.core.runtime.system.IsisSystemException;
-
-/**
- * @deprecated TODO [2033] convert ...
- * Currently `IsisSessionFactory` and those singletons that depend on it
- * (`SpecificationLoader` and `PersistenceSessionFactory`) are not life-cycle
- * managed by CDI, instead we provide Producer Methods for these.
- *
- * Consequently the framework is responsible for their life-cycles.
- *
- * We want to have CDI also manage these, which can be achieved by finally
- * removing the `IsisSessionProducerBean` singleton.
- *
- */
-@Singleton
-public class IsisSessionProducerBean {
-
- @Inject ServiceRegistry serviceRegistry; // depends on
-
- @Bean @Produces @Singleton //XXX note: the resulting singleton is not life-cycle managed by CDI/Spring, neither are InjectionPoints resolved by CDI/Spring
- public IsisSessionFactory produceIsisSessionFactory() {
- return _Context.computeIfAbsent(IsisSessionFactory.class, this::newIsisSessionFactory);
- }
-
- @Bean @Produces @Singleton //XXX note: the resulting singleton is not life-cycle managed by CDI/Spring, neither are InjectionPoints resolved by CDI/Spring
- public SpecificationLoader produceSpecificationLoader() throws IsisSystemException {
- return _Context.computeIfAbsent(SpecificationLoader.class, this::newSpecificationLoader);
- }
-
- // -- HELPER
-
-// private final _Lazy<IsisSessionFactory> isisSessionFactorySingleton =
-// _Lazy.threadSafe(this::newIsisSessionFactory);
-
- private final static _Probe probe = _Probe.maxCallsThenExitWithStacktrace(10).label("IsisSessionProducerBean");
-
- private SpecificationLoader newSpecificationLoader() {
- try {
- return new SpecificationLoaderFactory().createSpecificationLoader();
- } catch (IsisSystemException e) {
- throw _Exceptions.unrecoverable(e);
- }
- }
-
- private IsisSessionFactory newIsisSessionFactory() {
-
- try {
-
- probe.println("newIsisSessionFactory");
-
- final IsisSessionFactoryBuilder builder = new IsisSessionFactoryBuilder();
-
- // as a side-effect, if the metamodel turns out to be invalid, then
- // this will push the MetaModelInvalidException into IsisContext.
- return builder.buildSessionFactory();
-
- } catch (Exception e) {
- System.err.println(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
- e.printStackTrace();
- System.err.println("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<");
- System.exit(1);
- throw e;
- }
-
- }
-
-
-}
diff --git a/core/runtime/src/main/java/org/apache/isis/core/runtime/system/session/SpecificationLoaderProducerBean.java b/core/runtime/src/main/java/org/apache/isis/core/runtime/system/session/SpecificationLoaderProducerBean.java
new file mode 100644
index 0000000..4acaf7e
--- /dev/null
+++ b/core/runtime/src/main/java/org/apache/isis/core/runtime/system/session/SpecificationLoaderProducerBean.java
@@ -0,0 +1,57 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.isis.core.runtime.system.session;
+
+import javax.enterprise.inject.Produces;
+import javax.inject.Inject;
+import javax.inject.Singleton;
+
+import org.springframework.context.annotation.Bean;
+
+import org.apache.isis.commons.internal.context._Context;
+import org.apache.isis.core.metamodel.specloader.SpecificationLoader;
+import org.apache.isis.core.runtime.system.IsisSystemException;
+
+/**
+ * @deprecated TODO [2033] convert ...
+ * Currently `SpecificationLoader` is not life-cycle
+ * managed by CDI/Spring, instead we provide a 'Producer Method' for it.
+ *
+ * Consequently the framework is responsible for its life-cycle.
+ *
+ * We want to have CDI/Spring also manage these, which can be achieved by finally
+ * removing the `SpecificationLoaderProducerBean` singleton.
+ *
+ */
+@Singleton
+public class SpecificationLoaderProducerBean {
+
+ @Inject IsisSessionFactory isisSessionFactory; // depends on
+
+ // let Spring manage destruction , init is handled by isisSessionFactory internally
+ @Bean(destroyMethod = "shutdown")
+ @Produces @Singleton
+ //XXX note: the resulting singleton is not life-cycle managed by CDI/Spring,
+ //neither are InjectionPoints resolved by CDI/Spring
+ public SpecificationLoader produceSpecificationLoader() throws IsisSystemException {
+ return _Context.getElseFail(SpecificationLoader.class);
+ }
+
+}