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/01/27 22:21:50 UTC

[isis] branch 2033-IoC updated: ISIS-2033: introduces a Service to provide a ConversationContext

This is an automated email from the ASF dual-hosted git repository.

ahuber pushed a commit to branch 2033-IoC
in repository https://gitbox.apache.org/repos/asf/isis.git


The following commit(s) were added to refs/heads/2033-IoC by this push:
     new cf1cf70  ISIS-2033: introduces a Service to provide a ConversationContext
cf1cf70 is described below

commit cf1cf70723fc7ec29529172e616eae882cba00f4
Author: Andi Huber <ah...@apache.org>
AuthorDate: Sun Jan 27 23:21:41 2019 +0100

    ISIS-2033: introduces a Service to provide a ConversationContext
    
    just stubs yet
    
    Task-Url: https://issues.apache.org/jira/browse/ISIS-2033
---
 .../plugins/ioc/ConversationContextHandle.java}    | 20 ++----
 .../plugins/ioc/ConversationContextService.java}   | 21 +++----
 .../request/ConversationContextServiceWeld.java    | 71 ++++++++++++++++++++++
 ...eDefault.java => RequestContextHandleWeld.java} |  2 +-
 .../request/RequestContextServiceWeld.java         |  2 +-
 5 files changed, 87 insertions(+), 29 deletions(-)

diff --git a/core/plugins/ioc-weld/src/main/java/org/apache/isis/core/plugins/ioc/weld/services/request/RequestContextHandleDefault.java b/core/commons/src/main/java/org/apache/isis/core/plugins/ioc/ConversationContextHandle.java
similarity index 69%
copy from core/plugins/ioc-weld/src/main/java/org/apache/isis/core/plugins/ioc/weld/services/request/RequestContextHandleDefault.java
copy to core/commons/src/main/java/org/apache/isis/core/plugins/ioc/ConversationContextHandle.java
index 23a8c3a..7c02d9c 100644
--- a/core/plugins/ioc-weld/src/main/java/org/apache/isis/core/plugins/ioc/weld/services/request/RequestContextHandleDefault.java
+++ b/core/commons/src/main/java/org/apache/isis/core/plugins/ioc/ConversationContextHandle.java
@@ -14,21 +14,13 @@
  *  See the License for the specific language governing permissions and
  *  limitations under the License.
  */
-package org.apache.isis.core.plugins.ioc.weld.services.request;
+package org.apache.isis.core.plugins.ioc;
 
