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/09/30 19:01:31 UTC
[isis] branch v2 updated: ISIS-2158: re-wires the
RuntimeEventService, fixes sec-man seed
This is an automated email from the ASF dual-hosted git repository.
ahuber pushed a commit to branch v2
in repository https://gitbox.apache.org/repos/asf/isis.git
The following commit(s) were added to refs/heads/v2 by this push:
new 32bde33 ISIS-2158: re-wires the RuntimeEventService, fixes sec-man seed
32bde33 is described below
commit 32bde3302b1a98b8b672e7360b6f50e9f21c20cc
Author: Andi Huber <ah...@apache.org>
AuthorDate: Mon Sep 30 21:01:22 2019 +0200
ISIS-2158: re-wires the RuntimeEventService, fixes sec-man seed
- now that these events are fired only after the post-construct phase,
any managed service can reliably subscribe to these
- instead of seeding sec-man during post-construct, we do this
afterwards now
---
.../context/session/RuntimeEventService.java | 31 +++++++-----------
.../secman/jdo/seed/SeedSecurityModuleService.java | 38 +++++++++++++++++++---
2 files changed, 44 insertions(+), 25 deletions(-)
diff --git a/core/runtime/src/main/java/org/apache/isis/runtime/system/context/session/RuntimeEventService.java b/core/runtime/src/main/java/org/apache/isis/runtime/system/context/session/RuntimeEventService.java
index feb80f6..6d9f885 100644
--- a/core/runtime/src/main/java/org/apache/isis/runtime/system/context/session/RuntimeEventService.java
+++ b/core/runtime/src/main/java/org/apache/isis/runtime/system/context/session/RuntimeEventService.java
@@ -18,55 +18,46 @@
*/
package org.apache.isis.runtime.system.context.session;
-import javax.enterprise.event.Event;
import javax.inject.Inject;
import org.springframework.stereotype.Service;
-import org.apache.isis.runtime.system.persistence.JdoPersistenceLifecycleService;
+import org.apache.isis.applib.services.eventbus.EventBusService;
import org.apache.isis.runtime.system.session.IsisSession;
/**
*
* @since 2.0
- * @implNote listeners to runtime events are hard-wired, because these events are already fired
- * during bootstrapping, when event handling might not work properly yet.
+ * @implNote Listeners to runtime events can only reliably receive this after the
+ * post-construct phase has finished!
*/
@Service
public class RuntimeEventService {
+
+ @Inject private EventBusService eventBusService;
- @Inject JdoPersistenceLifecycleService listener; // dependsOn
-
- @Inject Event<AppLifecycleEvent> appLifecycleEvents;
- @Inject Event<SessionLifecycleEvent> sessionLifecycleEvents;
-
- // -- APP
+ // -- APP
public void fireAppPreMetamodel() {
- //appLifecycleEvents.fire(AppLifecycleEvent.of(AppLifecycleEvent.EventType.appPreMetamodel));
- listener.onAppLifecycleEvent(AppLifecycleEvent.of(AppLifecycleEvent.EventType.appPreMetamodel));
+ eventBusService.post(AppLifecycleEvent.of(AppLifecycleEvent.EventType.appPreMetamodel));
}
public void fireAppPostMetamodel() {
- //appLifecycleEvents.fire(AppLifecycleEvent.of(AppLifecycleEvent.EventType.appPostMetamodel));
- listener.onAppLifecycleEvent(AppLifecycleEvent.of(AppLifecycleEvent.EventType.appPostMetamodel));
+ eventBusService.post(AppLifecycleEvent.of(AppLifecycleEvent.EventType.appPostMetamodel));
}
public void fireAppPreDestroy() {
- //appLifecycleEvents.fire(AppLifecycleEvent.of(AppLifecycleEvent.EventType.appPreDestroy));
- listener.onAppLifecycleEvent(AppLifecycleEvent.of(AppLifecycleEvent.EventType.appPreDestroy));
+ eventBusService.post(AppLifecycleEvent.of(AppLifecycleEvent.EventType.appPreDestroy));
}
// -- SESSION
public void fireSessionOpened(IsisSession session) {
- //sessionLifecycleEvents.fire(SessionLifecycleEvent.of(session, SessionLifecycleEvent.EventType.sessionOpened));
- listener.onSessionLifecycleEvent(SessionLifecycleEvent.of(session, SessionLifecycleEvent.EventType.sessionOpened));
+ eventBusService.post(SessionLifecycleEvent.of(session, SessionLifecycleEvent.EventType.sessionOpened));
}
public void fireSessionClosing(IsisSession session) {
- //sessionLifecycleEvents.fire(SessionLifecycleEvent.of(session, SessionLifecycleEvent.EventType.sessionClosing));
- listener.onSessionLifecycleEvent(SessionLifecycleEvent.of(session, SessionLifecycleEvent.EventType.sessionClosing));
+ eventBusService.post(SessionLifecycleEvent.of(session, SessionLifecycleEvent.EventType.sessionClosing));
}
// public void fireSessionFlushing(IsisSession session) {
diff --git a/extensions/secman/persistence-jdo/src/main/java/org/apache/isis/extensions/secman/jdo/seed/SeedSecurityModuleService.java b/extensions/secman/persistence-jdo/src/main/java/org/apache/isis/extensions/secman/jdo/seed/SeedSecurityModuleService.java
index adc590d..a410cc7 100644
--- a/extensions/secman/persistence-jdo/src/main/java/org/apache/isis/extensions/secman/jdo/seed/SeedSecurityModuleService.java
+++ b/extensions/secman/persistence-jdo/src/main/java/org/apache/isis/extensions/secman/jdo/seed/SeedSecurityModuleService.java
@@ -18,29 +18,57 @@
*/
package org.apache.isis.extensions.secman.jdo.seed;
-import javax.annotation.PostConstruct;
import javax.inject.Inject;
-import javax.inject.Singleton;
+import org.springframework.context.event.EventListener;
import org.springframework.stereotype.Service;
+import org.apache.isis.commons.internal.exceptions._Exceptions;
import org.apache.isis.extensions.fixtures.fixturescripts.FixtureScripts;
+import org.apache.isis.runtime.system.context.session.AppLifecycleEvent;
+import lombok.val;
import lombok.extern.log4j.Log4j2;
@Service @Log4j2
public class SeedSecurityModuleService {
- @Inject FixtureScripts fixtureScripts;
+ @Inject private FixtureScripts fixtureScripts;
- @PostConstruct
+ //@PostConstruct ... to early, need to wait for the IsisSessionFactory,
+ //which can only init after the post-construct phase
public void init() {
-
+
log.info("SEED");
fixtureScripts.run(new SeedUsersAndRolesFixtureScript());
}
+ @EventListener(AppLifecycleEvent.class)
+ public void onAppLifecycleEvent(AppLifecycleEvent event) {
+
+ val eventType = event.getEventType();
+
+ log.debug("received app lifecycle event {}", eventType);
+
+ switch (eventType) {
+ case appPreMetamodel:
+ //create();
+ break;
+ case appPostMetamodel:
+ init();
+ break;
+ case appPreDestroy:
+ //shutdown();
+ break;
+
+ default:
+ throw _Exceptions.unmatchedCase(eventType);
+ }
+
+ }
+
+
}