You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@isis.apache.org by da...@apache.org on 2014/03/20 20:55:01 UTC

svn commit: r1579726 - in /isis/site/trunk/content: ./ components/objectstores/jdo/ components/objectstores/jdo/services/ reference/services/

Author: danhaywood
Date: Thu Mar 20 19:55:01 2014
New Revision: 1579726

URL: http://svn.apache.org/r1579726
Log:
event bus service

Added:
    isis/site/trunk/content/components/objectstores/jdo/IsisConfigurationForJdoIntegTests.md
    isis/site/trunk/content/components/objectstores/jdo/services/event-bus-service-jdo.md
Modified:
    isis/site/trunk/content/documentation.md
    isis/site/trunk/content/reference/services/event-bus-service.md
    isis/site/trunk/content/reference/services/publishing-service.md

Added: isis/site/trunk/content/components/objectstores/jdo/IsisConfigurationForJdoIntegTests.md
URL: http://svn.apache.org/viewvc/isis/site/trunk/content/components/objectstores/jdo/IsisConfigurationForJdoIntegTests.md?rev=1579726&view=auto
==============================================================================
--- isis/site/trunk/content/components/objectstores/jdo/IsisConfigurationForJdoIntegTests.md (added)
+++ isis/site/trunk/content/components/objectstores/jdo/IsisConfigurationForJdoIntegTests.md Thu Mar 20 19:55:01 2014
@@ -0,0 +1,7 @@
+Title: `IsisConfigurationForJdoIntegTests` (1.4.2-snapshot)
+
+When running integration tests with the JDO Objectstore, there are certain standard configuration properties that are usually set.  For example, integration tests are usually run against an in-memory HSQLDB database.
+
+To remove a little bit of boilerplate, the `IsisConfigurationForJdoIntegTests` class (in the `org.apache.isis.objectstore.jdo.datanucleus` package) can be used to bootstrap the application.
+
+The (example applications that we reverse engineer into our) [two](../../../intro/getting-started/simple-archetype.html) [archetypes](../../../intro/getting-started/quickstart-archetype.html) show this; see for example the [`ToDoSystemInitializer`](https://github.com/apache/isis/blob/3dcfb2fcd61636ff2fac66a3c7c54a500fdf2c6a/example/application/quickstart_wicket_restful_jdo/integtests/src/test/java/integration/ToDoSystemInitializer.java#L70) class.
\ No newline at end of file

Added: isis/site/trunk/content/components/objectstores/jdo/services/event-bus-service-jdo.md
URL: http://svn.apache.org/viewvc/isis/site/trunk/content/components/objectstores/jdo/services/event-bus-service-jdo.md?rev=1579726&view=auto
==============================================================================
--- isis/site/trunk/content/components/objectstores/jdo/services/event-bus-service-jdo.md (added)
+++ isis/site/trunk/content/components/objectstores/jdo/services/event-bus-service-jdo.md Thu Mar 20 19:55:01 2014
@@ -0,0 +1,17 @@
+Title: Event Bus Service for JDO
+
+To use the [`EventBusService`](../../../../reference/services/EventBusService.html) with the JDO Object Store, the JDO-specific implementation should be registered.
+
+The JDO implementation does not provide any additional functionality, but is aware of the lifecycle of domain entities and so ensures that objects are not interacted with while they are being rehydrated by the object store.
+
+
+## Register the Service
+
+Register this service like any other service, in `isis.properties`
+
+If the JDO ObjectStore *is* in use, use:
+
+    isis.services=...,\
+                  org.apache.isis.objectstore.jdo.datanucleus.service.eventbus.EventBusServiceJdo,\
+                  ...
+

Modified: isis/site/trunk/content/documentation.md
URL: http://svn.apache.org/viewvc/isis/site/trunk/content/documentation.md?rev=1579726&r1=1579725&r2=1579726&view=diff
==============================================================================
--- isis/site/trunk/content/documentation.md (original)
+++ isis/site/trunk/content/documentation.md Thu Mar 20 19:55:01 2014
@@ -288,7 +288,7 @@ For both:
 * [QueryResultsCache](./reference/services/query-results-cache.html)
 * [Scratchpad](./reference/services/scratchpad.html)
 * [Bulk.Interaction](./reference/services/bulk-interaction.html)
-* [EventBusService](./reference/services/event-bus-service.html) (stub)
+* [EventBusService](./reference/services/event-bus-service.html)
 
 
 }