-import org.apache.isis.core.plugins.ioc.RequestContextHandle;
+public interface ConversationContextHandle extends AutoCloseable {
 
-import lombok.RequiredArgsConstructor;
-
-@RequiredArgsConstructor(staticName="of")
-class RequestContextHandleDefault implements RequestContextHandle {
-
-	private final Runnable onClose;
+	/**
+	 * Refined to not throw a catched exception
+	 */
+	@Override void close();
 	
-	@Override
-	public void close() {
-		onClose.run();
-	}
-	
-
 }
diff --git a/core/plugins/ioc-weld/src/main/java/org/apache/isis/core/plugins/ioc/weld/services/request/RequestContextHandleDefault.java b/core/commons/src/main/java/org/apache/isis/core/plugins/ioc/ConversationContextService.java
similarity index 69%
copy from core/plugins/ioc-weld/src/main/java/org/apache/isis/core/plugins/ioc/weld/services/request/RequestContextHandleDefault.java
copy to core/commons/src/main/java/org/apache/isis/core/plugins/ioc/ConversationContextService.java
index 23a8c3a..9518582 100644
--- a/core/plugins/ioc-weld/src/main/java/org/apache/isis/core/plugins/ioc/weld/services/request/RequestContextHandleDefault.java
+++ b/core/commons/src/main/java/org/apache/isis/core/plugins/ioc/ConversationContextService.java
@@ -14,21 +14,16 @@
  *  See the License for the specific language governing permissions and
  *  limitations under the License.
  */
-package org.apache.isis.core.plugins.ioc.weld.services.request;
+package org.apache.isis.core.plugins.ioc;
 
-import org.apache.isis.core.plugins.ioc.RequestContextHandle;
+public interface ConversationContextService {
 
-import lombok.RequiredArgsConstructor;
-
-@RequiredArgsConstructor(staticName="of")
-class RequestContextHandleDefault implements RequestContextHandle {
-
-	private final Runnable onClose;
-	
-	@Override
-	public void close() {
-		onClose.run();
-	}
+    //TBD ... ConversationContextHandle startRequest();
 	
+    static void closeHandle(ConversationContextHandle conversationContextHandle) {
+        if(conversationContextHandle!=null) {
+            conversationContextHandle.close();
+        }
+    }
 
 }
diff --git a/core/plugins/ioc-weld/src/main/java/org/apache/isis/core/plugins/ioc/weld/services/request/ConversationContextServiceWeld.java b/core/plugins/ioc-weld/src/main/java/org/apache/isis/core/plugins/ioc/weld/services/request/ConversationContextServiceWeld.java
new file mode 100644
index 0000000..99ac180
--- /dev/null
+++ b/core/plugins/ioc-weld/src/main/java/org/apache/isis/core/plugins/ioc/weld/services/request/ConversationContextServiceWeld.java
@@ -0,0 +1,71 @@
+package org.apache.isis.core.plugins.ioc.weld.services.request;
+
+import java.util.Map;
+
+import javax.inject.Inject;
+import javax.inject.Singleton;
+
+import org.jboss.weld.context.bound.BoundConversationContext;
+import org.jboss.weld.context.bound.MutableBoundRequest;
+
+import org.apache.isis.core.plugins.ioc.ConversationContextService;
+
+@Singleton //FIXME [2033] just a copy and paste stub yet
+public class ConversationContextServiceWeld implements ConversationContextService {
+
+    @Inject BoundConversationContext conversationContext;
+
+
+    /* Start a transient conversation */
+    /* Provide a data store which will last the lifetime of the request */
+    /* and one that will last the lifetime of the session */
+    public void startTransientConversation(Map<String, Object> requestDataStore,
+            Map<String, Object> sessionDataStore) {
+
+        resumeOrStartConversation(requestDataStore, sessionDataStore, null);
+    }
+
+
+    /* Start a transient conversation (if cid is null) or resume a non-transient */
+    /* conversation. Provide a data store which will last the lifetime of the request */
+    /* and one that will last the lifetime of the session */
+    public void resumeOrStartConversation(
+            Map<String, Object> requestDataStore,
+            Map<String, Object> sessionDataStore,
+            String cid) {
+
+        /* Associate the stores with the context and activate the context */
+        /* BoundRequest just wraps the two datastores */
+        conversationContext.associate(new MutableBoundRequest(requestDataStore, sessionDataStore));
+
+        // Pass the cid in
+        conversationContext.activate(cid);
+
+    }
+
+
+    /* End the conversations, providing the same data store as was used to start */
+    /* the request. Any transient conversations will be destroyed, any newly-promoted */
+    /* conversations will be placed into the session */
+    public void endOrPassivateConversation(
+            Map<String, Object> requestDataStore,
+            Map<String, Object> sessionDataStore) {
+
+        try {
+
+            /* Invalidate the conversation (all transient conversations will be scheduled for destruction) */
+            conversationContext.invalidate();
+
+            /* Deactivate the conversation, causing all transient conversations to be destroyed */
+            conversationContext.deactivate();
+
+        } finally {
+
+            /* Ensure that whatever happens we dissociate to prevent memory leaks*/
+            conversationContext.dissociate(new MutableBoundRequest(requestDataStore, sessionDataStore));
+
+        }
+
+    }
+
+}
diff --git a/core/plugins/ioc-weld/src/main/java/org/apache/isis/core/plugins/ioc/weld/services/request/RequestContextHandleDefault.java b/core/plugins/ioc-weld/src/main/java/org/apache/isis/core/plugins/ioc/weld/services/request/RequestContextHandleWeld.java
similarity index 94%
rename from core/plugins/ioc-weld/src/main/java/org/apache/isis/core/plugins/ioc/weld/services/request/RequestContextHandleDefault.java
rename to core/plugins/ioc-weld/src/main/java/org/apache/isis/core/plugins/ioc/weld/services/request/RequestContextHandleWeld.java
index 23a8c3a..8358fbb 100644
--- a/core/plugins/ioc-weld/src/main/java/org/apache/isis/core/plugins/ioc/weld/services/request/RequestContextHandleDefault.java
+++ b/core/plugins/ioc-weld/src/main/java/org/apache/isis/core/plugins/ioc/weld/services/request/RequestContextHandleWeld.java
@@ -21,7 +21,7 @@ import org.apache.isis.core.plugins.ioc.RequestContextHandle;
 import lombok.RequiredArgsConstructor;
 
 @RequiredArgsConstructor(staticName="of")
-class RequestContextHandleDefault implements RequestContextHandle {
+class RequestContextHandleWeld implements RequestContextHandle {
 
 	private final Runnable onClose;
 	
diff --git a/core/plugins/ioc-weld/src/main/java/org/apache/isis/core/plugins/ioc/weld/services/request/RequestContextServiceWeld.java b/core/plugins/ioc-weld/src/main/java/org/apache/isis/core/plugins/ioc/weld/services/request/RequestContextServiceWeld.java
index 3e1ccf0..3be15d2 100644
--- a/core/plugins/ioc-weld/src/main/java/org/apache/isis/core/plugins/ioc/weld/services/request/RequestContextServiceWeld.java
+++ b/core/plugins/ioc-weld/src/main/java/org/apache/isis/core/plugins/ioc/weld/services/request/RequestContextServiceWeld.java
@@ -50,7 +50,7 @@ public class RequestContextServiceWeld implements RequestContextService {
 		requestContext.associate(requestDataStore);
 		requestContext.activate();
 		
-		return RequestContextHandleDefault.of(()->endRequest(requestDataStore));
+		return RequestContextHandleWeld.of(()->endRequest(requestDataStore));
 	}
 
 	private boolean isActive() {