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 2013/03/24 12:54:57 UTC

[3/3] git commit: ISIS-367: EventMetadata provides id; commented out entries for github pub service in example

ISIS-367: EventMetadata provides id; commented out entries for github pub service in example

* EventMetadata#getGuid renamed to EventMetadata#getTransactionId
* EventMetadata#getSequence added
* EventMetadata#getId added
* added commented out entries for example configuration of using github-hosted pubsub service for ActiveMQ/RA.


Project: http://git-wip-us.apache.org/repos/asf/isis/repo
Commit: http://git-wip-us.apache.org/repos/asf/isis/commit/a73ddca8
Tree: http://git-wip-us.apache.org/repos/asf/isis/tree/a73ddca8
Diff: http://git-wip-us.apache.org/repos/asf/isis/diff/a73ddca8

Branch: refs/heads/master
Commit: a73ddca862f9def4087ed20b749ac052b31d66ad
Parents: ace2b5b
Author: Dan Haywood <da...@apache.org>
Authored: Sun Mar 24 11:54:23 2013 +0000
Committer: Dan Haywood <da...@apache.org>
Committed: Sun Mar 24 11:54:23 2013 +0000

----------------------------------------------------------------------
 .../objectstore/jdo/service/RegisterEntities.java  |   18 ++++++
 .../RestfulObjectsSpecEventSerializer.java         |    4 +-
 .../applib/services/publish/EventMetadata.java     |   44 +++++++++++++--
 .../applib/services/publish/EventSerializer.java   |    2 +-
 .../services/publish/EventMetadataTest_getId.java  |   28 +++++++++
 .../system/transaction/IsisTransaction.java        |   16 +++++-
 .../dom/src/main/java/dom/todo/ToDoItem.java       |    1 -
 .../quickstart_wicket_restful_jdo/pom.xml          |   12 ++++
 .../viewer-webapp/pom.xml                          |    9 +++
 .../src/main/webapp/WEB-INF/isis.properties        |   10 ++-
 .../WEB-INF/persistor_datanucleus.properties       |    1 +
 .../viewer-webapp/src/main/webapp/WEB-INF/web.xml  |   14 ++++-
 12 files changed, 144 insertions(+), 15 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/isis/blob/a73ddca8/component/objectstore/jdo/jdo-datanucleus/src/main/java/org/apache/isis/objectstore/jdo/service/RegisterEntities.java
