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/12/19 12:33:06 UTC

[isis] branch master updated: ISIS-2158: conceptual fix for async wrapper demo

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


The following commit(s) were added to refs/heads/master by this push:
     new d0f97a9  ISIS-2158: conceptual fix for async wrapper demo
d0f97a9 is described below

commit d0f97a91371b57dd190abd7cc7099c0143abac5f
Author: Andi Huber <ah...@apache.org>
AuthorDate: Thu Dec 19 13:32:55 2019 +0100

    ISIS-2158: conceptual fix for async wrapper demo
    
    @Service classes are no longer allowed to contribute @Action(s)
    we invoke another domain-object instead, that is allowed to declare
    @Action(s)
---
 ...entSubscriber.java => DemoEventSubscriber.java} | 34 +++++++++++++++-------
 1 file changed, 24 insertions(+), 10 deletions(-)

diff --git a/examples/demo/src/main/java/demoapp/dom/events/EventSubscriber.java b/examples/demo/src/main/java/demoapp/dom/events/DemoEventSubscriber.java
similarity index 72%
rename from examples/demo/src/main/java/demoapp/dom/events/EventSubscriber.java
rename to examples/demo/src/main/java/demoapp/dom/events/DemoEventSubscriber.java
index b76fad1..1f95156 100644
--- a/examples/demo/src/main/java/demoapp/dom/events/EventSubscriber.java
+++ b/examples/demo/src/main/java/demoapp/dom/events/DemoEventSubscriber.java
@@ -27,26 +27,28 @@ import org.springframework.context.event.EventListener;
 import org.springframework.stereotype.Service;
 
 import org.apache.isis.applib.annotation.Action;
-import org.apache.isis.applib.annotation.DomainService;
+import org.apache.isis.applib.annotation.DomainObject;
+import org.apache.isis.applib.annotation.Nature;
 import org.apache.isis.applib.events.domain.AbstractDomainEvent;
 import org.apache.isis.applib.services.eventbus.EventBusService;
+import org.apache.isis.applib.services.factory.FactoryService;
 import org.apache.isis.applib.services.wrapper.WrapperFactory;
 
 import static demoapp.utils.DemoUtils.emphasize;
 
 import demoapp.dom.events.EventLogMenu.EventTestProgrammaticEvent;
+import lombok.val;
 import lombok.extern.log4j.Log4j2;
 
-@DomainService // allows async invocation of the storeEvent(...) Action
 @Service
 @Named("demoapp.eventSubscriber")
 @Qualifier("demo")
 @Log4j2
-public class EventSubscriber {
+public class DemoEventSubscriber {
 
     @Inject private WrapperFactory wrapper;
     @Inject private EventBusService eventBusService;
-    @Inject private EventLogRepository eventLogRepository;
+    @Inject private FactoryService factoryService;
 
     public static class EventSubscriberEvent extends AbstractDomainEvent<Object> {}
 
@@ -65,16 +67,28 @@ public class EventSubscriber {
 
         log.info(emphasize("DomainEvent: " + ev.getClass().getName()));
         
+        val eventLogWriter = factoryService.instantiate(EventLogWriter.class);
+        
         // store in event log, by calling the storeEvent(...) Action
-        wrapper.async(this)
-        .run(EventSubscriber::storeEvent, ev);
+        wrapper.async(eventLogWriter)
+        .run(EventLogWriter::storeEvent, ev);
 
     }
 
-    
-    @Action // allows async invocation 
-    public void storeEvent(EventTestProgrammaticEvent ev) {
-        eventLogRepository.add(EventLogEntry.of(ev));
+    @DomainObject(
+            nature = Nature.INMEMORY_ENTITY, 
+            objectType = "demoapp.eventLogWriter")
+    public static class EventLogWriter {
+
+        @Inject private EventLogRepository eventLogRepository;
+        
+        @Action // called asynchronously above invocation 
+        public void storeEvent(EventTestProgrammaticEvent ev) {
+            eventLogRepository.add(EventLogEntry.of(ev));
+        }
+        
     }
+    
+    
 
 }