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 2016/10/21 15:01:27 UTC

[33/44] isis git commit: ISIS-1507: switches off the QueryResultsCache while fixtures are being installed.

ISIS-1507: switches off the QueryResultsCache while fixtures are being installed.


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

Branch: refs/heads/master
Commit: f6976b14f241a104fcb90b6b0fb74fd3da7b9fca
Parents: 242e76b
Author: Dan Haywood <da...@haywood-associates.co.uk>
Authored: Fri Sep 30 08:54:27 2016 +0100
Committer: Dan Haywood <da...@haywood-associates.co.uk>
Committed: Fri Sep 30 08:54:27 2016 +0100

----------------------------------------------------------------------
 .../guides/_rgsvc_api_EventBusService.adoc      |  2 +-
 core/applib/pom.xml                             |  6 ++
 .../events/system/FixturesInstalledEvent.java   | 32 +++++++++
 .../events/system/FixturesInstallingEvent.java  | 32 +++++++++
 .../fixturespec/FixtureScriptsDefault.java      | 15 +++-
 .../queryresultscache/QueryResultsCache.java    | 73 +++++++++++++++++++-
 core/pom.xml                                    |  6 ++
 7 files changed, 160 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/isis/blob/f6976b14/adocs/documentation/src/main/asciidoc/guides/_rgsvc_api_EventBusService.adoc
----------------------------------------------------------------------
diff --git a/adocs/documentation/src/main/asciidoc/guides/_rgsvc_api_EventBusService.adoc b/adocs/documentation/src/main/asciidoc/guides/_rgsvc_api_EventBusService.adoc
index c7ed940..e8b6763 100644
--- a/adocs/documentation/src/main/asciidoc/guides/_rgsvc_api_EventBusService.adoc
+++ b/adocs/documentation/src/main/asciidoc/guides/_rgsvc_api_EventBusService.adoc
@@ -131,7 +131,7 @@ or if using Axonframework, the subscriber uses a different annotation:
 @DomainService(nature=NatureOfService.DOMAIN)
 public class MySubscribingDomainService
     @Programmatic
-    @org.axonframework.eventhandling.annotation.EventHandle
+    @org.axonframework.eventhandling.annotation.EventHandler
     public void on(ActionDomainEvent ev) { ... }
     ...
 }

http://git-wip-us.apache.org/repos/asf/isis/blob/f6976b14/core/applib/pom.xml
----------------------------------------------------------------------
diff --git a/core/applib/pom.xml b/core/applib/pom.xml
index b7eef02..a2a1d41 100644
--- a/core/applib/pom.xml
+++ b/core/applib/pom.xml
@@ -114,6 +114,12 @@
             <artifactId>jboss-jaxrs-api_2.0_spec</artifactId>
         </dependency>
 
+        <dependency>
+            <groupId>org.axonframework</groupId>
+            <artifactId>axon-core</artifactId>
+            <optional>true</optional>
+        </dependency>
+
         <!-- DataNucleus' standard JDO support -->
         <dependency>
             <groupId>javax.jdo</groupId>

