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 19:21:40 UTC
[isis] branch 2033-IoC updated: ISIS-2033: provides a
RequestContextServiceDefault
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 20c56de ISIS-2033: provides a RequestContextServiceDefault
20c56de is described below
commit 20c56de638325b97ff3399e8bd1d97ae39ef4374
Author: Andi Huber <ah...@apache.org>
AuthorDate: Sun Jan 27 20:21:30 2019 +0100
ISIS-2033: provides a RequestContextServiceDefault
Task-Url: https://issues.apache.org/jira/browse/ISIS-2033
---
.../core/plugins/ioc/RequestContextHandle.java | 16 +++++++++
.../core/plugins/ioc/RequestContextService.java | 17 +++++++++-
.../plugins/ioc/RequestContextServiceDefault.java | 38 ++++++++++++++++++++++
.../request/RequestContextHandleDefault.java | 16 +++++++++
.../request/RequestContextServiceWeld.java | 30 +++++++++++++----
.../integration/wicket/WebRequestCycleForIsis.java | 6 ++--
6 files changed, 112 insertions(+), 11 deletions(-)
diff --git a/core/commons/src/main/java/org/apache/isis/core/plugins/ioc/RequestContextHandle.java b/core/commons/src/main/java/org/apache/isis/core/plugins/ioc/RequestContextHandle.java
index 77bf8b9..0433572 100644
--- a/core/commons/src/main/java/org/apache/isis/core/plugins/ioc/RequestContextHandle.java
+++ b/core/commons/src/main/java/org/apache/isis/core/plugins/ioc/RequestContextHandle.java
@@ -1,3 +1,19 @@
+/*
+ * 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.core.plugins.ioc;
public interface RequestContextHandle extends AutoCloseable {
diff --git a/core/commons/src/main/java/org/apache/isis/core/plugins/ioc/RequestContextService.java b/core/commons/src/main/java/org/apache/isis/core/plugins/ioc/RequestContextService.java
index c72ce88..0587038 100644
--- a/core/commons/src/main/java/org/apache/isis/core/plugins/ioc/RequestContextService.java
+++ b/core/commons/src/main/java/org/apache/isis/core/plugins/ioc/RequestContextService.java
@@ -1,9 +1,24 @@
+/*
+ * 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.core.plugins.ioc;
public interface RequestContextService {
RequestContextHandle startRequest();
- boolean isActive();
static void closeHandle(RequestContextHandle requestContextHandle) {
if(requestContextHandle!=null) {
diff --git a/core/commons/src/main/java/org/apache/isis/core/plugins/ioc/RequestContextServiceDefault.java b/core/commons/src/main/java/org/apache/isis/core/plugins/ioc/RequestContextServiceDefault.java
new file mode 100644
index 0000000..b0c716d
--- /dev/null
+++ b/core/commons/src/main/java/org/apache/isis/core/plugins/ioc/RequestContextServiceDefault.java
@@ -0,0 +1,38 @@
+/*
+ * 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.core.plugins.ioc;
+
+import javax.annotation.Priority;
+import javax.enterprise.inject.Alternative;
+import javax.inject.Singleton;
+
+/**
+ * Acts as a no-op implementation, that is used as lowest priority default, whenever
+ * service-provisioning can not find any alternative with higher priority.
+ *
+ * @since 2.0.0-M3
+ *
+ */
+@Singleton @Alternative @Priority(0)
+public class RequestContextServiceDefault implements RequestContextService {
+
+ @Override
+ public RequestContextHandle startRequest() {
+ return null; // don't return a handle
+ }
+
+}
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/RequestContextHandleDefault.java
index a22ee05..23a8c3a 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/RequestContextHandleDefault.java
@@ -1,3 +1,19 @@
+/*
+ * 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.core.plugins.ioc.weld.services.request;
import org.apache.isis.core.plugins.ioc.RequestContextHandle;
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 11dac41..3e1ccf0 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
@@ -1,16 +1,35 @@
+/*
+ * 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.core.plugins.ioc.weld.services.request;
-import java.util.HashMap;
import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+import javax.annotation.Priority;
+import javax.enterprise.inject.Alternative;
import javax.inject.Inject;
import javax.inject.Singleton;
+import org.jboss.weld.context.bound.BoundRequestContext;
+
import org.apache.isis.core.plugins.ioc.RequestContextHandle;
import org.apache.isis.core.plugins.ioc.RequestContextService;
-import org.jboss.weld.context.bound.BoundRequestContext;
-@Singleton
+@Singleton @Alternative @Priority(10)
public class RequestContextServiceWeld implements RequestContextService {
/* Inject the BoundRequestContext. */
@@ -25,7 +44,7 @@ public class RequestContextServiceWeld implements RequestContextService {
return null; // if already active, don't return a handle
}
- final Map<String, Object> requestDataStore = new HashMap<>();
+ final Map<String, Object> requestDataStore = new ConcurrentHashMap<>();
// Associate the store with the context and activate the context
requestContext.associate(requestDataStore);
@@ -34,8 +53,7 @@ public class RequestContextServiceWeld implements RequestContextService {
return RequestContextHandleDefault.of(()->endRequest(requestDataStore));
}
- @Override
- public boolean isActive() {
+ private boolean isActive() {
return requestContext.isActive();
}
diff --git a/core/viewer-wicket-impl/src/main/java/org/apache/isis/viewer/wicket/viewer/integration/wicket/WebRequestCycleForIsis.java b/core/viewer-wicket-impl/src/main/java/org/apache/isis/viewer/wicket/viewer/integration/wicket/WebRequestCycleForIsis.java
index ed9da9f..4eb05e5 100644
--- a/core/viewer-wicket-impl/src/main/java/org/apache/isis/viewer/wicket/viewer/integration/wicket/WebRequestCycleForIsis.java
+++ b/core/viewer-wicket-impl/src/main/java/org/apache/isis/viewer/wicket/viewer/integration/wicket/WebRequestCycleForIsis.java
@@ -16,7 +16,6 @@
* specific language governing permissions and limitations
* under the License.
*/
-
package org.apache.isis.viewer.wicket.viewer.integration.wicket;
import java.lang.reflect.Constructor;
@@ -90,7 +89,7 @@ public class WebRequestCycleForIsis implements IRequestCycleListener {
private PageClassRegistry pageClassRegistry;
private final static _Probe probe = _Probe.unlimited().label("WebRequestCycleForIsis");
- private _Lazy<RequestContextService> lazyRequestContextService = _Lazy.of(()->
+ private _Lazy<RequestContextService> requestContextService = _Lazy.of(()->
_CDI.getSingleton(RequestContextService.class));
public final static MetaDataKey<RequestContextHandle> REQUEST_CONTEXT_HANDLE_KEY
@@ -104,11 +103,10 @@ public class WebRequestCycleForIsis implements IRequestCycleListener {
probe.println("onBeginRequest in");
- val requestContextService = lazyRequestContextService.get();
// this handle needs to be closed when the request-scope's life-cycle ends
// so we store it onto the requestCycle as meta-data entry, to be
// retrieved later at 'onEndRequest'
- val requestContextHandle = requestContextService.startRequest();
+ val requestContextHandle = requestContextService.get().startRequest();
if(requestContextHandle!=null) {
requestCycle.setMetaData(REQUEST_CONTEXT_HANDLE_KEY, requestContextHandle);
}