----------------------------------------------------------------------
diff --git a/component/objectstore/jdo/jdo-datanucleus/src/main/java/org/apache/isis/objectstore/jdo/service/RegisterEntities.java b/component/objectstore/jdo/jdo-datanucleus/src/main/java/org/apache/isis/objectstore/jdo/service/RegisterEntities.java
index d3d7e9c..97a493f 100644
--- a/component/objectstore/jdo/jdo-datanucleus/src/main/java/org/apache/isis/objectstore/jdo/service/RegisterEntities.java
+++ b/component/objectstore/jdo/jdo-datanucleus/src/main/java/org/apache/isis/objectstore/jdo/service/RegisterEntities.java
@@ -1,3 +1,21 @@
+/*
+ *  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.objectstore.jdo.service;
 
 import java.util.Map;

http://git-wip-us.apache.org/repos/asf/isis/blob/a73ddca8/component/viewer/restfulobjects/rendering/src/main/java/org/apache/isis/viewer/restfulobjects/rendering/eventserializer/RestfulObjectsSpecEventSerializer.java
----------------------------------------------------------------------
diff --git a/component/viewer/restfulobjects/rendering/src/main/java/org/apache/isis/viewer/restfulobjects/rendering/eventserializer/RestfulObjectsSpecEventSerializer.java b/component/viewer/restfulobjects/rendering/src/main/java/org/apache/isis/viewer/restfulobjects/rendering/eventserializer/RestfulObjectsSpecEventSerializer.java
index 8e87490..332780b 100644
--- a/component/viewer/restfulobjects/rendering/src/main/java/org/apache/isis/viewer/restfulobjects/rendering/eventserializer/RestfulObjectsSpecEventSerializer.java
+++ b/component/viewer/restfulobjects/rendering/src/main/java/org/apache/isis/viewer/restfulobjects/rendering/eventserializer/RestfulObjectsSpecEventSerializer.java
@@ -57,7 +57,9 @@ public class RestfulObjectsSpecEventSerializer implements EventSerializer {
         final JsonRepresentation eventRepr = JsonRepresentation.newMap();
         final JsonRepresentation metadataRepr = JsonRepresentation.newMap();
         eventRepr.mapPut("metadata", metadataRepr);
-        metadataRepr.mapPut("guid", metadata.getGuid());
+        metadataRepr.mapPut("id", metadata.getId());
+        metadataRepr.mapPut("transactionId", metadata.getTransactionId());
+        metadataRepr.mapPut("sequence", metadata.getSequence());
         metadataRepr.mapPut("user", metadata.getUser());
         metadataRepr.mapPut("timestamp", metadata.getTimestamp());
         eventRepr.mapPut("payload", payloadRepr);

http://git-wip-us.apache.org/repos/asf/isis/blob/a73ddca8/core/applib/src/main/java/org/apache/isis/applib/services/publish/EventMetadata.java
----------------------------------------------------------------------
diff --git a/core/applib/src/main/java/org/apache/isis/applib/services/publish/EventMetadata.java b/core/applib/src/main/java/org/apache/isis/applib/services/publish/EventMetadata.java
index 42983e6..e97dc15 100644
--- a/core/applib/src/main/java/org/apache/isis/applib/services/publish/EventMetadata.java
+++ b/core/applib/src/main/java/org/apache/isis/applib/services/publish/EventMetadata.java
@@ -12,22 +12,40 @@ import java.util.UUID;
  */
 public class EventMetadata {
     
-    private final UUID guid;
+    private final UUID transactionId;
+    private final int sequence;
     private final String user;
     private final long timestamp;
     
-    public EventMetadata(UUID guid, String user, long timestamp) {
-        this.guid = guid;
+    public EventMetadata(UUID transactionId, int sequence, String user, long timestamp) {
+        this.transactionId = transactionId;
+        this.sequence = sequence;
         this.user = user;
         this.timestamp = timestamp;
     }
     
     /**
-     * Unique identifier of this event.
+     * Isis' identifier of the transaction within which this event
+     * originated.
+     * 
+     * <p>
+     * Note that there could be several events all with the same transaction Id.
      */
-    public UUID getGuid() {
-        return guid;
+    public UUID getTransactionId() {
+        return transactionId;
     }
+    
+    /**
+     * The zero-based sequence number of this event within the transaction.
+     * 
+     * <p>
+     * The combination of {@link #getTransactionId() transaction Id} and {@link #getSequence() sequence}
+     * is guaranteed to be unique.
+     */
+    public int getSequence() {
+        return sequence;
+    }
+    
     /**
      * Represents the user that was responsible for generating the event.  
      */
@@ -41,4 +59,18 @@ public class EventMetadata {
     public long getTimestamp() {
         return timestamp;
     }
+    
+    /**
+     * Returns a string that concatenates the {@link #getTransactionId()} and the
+     * {@link #getSequence()} with a <tt>:</tt>.
+     */
+    public String getId() {
+        return getTransactionId() + ":" + getSequence();
+    }
+    
+    @Override
+    public String toString() {
+        return getId();
+    }
+
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/isis/blob/a73ddca8/core/applib/src/main/java/org/apache/isis/applib/services/publish/EventSerializer.java
----------------------------------------------------------------------
diff --git a/core/applib/src/main/java/org/apache/isis/applib/services/publish/EventSerializer.java b/core/applib/src/main/java/org/apache/isis/applib/services/publish/EventSerializer.java
index e576902..13008df 100644
--- a/core/applib/src/main/java/org/apache/isis/applib/services/publish/EventSerializer.java
+++ b/core/applib/src/main/java/org/apache/isis/applib/services/publish/EventSerializer.java
@@ -26,7 +26,7 @@ public interface EventSerializer {
         @Programmatic
         @Override
         public Object serialize(EventMetadata metadata, EventPayload payload) {
-            return "PUBLISHED: \n    metadata: " + metadata.getGuid() + ":" + metadata.getUser() + ":" + metadata.getTimestamp() + ":    payload:s\n"+ payload.toString();
+            return "PUBLISHED: \n    metadata: " + metadata.getId() + ":" + metadata.getUser() + ":" + metadata.getTimestamp() + ":    payload:s\n"+ payload.toString();
         }
     }
 

http://git-wip-us.apache.org/repos/asf/isis/blob/a73ddca8/core/applib/src/test/java/org/apache/isis/applib/services/publish/EventMetadataTest_getId.java
----------------------------------------------------------------------
diff --git a/core/applib/src/test/java/org/apache/isis/applib/services/publish/EventMetadataTest_getId.java b/core/applib/src/test/java/org/apache/isis/applib/services/publish/EventMetadataTest_getId.java
new file mode 100644
index 0000000..7c741fe
--- /dev/null
+++ b/core/applib/src/test/java/org/apache/isis/applib/services/publish/EventMetadataTest_getId.java
@@ -0,0 +1,28 @@
+package org.apache.isis.applib.services.publish;
+
+import static org.hamcrest.CoreMatchers.*;
+import static org.junit.Assert.*;
+
+import java.util.Calendar;
+import java.util.UUID;
+
+import org.junit.Test;
+
+public class EventMetadataTest_getId {
+
+    @Test
+    public void test() {
+        UUID transactionId = UUID.fromString("1bd8e5d4-2d67-4395-b5e8-d74acd766766");
+        int sequence = 2;
+        String user = "fred";
+        long timestamp = 1364120978631L;
+        EventMetadata eventMetadata = new EventMetadata(transactionId, sequence, user, timestamp);
+        
+        assertThat(eventMetadata.getTransactionId(), is(UUID.fromString("1bd8e5d4-2d67-4395-b5e8-d74acd766766")));
+        assertThat(eventMetadata.getSequence(), is(2));
+        assertThat(eventMetadata.getUser(), is("fred"));
+        assertThat(eventMetadata.getTimestamp(), is(1364120978631L));
+        assertThat(eventMetadata.getId(), is("1bd8e5d4-2d67-4395-b5e8-d74acd766766:2"));
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/isis/blob/a73ddca8/core/runtime/src/main/java/org/apache/isis/core/runtime/system/transaction/IsisTransaction.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/apache/isis/core/runtime/system/transaction/IsisTransaction.java b/core/runtime/src/main/java/org/apache/isis/core/runtime/system/transaction/IsisTransaction.java
index eb0e790..e9e2728 100644
--- a/core/runtime/src/main/java/org/apache/isis/core/runtime/system/transaction/IsisTransaction.java
+++ b/core/runtime/src/main/java/org/apache/isis/core/runtime/system/transaction/IsisTransaction.java
@@ -191,6 +191,8 @@ public class IsisTransaction implements TransactionScopedComponent {
 
     private final UUID guid;
 
+    private int eventSequence;
+
     public IsisTransaction(final IsisTransactionManager transactionManager, final org.apache.isis.core.commons.authentication.MessageBroker messageBroker, final UpdateNotifier updateNotifier, final TransactionalResource objectStore, final AuditingService auditingService, PublishingServiceWithDefaultPayloadFactories publishingService) {
         
         ensureThatArg(transactionManager, is(not(nullValue())), "transaction manager is required");
@@ -204,6 +206,7 @@ public class IsisTransaction implements TransactionScopedComponent {
         this.publishingService = publishingService;
         
         this.guid = UUID.randomUUID();
+        this.eventSequence = 0;
 
         this.state = State.IN_PROGRESS;
 
@@ -221,6 +224,7 @@ public class IsisTransaction implements TransactionScopedComponent {
         return guid;
     }
     
+    
     // ////////////////////////////////////////////////////////////////
     // State
     // ////////////////////////////////////////////////////////////////
@@ -409,7 +413,7 @@ public class IsisTransaction implements TransactionScopedComponent {
                 return;
             } 
             final PublishedAction.PayloadFactory payloadFactory = publishedActionFacet.value();
-            final EventMetadata metadata = new EventMetadata(getGuid(), currentUser, currentTimestampEpoch);
+            final EventMetadata metadata = newEventMetadata(currentUser, currentTimestampEpoch);
             publishingService.publishAction(payloadFactory, metadata, currentInvocation);
         } finally {
             ActionInvocationFacet.currentInvocation.set(null);
@@ -423,7 +427,7 @@ public class IsisTransaction implements TransactionScopedComponent {
                 continue;
             }
             final PublishedObject.PayloadFactory payloadFactory = publishedObjectFacet.value();
-            final EventMetadata metadata = new EventMetadata(getGuid(), currentUser, currentTimestampEpoch);
+            final EventMetadata metadata = newEventMetadata(currentUser, currentTimestampEpoch);
 
             publishingService.publishObject(payloadFactory, metadata, changedAdapter);
         }
@@ -433,6 +437,14 @@ public class IsisTransaction implements TransactionScopedComponent {
         return Clock.getTime();
     }
 
+    private EventMetadata newEventMetadata(final String currentUser, final long currentTimestampEpoch) {
+        return new EventMetadata(getGuid(), nextEventSequence(), currentUser, currentTimestampEpoch);
+    }
+
+    private int nextEventSequence() {
+        return eventSequence++;
+    }
+    
     private void auditChangedProperty(final String currentUser, final long currentTimestampEpoch, final Entry<AdapterAndProperty, PreAndPostValues> auditEntry) {
         final AdapterAndProperty aap = auditEntry.getKey();
         final ObjectAdapter adapter = aap.getAdapter();

http://git-wip-us.apache.org/repos/asf/isis/blob/a73ddca8/example/application/quickstart_wicket_restful_jdo/dom/src/main/java/dom/todo/ToDoItem.java
----------------------------------------------------------------------
diff --git a/example/application/quickstart_wicket_restful_jdo/dom/src/main/java/dom/todo/ToDoItem.java b/example/application/quickstart_wicket_restful_jdo/dom/src/main/java/dom/todo/ToDoItem.java
index 7e07a74..63e0023 100644
--- a/example/application/quickstart_wicket_restful_jdo/dom/src/main/java/dom/todo/ToDoItem.java
+++ b/example/application/quickstart_wicket_restful_jdo/dom/src/main/java/dom/todo/ToDoItem.java
@@ -404,7 +404,6 @@ public class ToDoItem implements Comparable<ToDoItem> /*, Locatable*/ { // GMAP3
     /**
      * by complete flag, then due by date, then description
      */
-    // exclude from the framework's metamodel
     @Override
     public int compareTo(final ToDoItem other) {
         if (isComplete() && !other.isComplete()) {

http://git-wip-us.apache.org/repos/asf/isis/blob/a73ddca8/example/application/quickstart_wicket_restful_jdo/pom.xml
----------------------------------------------------------------------
diff --git a/example/application/quickstart_wicket_restful_jdo/pom.xml b/example/application/quickstart_wicket_restful_jdo/pom.xml
index 8b3e1da..3bd16ff 100644
--- a/example/application/quickstart_wicket_restful_jdo/pom.xml
+++ b/example/application/quickstart_wicket_restful_jdo/pom.xml
@@ -321,6 +321,7 @@
 
 
             <!-- 3rd party extensions -->
+
             <!--
             GMAP3: uncomment to use https://github.com/danhaywood/isis-wicket-gmap3
             <dependency>
@@ -331,6 +332,17 @@
                 <scope>import</scope>
             </dependency>
             -->
+            
+            <!-- 
+            ActiveMQ/RA Publishing Service:
+            uncomment to use https://github.com/danhaywood/isis-publishingservice-activemq-ra
+            <dependency>
+            <groupId>com.danhaywood.isis.publishingservice</groupId>
+                <artifactId>danhaywood-isis-publishingservice-activemq-ra</artifactId>
+                <version>0.0.1-SNAPSHOT</version>
+            </dependency>
+             -->
+            
 
         </dependencies>
     </dependencyManagement>

http://git-wip-us.apache.org/repos/asf/isis/blob/a73ddca8/example/application/quickstart_wicket_restful_jdo/viewer-webapp/pom.xml
----------------------------------------------------------------------
diff --git a/example/application/quickstart_wicket_restful_jdo/viewer-webapp/pom.xml b/example/application/quickstart_wicket_restful_jdo/viewer-webapp/pom.xml
index 38efdcd..03b071a 100644
--- a/example/application/quickstart_wicket_restful_jdo/viewer-webapp/pom.xml
+++ b/example/application/quickstart_wicket_restful_jdo/viewer-webapp/pom.xml
@@ -286,6 +286,15 @@
             <artifactId>danhaywood-isis-wicket-gmap3-ui</artifactId>
         </dependency>
          -->
+         
+        <!-- 
+        ActiveMQ/RA Publishing Service:
+        uncomment to use https://github.com/danhaywood/isis-publishingservice-activemq-ra
+        <dependency>
+            <groupId>com.danhaywood.isis.publishingservice</groupId>
+            <artifactId>danhaywood-isis-publishingservice-activemq-ra</artifactId>
+        </dependency>
+         -->
 
     </dependencies>
 

http://git-wip-us.apache.org/repos/asf/isis/blob/a73ddca8/example/application/quickstart_wicket_restful_jdo/viewer-webapp/src/main/webapp/WEB-INF/isis.properties
----------------------------------------------------------------------
diff --git a/example/application/quickstart_wicket_restful_jdo/viewer-webapp/src/main/webapp/WEB-INF/isis.properties b/example/application/quickstart_wicket_restful_jdo/viewer-webapp/src/main/webapp/WEB-INF/isis.properties
index c8de80a..430d692 100644
--- a/example/application/quickstart_wicket_restful_jdo/viewer-webapp/src/main/webapp/WEB-INF/isis.properties
+++ b/example/application/quickstart_wicket_restful_jdo/viewer-webapp/src/main/webapp/WEB-INF/isis.properties
@@ -158,14 +158,15 @@ isis.user-profile-store=in-memory
 
 
 # if using the DataNucleus object store
-# (with support for JDO's audit service, and installing fixtures using a domain service)
 #isis.services.prefix = 
 isis.services = objstore.jdo.todo.ToDoItemsJdo,\
                 fixture.todo.ToDoItemsFixturesService,\
                 dom.audit.AuditServiceDemo,\
-                org.apache.isis.applib.services.publish.PublishingService$Stderr,\
+                org.apache.isis.objectstore.jdo.applib.service.exceprecog.ExceptionRecognizerCompositeForJdoObjectStore,\
                 org.apache.isis.viewer.restfulobjects.rendering.eventserializer.RestfulObjectsSpecEventSerializer,\
-                org.apache.isis.objectstore.jdo.applib.service.exceprecog.ExceptionRecognizerCompositeForJdoObjectStore
+                org.apache.isis.applib.services.publish.PublishingService$Stderr
+                #com.danhaywood.isis.publishingservice.activemq.ra.PublishingServiceUsingActiveMqRa
+
 
 # Specify the (optional) test fixtures
 #
@@ -178,4 +179,7 @@ isis.services = objstore.jdo.todo.ToDoItemsJdo,\
 
 
 
+# ActiveMQ/RA Publishing Service
+# see: https://github.com/danhaywood/isis-publishingservice-activemq-ra
+#com.danhaywood.isis.publishingservice.activemq.ra.connectionFactory=openejb:Resource/ConnectionFactory
 

http://git-wip-us.apache.org/repos/asf/isis/blob/a73ddca8/example/application/quickstart_wicket_restful_jdo/viewer-webapp/src/main/webapp/WEB-INF/persistor_datanucleus.properties
----------------------------------------------------------------------
diff --git a/example/application/quickstart_wicket_restful_jdo/viewer-webapp/src/main/webapp/WEB-INF/persistor_datanucleus.properties b/example/application/quickstart_wicket_restful_jdo/viewer-webapp/src/main/webapp/WEB-INF/persistor_datanucleus.properties
index 3761872..e061e4f 100644
--- a/example/application/quickstart_wicket_restful_jdo/viewer-webapp/src/main/webapp/WEB-INF/persistor_datanucleus.properties
+++ b/example/application/quickstart_wicket_restful_jdo/viewer-webapp/src/main/webapp/WEB-INF/persistor_datanucleus.properties
@@ -49,6 +49,7 @@ isis.persistor.datanucleus.impl.datanucleus.persistenceByReachabilityAtCommit=fa
 #isis.persistor.datanucleus.impl.datanucleus.ConnectionFactory2Name=java:comp/env/jdbc/quickstart-nontx
 #isis.persistor.datanucleus.impl.javax.jdo.option.TransactionType=JTA
 
+
 #
 # HSQLDB in-memory
 #

http://git-wip-us.apache.org/repos/asf/isis/blob/a73ddca8/example/application/quickstart_wicket_restful_jdo/viewer-webapp/src/main/webapp/WEB-INF/web.xml
----------------------------------------------------------------------
diff --git a/example/application/quickstart_wicket_restful_jdo/viewer-webapp/src/main/webapp/WEB-INF/web.xml b/example/application/quickstart_wicket_restful_jdo/viewer-webapp/src/main/webapp/WEB-INF/web.xml
index 9ae3812..c61cb87 100644
--- a/example/application/quickstart_wicket_restful_jdo/viewer-webapp/src/main/webapp/WEB-INF/web.xml
+++ b/example/application/quickstart_wicket_restful_jdo/viewer-webapp/src/main/webapp/WEB-INF/web.xml
@@ -270,6 +270,18 @@
         <res-auth>Container</res-auth>
     </resource-ref>
      -->
-  
+
+
+    <!-- 
+    ActiveMQ/RA Publishing Service
+    see: https://github.com/danhaywood/isis-publishingservice-activemq-ra
+    ??? is this necessary, though ???
+    <resource-ref> 
+        <description>JMS Connection Factory</description> 
+        <res-ref-name>ConnectionFactory</res-ref-name> 
+        <res-type>javax.jms.ConnectionFactory</res-type> 
+        <res-auth>Container</res-auth> 
+    </resource-ref> 
+    -->
 
 </web-app>