@@ -534,6 +534,7 @@ Other
 * [Using a JNDI Datasource](components/objectstores/jdo/using-jndi-datasource.html)
 * [Enabling Logging](components/objectstores/jdo/enabling-logging.html)
 * [Deploying on the Google App Engine](components/objectstores/jdo/deploying-on-the-google-app-engine.html)
+* [`IsisConfigurationForJdoIntegTests`](components/objectstores/jdo/IsisConfigurationForJdoIntegTests.html) (1.4.2-snapshot)
 
 }
 
@@ -568,6 +569,7 @@ Other
 * [Background Command Service on JDO](components/objectstores/jdo/services/background-command-service-jdo.html)
 * [Publishing Service on JDO](components/objectstores/jdo/services/publishing-service-jdo.html) 
 * [Auditing Service on JDO](components/objectstores/jdo/services/auditing-service-jdo.html)
+* [Event Bus Service for JDO](components/objectstores/jdo/services/reference/services/event-bus-service-jdo.html)
 
 #### <a name="jdo-objectstore-non-ui">Non-UI</a>
 

Modified: isis/site/trunk/content/reference/services/event-bus-service.md
URL: http://svn.apache.org/viewvc/isis/site/trunk/content/reference/services/event-bus-service.md?rev=1579726&r1=1579725&r2=1579726&view=diff
==============================================================================
--- isis/site/trunk/content/reference/services/event-bus-service.md (original)
+++ isis/site/trunk/content/reference/services/event-bus-service.md Thu Mar 20 19:55:01 2014
@@ -1,28 +1,118 @@
 Title: Event Bus Service
 