http://git-wip-us.apache.org/repos/asf/isis/blob/f6976b14/core/applib/src/main/java/org/apache/isis/applib/events/system/FixturesInstalledEvent.java
----------------------------------------------------------------------
diff --git a/core/applib/src/main/java/org/apache/isis/applib/events/system/FixturesInstalledEvent.java b/core/applib/src/main/java/org/apache/isis/applib/events/system/FixturesInstalledEvent.java
new file mode 100644
index 0000000..83060c3
--- /dev/null
+++ b/core/applib/src/main/java/org/apache/isis/applib/events/system/FixturesInstalledEvent.java
@@ -0,0 +1,32 @@
+/*
+ *  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.applib.events.system;
+
+import java.util.EventObject;
+
+public class FixturesInstalledEvent extends EventObject {
+
+    private static final long serialVersionUID = 1L;
+
+    public FixturesInstalledEvent(final Object source) {
+        super(source);
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/isis/blob/f6976b14/core/applib/src/main/java/org/apache/isis/applib/events/system/FixturesInstallingEvent.java
----------------------------------------------------------------------
diff --git a/core/applib/src/main/java/org/apache/isis/applib/events/system/FixturesInstallingEvent.java b/core/applib/src/main/java/org/apache/isis/applib/events/system/FixturesInstallingEvent.java
new file mode 100644
index 0000000..812c4e6
--- /dev/null
+++ b/core/applib/src/main/java/org/apache/isis/applib/events/system/FixturesInstallingEvent.java
@@ -0,0 +1,32 @@
+/*
+ *  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.applib.events.system;
+
+import java.util.EventObject;
+
+public class FixturesInstallingEvent extends EventObject {
+
+    private static final long serialVersionUID = 1L;
+
+    public FixturesInstallingEvent(final Object source) {
+        super(source);
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/isis/blob/f6976b14/core/applib/src/main/java/org/apache/isis/applib/services/fixturespec/FixtureScriptsDefault.java
----------------------------------------------------------------------
diff --git a/core/applib/src/main/java/org/apache/isis/applib/services/fixturespec/FixtureScriptsDefault.java b/core/applib/src/main/java/org/apache/isis/applib/services/fixturespec/FixtureScriptsDefault.java
index 6401aab..ae88f38 100644
--- a/core/applib/src/main/java/org/apache/isis/applib/services/fixturespec/FixtureScriptsDefault.java
+++ b/core/applib/src/main/java/org/apache/isis/applib/services/fixturespec/FixtureScriptsDefault.java
@@ -21,7 +21,6 @@ package org.apache.isis.applib.services.fixturespec;
 import java.util.List;
 
 import javax.annotation.PostConstruct;
-import javax.inject.Inject;
 
 import org.apache.isis.applib.annotation.Action;
 import org.apache.isis.applib.annotation.ActionLayout;
@@ -32,9 +31,12 @@ import org.apache.isis.applib.annotation.Optionality;
 import org.apache.isis.applib.annotation.Parameter;
 import org.apache.isis.applib.annotation.ParameterLayout;
 import org.apache.isis.applib.annotation.RestrictTo;
+import org.apache.isis.applib.events.system.FixturesInstalledEvent;
+import org.apache.isis.applib.events.system.FixturesInstallingEvent;
 import org.apache.isis.applib.fixturescripts.FixtureResult;
 import org.apache.isis.applib.fixturescripts.FixtureScript;
 import org.apache.isis.applib.fixturescripts.FixtureScripts;
+import org.apache.isis.applib.services.eventbus.EventBusService;
 
 /**
  * Default instance of {@link FixtureScripts}, instantiated automatically by the framework if no custom user-defined instance was
@@ -101,7 +103,12 @@ public class FixtureScriptsDefault extends FixtureScripts {
                 multiLine = 10)
             @Parameter(optionality = Optionality.OPTIONAL)
             final String parameters) {
-        return super.runFixtureScript(fixtureScript, parameters);
+        try {
+            eventBusService.post(new FixturesInstallingEvent(this));
+            return super.runFixtureScript(fixtureScript, parameters);
+        } finally {
+            eventBusService.post(new FixturesInstalledEvent(this));
+        }
     }
 
     /**
@@ -216,7 +223,9 @@ public class FixtureScriptsDefault extends FixtureScripts {
 
     //region > injected services
     @javax.inject.Inject
-    private FixtureScriptsSpecificationProvider fixtureScriptsSpecificationProvider;
+    FixtureScriptsSpecificationProvider fixtureScriptsSpecificationProvider;
+    @javax.inject.Inject
+    EventBusService eventBusService;
     //endregion
 
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/isis/blob/f6976b14/core/applib/src/main/java/org/apache/isis/applib/services/queryresultscache/QueryResultsCache.java
----------------------------------------------------------------------
diff --git a/core/applib/src/main/java/org/apache/isis/applib/services/queryresultscache/QueryResultsCache.java b/core/applib/src/main/java/org/apache/isis/applib/services/queryresultscache/QueryResultsCache.java
index 12accb1..82b45a8 100644
--- a/core/applib/src/main/java/org/apache/isis/applib/services/queryresultscache/QueryResultsCache.java
+++ b/core/applib/src/main/java/org/apache/isis/applib/services/queryresultscache/QueryResultsCache.java
@@ -20,9 +20,13 @@ import java.util.Arrays;
 import java.util.Map;
 import java.util.concurrent.Callable;
 
+import javax.annotation.PostConstruct;
+import javax.annotation.PreDestroy;
 import javax.enterprise.context.RequestScoped;
+import javax.inject.Inject;
 
 import com.google.common.collect.Maps;
+import com.google.common.eventbus.Subscribe;
 
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -30,7 +34,10 @@ import org.slf4j.LoggerFactory;
 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.events.system.FixturesInstalledEvent;
+import org.apache.isis.applib.events.system.FixturesInstallingEvent;
 import org.apache.isis.applib.services.WithTransactionScope;
+import org.apache.isis.applib.services.eventbus.EventBusService;
 
 /**
  * This service (API and implementation) provides a mechanism by which idempotent query results can be cached for the duration of an interaction.
@@ -48,6 +55,7 @@ public class QueryResultsCache implements WithTransactionScope {
 
     private static final Logger LOG = LoggerFactory.getLogger(QueryResultsCache.class);
 
+
     public static class Key {
         private final Class<?> callingClass;
         private final String methodName;
@@ -134,17 +142,35 @@ public class QueryResultsCache implements WithTransactionScope {
 
     @Programmatic
     public <T> T execute(final Callable<T> callable, final Class<?> callingClass, final String methodName, final Object... keys) {
+        if(control.isFixturesInstalling()) {
+            try {
+                return callable.call();
+            } catch (Exception e) {
+                throw new RuntimeException(e);
+            }
+        }
         final Key cacheKey = new Key(callingClass, methodName, keys);
-        return execute(callable, cacheKey);
+        return executeWithCaching(callable, cacheKey);
     }
 
     @Programmatic
     @SuppressWarnings("unchecked")
     public <T> T execute(final Callable<T> callable, final Key cacheKey) {
+        if(control.isFixturesInstalling()) {
+            try {
+                return callable.call();
+            } catch (Exception e) {
+                throw new RuntimeException(e);
+            }
+        }
+        return executeWithCaching(callable, cacheKey);
+    }
+
+    protected <T> T executeWithCaching(final Callable<T> callable, final Key cacheKey) {
         try {
             final Value<?> cacheValue = cache.get(cacheKey);
             logHitOrMiss(cacheKey, cacheValue);
-            if(cacheValue != null) { 
+            if(cacheValue != null) {
                 return (T) cacheValue.getResult();
             }
 
@@ -208,4 +234,47 @@ public class QueryResultsCache implements WithTransactionScope {
         cache.clear();
     }
 
+    /**
+     * In separate class because {@link QueryResultsCache} itself is request-scoped
+     */
+    @DomainService(nature = NatureOfService.DOMAIN)
+    public static class Control {
+
+        @PostConstruct
+        public void postConstruct() {
+            eventBusService.register(this);
+        }
+
+        @PreDestroy
+        public void preDestroy() {
+            eventBusService.unregister(this);
+        }
+
+        @Subscribe
+        @org.axonframework.eventhandling.annotation.EventHandler
+        public void on(FixturesInstallingEvent ev) {
+            fixturesInstalling = true;
+        }
+
+        @Subscribe
+        @org.axonframework.eventhandling.annotation.EventHandler
+        public void on(FixturesInstalledEvent ev) {
+            fixturesInstalling = false;
+        }
+
+        private boolean fixturesInstalling;
+
+        public boolean isFixturesInstalling() {
+            return fixturesInstalling;
+        }
+
+        @Inject
+        EventBusService eventBusService;
+    }
+
+
+    @Inject
+    Control control;
+
+
 }

http://git-wip-us.apache.org/repos/asf/isis/blob/f6976b14/core/pom.xml
----------------------------------------------------------------------
diff --git a/core/pom.xml b/core/pom.xml
index 66cfce5..2c9adf8 100644
--- a/core/pom.xml
+++ b/core/pom.xml
@@ -153,6 +153,7 @@
         <guice.version>4.0</guice.version>
         <picocontainer.version>2.15</picocontainer.version>
 
+
         <dom4j.version>1.6.1</dom4j.version>
         <jdom.version>2.0.2</jdom.version>
         <xstream.version>1.4.8</xstream.version>
@@ -1306,6 +1307,11 @@ ${license.additional-notes}
                 <artifactId>guava</artifactId>
                 <version>${guava.version}</version>
             </dependency>
+            <dependency>
+                <groupId>org.axonframework</groupId>
+                <artifactId>axon-core</artifactId>
+                <version>${axon-core.version}</version>
+            </dependency>
 
             <!-- Logging -->
             <dependency>