-> stub
+The `EventBusService` is a wrapper for a [Guava](https://code.google.com/p/guava-libraries/) [`EventBus`](https://code.google.com/p/guava-libraries/wiki/EventBusExplained), allowing arbitrary events to be posted and subscribed to (within the Isis runtime).  The primary use case is for decoupling interactions from one module/package/namespace and another.
 
+Only domain services should be registered as subscribers; not domain entities.  Domain services are guaranteed to be instantiated and resident in memory, whereas the same is not true of domain entities.  
+
+The typical implementation of a domain service subscriber is to identify the impacted entities, load them using a repository query, and then to delegate to the event to them.
 
 ## API
 
 The API defined by `EventBusService` is:
 
 
+    public abstract class EventBusService {
+
+        protected abstract EventBus getEventBus();
+        
+        public void register(Object domainObject) { ... }
+        
+        @Programmatic
+        public void unregister(Object domainObject) { ... }
+        
+        @Programmatic
+        public void post(Object event) { ... }
+
+    }
+
+where
+
+* `register(Object)` registers the object with the event bus (it is simply a wrapper that delegates to `EventBus#register(Object)`)
+* `unregister(Object)` unregisters the object with the event bus (it is simply a wrapper that delegates to `EventBus#unregister(Object)`)
+* `post(Object)` posts the event onto event bus (it is simply a wrapper that delegates to `EventBus#post(Object)`)
+* `getEventBus()` provides access to the Guava `EventBus` for anything more sophisticated.
+
 ## Usage
 
+A good practice for domain services is to self-register when the `EventBusService` is injected into it:
+
+    private EventBusService eventBusService;
+    public void injectEventBusService(final EventBusService eventBusService) {
+        this.eventBusService = eventBusService;
+        eventBusService.register(this);
+    }
+
+The actual subscription of events is done by annotating a method on the class (that is, the usual Guava programming model).  
+
+For example, suppose in a library domain that a `LibraryMember` wants to leave the library.  A letter should be sent out detailing any books that they still have out on loan:
+
+In the `LibraryMember` class, we publish the event:
+
+    public class LibraryMember {
+        ...
+        public void leave() {
+            eventBus.post(new LibraryMemberLeaveEvent(this));
+        }
+        ...
+    }
+    
+Meanwhile, in the `BookRepository` domain service, we subscribe to the event and act upon it:
+
+    public class BookRepository {
+
+        @com.google.common.eventbus.Subscribe 
+        @Programmatic
+        public void onLibraryMemberLeaving(LibraryMemberLeaveEvent e) {
+            LibraryMember lm = e.getLibraryMember();
+            List<Book> lentBooks = findBooksOnLoanFor(lm);
+            if(!lentBooks.isEmpty()) {
+                sendLetter(lm, lentBooks);
+            }
+        }
+        ...
+    }
+
+This design allows the `libraryMember` module to be decoupled from the `book` module.
+
+    
+### `@PostsPropertyChangedEvent`
 
+Isis will also automatically publish (post) an `org.apache.isis.applib.services.eventbus.PropertyChangedEvent` event object on any property that is annotated with [`@PostsPropertyChangedEvent](../recognized-annotations/PostsPropertyChangedEvent.html).  This can remove some boilerplate.
+
+> The `@PropertyChangeEvent` is only raised for interactions through the UI, or through interactions through a wrapper created by the [Wrapper Factory](wrapper-factory.html) service.
+
+> This is work-in-progress.  In the future other interactions (such as action invocations, or collection add to/remove) may also be raised automatically.
+    
 ## Implementation
 
-`org.apache.isis.core.runtime.services.eventbus.EventBusServiceDefault`
+Isis provides two implementations.  The default implementation (provided by core runtime) is:
+
+    org.apache.isis.core.runtime.services.eventbus.EventBusServiceDefault
+
+However, if the JDO objectstore is in use, then its implementation *must* be used instead:
+
+    org.apache.isis.objectstore.jdo.datanucleus.service.eventbus.EventBusServiceJdo
 
 ## Register the Service
 
-Register this service like any other service, in `isis.properties`, eg:
+Register this service like any other service, in `isis.properties`
+
+If the JDO Objectstore is *not* in use, use:
 
     isis.services=...,\
                   org.apache.isis.core.runtime.services.eventbus.EventBusServiceDefault,\
                   ...
 
+If the JDO ObjectStore *is* in use, use:
+
+    isis.services=...,\
+                  org.apache.isis.objectstore.jdo.datanucleus.service.eventbus.EventBusServiceJdo,\
+                  ...
 
 ## Related Services
 
+The `EventBusService` is intended for fine-grained publish/subscribe for object-to-object interactions within an Isis domain object model.  The event propogation is strictly in-memory, and there are no restrictions on the object acting as the event (it need not be serializable, for example).
+
+The [`PublishingService`](./PublishingService.html) meanwhile is intended for coarse-grained publish/subscribe for system-to-system interactions, from Isis to some other system.  Here the only events published are those that action invocations (for actions annotated with [`@PublishedAction`](../recognized-annotations/PublishedAction.html)) and of changed objects (for objects annotated with [`@PublishedObject`](../recognized-annotations/PublishedObject.html).
+
+

Modified: isis/site/trunk/content/reference/services/publishing-service.md
URL: http://svn.apache.org/viewvc/isis/site/trunk/content/reference/services/publishing-service.md?rev=1579726&r1=1579725&r2=1579726&view=diff
==============================================================================
--- isis/site/trunk/content/reference/services/publishing-service.md (original)
+++ isis/site/trunk/content/reference/services/publishing-service.md Thu Mar 20 19:55:01 2014
@@ -182,18 +182,28 @@ An alternative implementation of the `Pu
 
 An alternative implementation of the `EventSerializer` is provided by the [Restful Objects viewer](../../components/viewers/restfulobjects/event-serializer-rospec.html).  This implementation serializes the payload using the conventions of the [Restful Objects spec](http://restfulobjects.org).
 
-#### Related Services
+## Related Services
+
+The [`PublishingService`](./PublishingService.html) is intended for coarse-grained publish/subscribe for system-to-system interactions, from Isis to some other system.  Here the only events published are those that action invocations (for actions annotated with [`@PublishedAction`](../recognized-annotations/PublishedAction.html)) and of changed objects (for objects annotated with [`@PublishedObject`](../recognized-annotations/PublishedObject.html).
+
+The [`EventBusService`](./EventBusService.html) meanwhile is intended for fine-grained publish/subscribe for object-to-object interactions within an Isis domain object model.  The event propogation is strictly in-memory, and there are no restrictions on the object acting as the event (it need not be serializable, for example).  
+
+
+## Third-party integrations
 
 Dan Haywood's [camel-isis-pubsubjdo](https://github.com/danhaywood/camel-isis-pubsubjdo) project up on github shows how to poll and process the persisted `PublishedEvent` table using [Apache Camel](http://camel.apache.org).
 
 
-## Class Diagram
+<hr/>
+
+## Design Notes
 
 The following class diagram shows how the above components fit together:
 
  ![](images/yuml.me-23db58a4.png)
 
-The diagram was generated at [yuml.me](http://yuml.me/edit/23db58a4) using the following description:
+ 
+This yuml.me diagram was generated at [yuml.me](http://yuml.me/edit/23db58a4) using the following description:
 
 <pre>
 [PublishingService]++-serializesUsing>[EventSerializer]