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 2020/03/17 00:08:31 UTC
[isis] 29/42: ISIS-2278: initial spike, to tidy up
This is an automated email from the ASF dual-hosted git repository.
danhaywood pushed a commit to branch ISIS-2278
in repository https://gitbox.apache.org/repos/asf/isis.git
commit 3370b630934bd3ad8bdec7a9fb42696c2860f1fd
Author: danhaywood <da...@haywood-associates.co.uk>
AuthorDate: Sat Mar 14 12:39:08 2020 +0000
ISIS-2278: initial spike, to tidy up
---
.../services/command/CommandExecutorService.java | 11 +-
.../applib/services/wrapper/WrapperFactory.java | 65 +++-
.../services/ProxyFactoryServiceByteBuddy.java | 3 +-
.../pages/sections/isis.viewer.restfulobjects.adoc | 2 +-
.../command/CommandExecutorServiceDefault.java | 135 +++++----
.../runtimeservices/wrapper/AsyncWrapDefault.java | 333 ---------------------
.../wrapper/WrapperFactoryDefault.java | 231 +++++++++++---
.../wrapper/proxy/ProxyCreator.java | 12 +-
.../wrapper/WrapperFactoryDefaultTest.java | 4 +-
.../demoapp/dom/events/DemoEventSubscriber.java | 5 +-
.../testdomain/auditing/AuditerServiceTest.java | 10 +-
.../commandexecution/WrapperAsyncTest.java | 14 +-
.../publishing/PublisherServiceTest.java | 10 +-
13 files changed, 362 insertions(+), 473 deletions(-)
diff --git a/api/applib/src/main/java/org/apache/isis/applib/services/command/CommandExecutorService.java b/api/applib/src/main/java/org/apache/isis/applib/services/command/CommandExecutorService.java
index 917a4e5..56d029b 100644
--- a/api/applib/src/main/java/org/apache/isis/applib/services/command/CommandExecutorService.java
+++ b/api/applib/src/main/java/org/apache/isis/applib/services/command/CommandExecutorService.java
@@ -18,6 +18,9 @@
*/
package org.apache.isis.applib.services.command;
+import org.apache.isis.applib.services.bookmark.Bookmark;
+import org.apache.isis.schema.cmd.v2.CommandDto;
+
// tag::refguide[]
public interface CommandExecutorService {
@@ -50,8 +53,12 @@ public interface CommandExecutorService {
*/
// tag::refguide[]
void executeCommand(
- SudoPolicy sudoPolicy, // <.>
- CommandWithDto commandWithDto // <.>
+ SudoPolicy sudoPolicy, // <.>
+ CommandWithDto commandWithDto // <.>
+ );
+
+ Bookmark executeCommand(
+ CommandDto commandDto // <.>
);
}
diff --git a/api/applib/src/main/java/org/apache/isis/applib/services/wrapper/WrapperFactory.java b/api/applib/src/main/java/org/apache/isis/applib/services/wrapper/WrapperFactory.java
index 0cfd47e..2a932a8 100644
--- a/api/applib/src/main/java/org/apache/isis/applib/services/wrapper/WrapperFactory.java
+++ b/api/applib/src/main/java/org/apache/isis/applib/services/wrapper/WrapperFactory.java
@@ -20,6 +20,8 @@
package org.apache.isis.applib.services.wrapper;
import java.util.List;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.ForkJoinPool;
import org.apache.isis.applib.services.factory.FactoryService;
import org.apache.isis.applib.services.wrapper.events.InteractionEvent;
@@ -30,6 +32,7 @@ import static org.apache.isis.core.commons.collections.ImmutableEnumSet.*;
import lombok.AccessLevel;
import lombok.RequiredArgsConstructor;
+import lombok.val;
import lombok.experimental.UtilityClass;
/**
@@ -154,12 +157,13 @@ public interface WrapperFactory {
}
// end::refguide-2[]
- // tag::refguide-2[]
+
+ // tag::refguide-3[]
enum RuleCheckingPolicy {
SYNC, // <.>
ASYNC // <.>
}
- // tag::refguide-3[]
+ // end::refguide-3[]
/**
* Same as {@link #wrap(Object)}, except the actual execution occurs only if
@@ -171,7 +175,7 @@ public interface WrapperFactory {
*/
// tag::refguide[]
<T> T wrap(T domainObject, // <.>
- ImmutableEnumSet<ExecutionMode> mode);
+ ImmutableEnumSet<ExecutionMode> modes);
// end::refguide[]
/**
@@ -246,31 +250,38 @@ public interface WrapperFactory {
//
/**
- * Returns a {@link AsyncWrap} bound to the provided {@code domainObject},
- * to prepare for type-safe asynchronous action execution.
+ * Returns a proxy object for the provided {@code domainObject},
+ * through which can execute the action asynchronously.
*
* @param <T>
* @param domainObject
* @param mode
*
+ * @param executorService
* @since 2.0
*/
// tag::refguide-async[]
<T> T async(T domainObject, // <.>
ImmutableEnumSet<ExecutionMode> mode,
- RuleCheckingPolicy ruleCheckingPolicy);
+ RuleCheckingPolicy ruleCheckingPolicy,
+ ExecutorService executorService);
// end::refguide-async[]
// tag::refguide-async[]
- <T> T async(T domainObject, // <.>
- ImmutableEnumSet<ExecutionMode> mode);
+ default <T> T async(T domainObject, // <.>
+ ImmutableEnumSet<ExecutionMode> modes) {
+ // end::refguide-async[]
+
+ return async(domainObject, modes, RuleCheckingPolicy.ASYNC, ForkJoinPool.commonPool());
+
+ // tag::refguide-async[]
+ // ...
+ }
// end::refguide-async[]
/**
* Shortcut for {@link #async(Object, ImmutableEnumSet)} using execution mode
* {@link ExecutionModes#EXECUTE}.
- * @param <T>
- * @param domainObject
*
* @since 2.0
*/
@@ -286,20 +297,48 @@ public interface WrapperFactory {
// end::refguide-async[]
/**
+ * Returns a proxy object for the provided {@code mixinClass},
+ * through which can execute the action asynchronously.
+ *
+ * @param <T>
+ * @param mixinClass
+ * @param mixedIn
+ * @param modes
+ *
+ * @since 2.0
+ */
+ // tag::refguide-async[]
+ <T> T asyncMixin( // <.>
+ Class<T> mixinClass, Object mixedIn,
+ ImmutableEnumSet<ExecutionMode> modes,
+ RuleCheckingPolicy ruleCheckingPolicy,
+ ExecutorService executorService);
+
+ // end::refguide-async[]
+ /**
* Returns a {@link AsyncWrap} bound to the provided {@code mixinClass},
* to prepare for type-safe asynchronous action execution.
*
* @param <T>
* @param mixinClass
* @param mixedIn
- * @param mode
+ * @param modes
*
* @since 2.0
*/
// tag::refguide-async[]
- <T> T asyncMixin( // <.>
+ default <T> T asyncMixin( // <.>
Class<T> mixinClass, Object mixedIn,
- ImmutableEnumSet<ExecutionMode> mode);
+ ImmutableEnumSet<ExecutionMode> modes) {
+ // end::refguide-async[]
+
+ return asyncMixin(
+ mixinClass, mixedIn, modes,
+ RuleCheckingPolicy.ASYNC, ForkJoinPool.commonPool());
+
+ // tag::refguide-async[]
+ // ...
+ }
// end::refguide-async[]
/**
diff --git a/core/codegen-bytebuddy/src/main/java/org/apache/isis/core/codegen/bytebuddy/services/ProxyFactoryServiceByteBuddy.java b/core/codegen-bytebuddy/src/main/java/org/apache/isis/core/codegen/bytebuddy/services/ProxyFactoryServiceByteBuddy.java
index 2dae439..e995394e 100644
--- a/core/codegen-bytebuddy/src/main/java/org/apache/isis/core/codegen/bytebuddy/services/ProxyFactoryServiceByteBuddy.java
+++ b/core/codegen-bytebuddy/src/main/java/org/apache/isis/core/codegen/bytebuddy/services/ProxyFactoryServiceByteBuddy.java
@@ -34,6 +34,7 @@ import org.apache.isis.core.commons.internal.base._NullSafe;
import org.apache.isis.core.commons.internal.context._Context;
import org.apache.isis.core.commons.internal.plugins.codegen.ProxyFactory;
import org.apache.isis.core.commons.internal.plugins.codegen.ProxyFactoryService;
+import org.apache.isis.core.commons.internal.plugins.codegen.ProxyFactoryServiceAbstract;
import net.bytebuddy.ByteBuddy;
import net.bytebuddy.NamingStrategy;
@@ -42,7 +43,7 @@ import net.bytebuddy.implementation.InvocationHandlerAdapter;
import net.bytebuddy.matcher.ElementMatchers;
@Service
-public class ProxyFactoryServiceByteBuddy implements ProxyFactoryService {
+public class ProxyFactoryServiceByteBuddy extends ProxyFactoryServiceAbstract {
private final ClassLoadingStrategyAdvisor strategyAdvisor = new ClassLoadingStrategyAdvisor();
diff --git a/core/config/src/main/adoc/modules/config/pages/sections/isis.viewer.restfulobjects.adoc b/core/config/src/main/adoc/modules/config/pages/sections/isis.viewer.restfulobjects.adoc
index 82e0892..3da5008 100644
--- a/core/config/src/main/adoc/modules/config/pages/sections/isis.viewer.restfulobjects.adoc
+++ b/core/config/src/main/adoc/modules/config/pages/sections/isis.viewer.restfulobjects.adoc
@@ -17,7 +17,7 @@ isis.viewer.restfulobjects. +
base-uri
|
-| If left unset (the default), then the RO viewer will use the ``UriInfo`` (injected using ``Context``) to figure out the base Uri (used to render ``href``s).
+| If left unset (the default), then the RO viewer will use the ``UriInfo`` (injected using ``AsyncContext``) to figure out the base Uri (used to render ``href``s).
This will be correct much of the time, but will almost certainly be wrong if there is a reverse proxy.
diff --git a/core/runtimeservices/src/main/java/org/apache/isis/core/runtimeservices/command/CommandExecutorServiceDefault.java b/core/runtimeservices/src/main/java/org/apache/isis/core/runtimeservices/command/CommandExecutorServiceDefault.java
index bf0901f..d729583 100644
--- a/core/runtimeservices/src/main/java/org/apache/isis/core/runtimeservices/command/CommandExecutorServiceDefault.java
+++ b/core/runtimeservices/src/main/java/org/apache/isis/core/runtimeservices/command/CommandExecutorServiceDefault.java
@@ -21,6 +21,7 @@ package org.apache.isis.core.runtimeservices.command;
import java.sql.Timestamp;
import java.util.Collections;
import java.util.List;
+import java.util.Optional;
import java.util.stream.Collectors;
import java.util.stream.Stream;
@@ -33,6 +34,7 @@ import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Service;
import org.apache.isis.applib.annotation.OrderPrecedence;
+import org.apache.isis.applib.graph.tree.LazyTreeNode;
import org.apache.isis.applib.services.bookmark.Bookmark;
import org.apache.isis.applib.services.bookmark.BookmarkService;
import org.apache.isis.applib.services.clock.ClockService;
@@ -47,9 +49,13 @@ import org.apache.isis.applib.util.schema.CommandDtoUtils;
import org.apache.isis.applib.util.schema.CommonDtoUtils;
import org.apache.isis.core.commons.internal.collections._Lists;
import org.apache.isis.core.commons.internal.exceptions._Exceptions;
+import org.apache.isis.core.metamodel.adapter.oid.Oid;
+import org.apache.isis.core.metamodel.adapter.oid.RootOid;
import org.apache.isis.core.metamodel.consent.InteractionInitiatedBy;
import org.apache.isis.core.metamodel.facets.actions.action.invocation.CommandUtil;
+import org.apache.isis.core.metamodel.objectmanager.load.ObjectLoader;
import org.apache.isis.core.metamodel.spec.ManagedObject;
+import org.apache.isis.core.metamodel.spec.ObjectSpecId;
import org.apache.isis.core.metamodel.spec.ObjectSpecification;
import org.apache.isis.core.metamodel.spec.feature.Contributed;
import org.apache.isis.core.metamodel.spec.feature.ObjectAction;
@@ -57,7 +63,9 @@ import org.apache.isis.core.metamodel.spec.feature.ObjectAssociation;
import org.apache.isis.core.metamodel.spec.feature.OneToOneAssociation;
import org.apache.isis.core.metamodel.specloader.SpecificationLoader;
import org.apache.isis.core.runtime.persistence.session.PersistenceSession;
+import org.apache.isis.core.runtime.session.IsisSession;
import org.apache.isis.core.runtime.session.IsisSessionFactory;
+import org.apache.isis.core.runtime.session.IsisSessionTracker;
import org.apache.isis.schema.cmd.v2.ActionDto;
import org.apache.isis.schema.cmd.v2.CommandDto;
import org.apache.isis.schema.cmd.v2.MemberDto;
@@ -137,71 +145,77 @@ public class CommandExecutorServiceDefault implements CommandExecutorService {
? currentExecution.getStartedAt()
: clockService.nowAsJavaSqlTimestamp();
- commandWithDto.internal().setStartedAt(startedAt);
+ commandWithDto.internal().setStartedAt(startedAt);
- final CommandDto dto = commandWithDto.asDto();
+ final CommandDto dto = commandWithDto.asDto();
- final MemberDto memberDto = dto.getMember();
- final String memberId = memberDto.getMemberIdentifier();
+ Bookmark resultBookmark = executeCommand(dto);
+ commandWithDto.internal().setResult(resultBookmark);
+ }
- final OidsDto oidsDto = CommandDtoUtils.targetsFor(dto);
- final List<OidDto> targetOidDtos = oidsDto.getOid();
+ @Override
+ public Bookmark executeCommand(CommandDto dto) {
- final InteractionType interactionType = memberDto.getInteractionType();
- if(interactionType == InteractionType.ACTION_INVOCATION) {
+ final MemberDto memberDto = dto.getMember();
+ final String memberId = memberDto.getMemberIdentifier();
- final ActionDto actionDto = (ActionDto) memberDto;
+ final OidsDto oidsDto = CommandDtoUtils.targetsFor(dto);
+ final List<OidDto> targetOidDtos = oidsDto.getOid();
- for (OidDto targetOidDto : targetOidDtos) {
+ final InteractionType interactionType = memberDto.getInteractionType();
+ if(interactionType == InteractionType.ACTION_INVOCATION) {
- val targetAdapter = adapterFor(targetOidDto);
- final ObjectAction objectAction = findObjectAction(targetAdapter, memberId);
+ final ActionDto actionDto = (ActionDto) memberDto;
- // we pass 'null' for the mixedInAdapter; if this action _is_ a mixin then
- // it will switch the targetAdapter to be the mixedInAdapter transparently
- val argAdapters = argAdaptersFor(actionDto);
- val resultAdapter = objectAction.execute(
- targetAdapter, null, argAdapters, InteractionInitiatedBy.FRAMEWORK);
+ for (OidDto targetOidDto : targetOidDtos) {
- // flush any Isis PersistenceCommands pending
- // (else might get transient objects for the return value)
- transactionService.flushTransaction();
+ val targetAdapter = adapterFor(targetOidDto);
+ final ObjectAction objectAction = findObjectAction(targetAdapter, memberId);
- //
- // for the result adapter, we could alternatively have used...
- // (priorExecution populated by the push/pop within the interaction object)
- //
- // final Interaction.Execution priorExecution = backgroundInteraction.getPriorExecution();
- // Object unused = priorExecution.getReturned();
- //
+ // we pass 'null' for the mixedInAdapter; if this action _is_ a mixin then
+ // it will switch the targetAdapter to be the mixedInAdapter transparently
+ val argAdapters = argAdaptersFor(actionDto);
+ val resultAdapter = objectAction.execute(
+ targetAdapter, null, argAdapters, InteractionInitiatedBy.FRAMEWORK);
- // REVIEW: this doesn't really make sense if >1 action
- if(resultAdapter != null) {
- Bookmark resultBookmark = CommandUtil.bookmarkFor(resultAdapter);
- commandWithDto.internal().setResult(resultBookmark);
- }
- }
- } else {
+ // flush any Isis PersistenceCommands pending
+ // (else might get transient objects for the return value)
+ transactionService.flushTransaction();
- final PropertyDto propertyDto = (PropertyDto) memberDto;
+ //
+ // for the result adapter, we could alternatively have used...
+ // (priorExecution populated by the push/pop within the interaction object)
+ //
+ // final Interaction.Execution priorExecution = backgroundInteraction.getPriorExecution();
+ // Object unused = priorExecution.getReturned();
+ //
- for (OidDto targetOidDto : targetOidDtos) {
+ // REVIEW: this doesn't really make sense if >1 action
+ if(resultAdapter != null) {
+ return CommandUtil.bookmarkFor(resultAdapter);
+ }
+ }
+ } else {
- final Bookmark bookmark = Bookmark.from(targetOidDto);
- final Object targetObject = bookmarkService.lookup(bookmark);
+ final PropertyDto propertyDto = (PropertyDto) memberDto;
- val targetAdapter = adapterFor(targetObject);
+ for (OidDto targetOidDto : targetOidDtos) {
- final OneToOneAssociation property = findOneToOneAssociation(targetAdapter, memberId);
+ final Bookmark bookmark = Bookmark.from(targetOidDto);
+ final Object targetObject = bookmarkService.lookup(bookmark);
- val newValueAdapter = newValueAdapterFor(propertyDto);
+ val targetAdapter = adapterFor(targetObject);
- property.set(targetAdapter, newValueAdapter, InteractionInitiatedBy.FRAMEWORK);
+ final OneToOneAssociation property = findOneToOneAssociation(targetAdapter, memberId);
- // there is no return value for property modifications.
- }
- }
+ val newValueAdapter = newValueAdapterFor(propertyDto);
+ property.set(targetAdapter, newValueAdapter, InteractionInitiatedBy.FRAMEWORK);
+
+ // there is no return value for property modifications.
+ }
+ }
+ return null;
}
protected void afterCommit(CommandWithDto commandWithDto, Exception exceptionIfAny) {
@@ -319,12 +333,33 @@ public class CommandExecutorServiceDefault implements CommandExecutorService {
}
private ManagedObject adapterFor(final Object pojo) {
+ if(pojo instanceof OidDto) {
+ return adapterFor((OidDto)pojo);
+ }
+ if(pojo instanceof RootOid) {
+ return adapterFor((RootOid) pojo);
+ }
+ // value type
return ManagedObject.of(getSpecificationLoader()::loadSpecification, pojo);
-
- //legacy of
- //return ObjectAdapterLegacy.__CommandExecutorServiceDefault.adapterFor(targetObject);
}
+ private ManagedObject adapterFor(final OidDto oid) {
+ val oidStr = Oid.marshaller().joinAsOid(oid.getType(), oid.getId());
+ val rootOid = Oid.unmarshaller().unmarshal(oidStr, RootOid.class);
+ return adapterFor(rootOid);
+ }
+
+ private ManagedObject adapterFor(final RootOid oid) {
+ val objectSpec = specificationLoader.loadSpecification(oid.getObjectSpecId());
+ val loadRequest = ObjectLoader.Request.of(objectSpec, oid.getIdentifier());
+
+ Optional<IsisSession> isisSession = isisSessionTracker.currentSession();
+ return isisSession
+ .map(x -> x.getObjectManager().loadObject(loadRequest))
+ .orElse(null);
+ }
+
+
// //////////////////////////////////////
protected IsisSessionFactory getIsisSessionFactory() {
@@ -349,8 +384,8 @@ public class CommandExecutorServiceDefault implements CommandExecutorService {
@Inject TransactionService transactionService;
@Inject SpecificationLoader specificationLoader;
@Inject IsisSessionFactory isisSessionFactory;
-
+ @Inject IsisSessionTracker isisSessionTracker;
+
@Inject private javax.inject.Provider<InteractionContext> interactionContextProvider;
- //@Inject private javax.inject.Provider<CommandContext> commandContextProvider;
}
diff --git a/core/runtimeservices/src/main/java/org/apache/isis/core/runtimeservices/wrapper/AsyncWrapDefault.java b/core/runtimeservices/src/main/java/org/apache/isis/core/runtimeservices/wrapper/AsyncWrapDefault.java
deleted file mode 100644
index 9ed9851..0000000
--- a/core/runtimeservices/src/main/java/org/apache/isis/core/runtimeservices/wrapper/AsyncWrapDefault.java
+++ /dev/null
@@ -1,333 +0,0 @@
-/*
- * 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.runtimeservices.wrapper;
-
-import java.util.concurrent.Callable;
-import java.util.concurrent.CompletableFuture;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Future;
-import java.util.function.Consumer;
-import java.util.function.Supplier;
-
-import org.apache.isis.applib.services.bookmark.Bookmark;
-import org.apache.isis.applib.services.bookmark.BookmarkService;
-import org.apache.isis.applib.services.wrapper.AsyncWrap;
-import org.apache.isis.applib.services.wrapper.WrapperFactory;
-import org.apache.isis.applib.services.wrapper.WrapperFactory.ExecutionMode;
-import org.apache.isis.applib.services.xactn.TransactionService;
-import org.apache.isis.core.commons.collections.ImmutableEnumSet;
-import org.apache.isis.applib.services.MethodReferences.Call1;
-import org.apache.isis.applib.services.MethodReferences.Call2;
-import org.apache.isis.applib.services.MethodReferences.Call3;
-import org.apache.isis.applib.services.MethodReferences.Call4;
-import org.apache.isis.applib.services.MethodReferences.Call5;
-import org.apache.isis.core.commons.internal.exceptions._Exceptions;
-import org.apache.isis.core.runtime.session.IsisSessionFactory;
-import org.apache.isis.core.security.authentication.AuthenticationSessionTracker;
-
-import lombok.Getter;
-import lombok.NonNull;
-import lombok.val;
-import lombok.extern.log4j.Log4j2;
-/**
- *
- * @since 2.0
- *
- */
-@Log4j2
-class AsyncWrapDefault<T> implements AsyncWrap<T> {
-
- @NonNull
- private final WrapperFactory wrapperFactory;
-
- @NonNull
- private final IsisSessionFactory isisSessionFactory;
-
- @NonNull
- private final AuthenticationSessionTracker authenticationSessionTracker;
-
- @NonNull
- private final TransactionService transactionService;
-
- @NonNull
- private final BookmarkService bookmarkService;
-
- @NonNull
- private final Bookmark bookmark;
-
- private final Class<T> domainClass;
-
- @Getter(onMethod = @__(@Override))
- private ImmutableEnumSet<ExecutionMode> executionModes;
-
- private ImmutableEnumSet<ExecutionMode> executionModesSync;
-
- private ImmutableEnumSet<ExecutionMode> executionModesAsync;
-
- @NonNull
- @Getter(onMethod = @__({@Override}))
- private ExecutorService executorService;
-
- @NonNull
- @Getter(onMethod = @__({@Override}))
- private Consumer<Exception> exceptionHandler;
-
- @NonNull
- @Getter(onMethod = @__({@Override}))
- private WrapperFactory.RuleCheckingPolicy ruleCheckingPolicy;
-
- AsyncWrapDefault(
- final WrapperFactory wrapperFactory,
- final IsisSessionFactory isisSessionFactory,
- final AuthenticationSessionTracker authenticationSessionTracker,
- final TransactionService transactionService,
- final BookmarkService bookmarkService,
- final T domainObject,
- final ImmutableEnumSet<ExecutionMode> executionModes,
- final ExecutorService executorService,
- final Consumer<Exception> exceptionHandler,
- final WrapperFactory.RuleCheckingPolicy ruleCheckingPolicy) {
-
- this.wrapperFactory = wrapperFactory;
- this.isisSessionFactory = isisSessionFactory;
- this.authenticationSessionTracker = authenticationSessionTracker;
- this.transactionService = transactionService;
- this.bookmarkService = bookmarkService;
- this.bookmark = bookmarkService.bookmarkFor(domainObject);
- this.domainClass = (Class<T>) domainObject.getClass();
- this.executionModes = executionModes;
-
- withRuleCheckingPolicy(ruleCheckingPolicy);
- withExecutorService(executorService);
- withExceptionHandler(exceptionHandler);
- }
-
- private void deriveExecutionModes() {
-
- if(executionModes.contains(ExecutionMode.SKIP_RULE_VALIDATION)) {
- // ruleCheckingPolicy doesn't matter
- executionModesSync = WrapperFactory.ExecutionModes.NOOP;
- executionModesAsync = executionModes;
- } else {
- switch (ruleCheckingPolicy) {
- case SYNC:
- // move rule validation to be performed synchronously.
- executionModesSync = WrapperFactory.ExecutionModes.NO_EXECUTE; // ie do check rules.
- val tmp = executionModes.toEnumSet();
- tmp.add(ExecutionMode.SKIP_RULE_VALIDATION);
- this.executionModesAsync = ImmutableEnumSet.from(tmp);
- break;
- case ASYNC:
- executionModesSync = WrapperFactory.ExecutionModes.NOOP;
- this.executionModesAsync = executionModes;
- break;
- }
- }
- }
-
-
- /**
- * Fine-tune the executor.
- */
- public AsyncWrap<T> withExecutorService(ExecutorService executorService) {
- this.executorService = executorService;
- return this;
- }
-
- /**
- * Fine-tune the exception handler.
- */
- @Override
- public AsyncWrap<T> withExceptionHandler(Consumer<Exception> handler) {
- this.exceptionHandler = handler;
- return this;
- }
-
- /**
- * Adjust whether rule checking happens immediately or asynchronously.
- */
- @Override
- public AsyncWrap<T> withRuleCheckingPolicy(WrapperFactory.RuleCheckingPolicy ruleCheckingPolicy) {
- this.ruleCheckingPolicy = ruleCheckingPolicy;
- deriveExecutionModes();
- return this;
- }
-
- // -- METHOD REFERENCE MATCHERS (WITH RETURN VALUE)
-
- @Override
- public <R> Future<R> call(Call1<? extends R, ? super T> action) {
-
- if(shouldValidateSync()) {
- T lookup = bookmarkService.lookup(bookmark, this.domainClass);
- val proxy = wrapperFactory.wrap(lookup, executionModesSync);
- action.call(proxy);
- }
-
- if(shouldValidateAsync() || shouldExecuteAsync()) {
- return submit(()-> {
-
- final T lookup = bookmarkService.lookup(bookmark, this.domainClass);
- val proxy = wrapperFactory.wrap(lookup, executionModesAsync);
- return action.call(proxy);
- });
- }
-
- return CompletableFuture.completedFuture(null);
- }
-
-
- @Override
- public <R, A1> Future<R> call(Call2<? extends R, ? super T, A1> action, A1 arg1) {
-
- if(shouldValidateSync()) {
- T lookup = bookmarkService.lookup(bookmark, this.domainClass);
- val proxy = wrapperFactory.wrap(lookup, executionModesSync);
- action.call(proxy, arg1);
- }
-
- if(shouldValidateAsync() || shouldExecuteAsync()) {
- return submit(()-> {
-
- final T lookup = bookmarkService.lookup(bookmark, this.domainClass);
- val proxy = wrapperFactory.wrap(lookup, executionModesAsync);
- return action.call(proxy, arg1);
- });
- }
-
- return CompletableFuture.completedFuture(null);
- }
-
- @Override
- public <R, A1, A2> Future<R> call(Call3<? extends R, ? super T, A1, A2> action, A1 arg1, A2 arg2) {
-
- if(shouldValidateSync()) {
- T lookup = bookmarkService.lookup(bookmark, this.domainClass);
- val proxy = wrapperFactory.wrap(lookup, executionModesSync);
- action.call(proxy, arg1, arg2);
- }
-
- if(shouldValidateAsync() || shouldExecuteAsync()) {
- return submit(()-> {
-
- final T lookup = bookmarkService.lookup(bookmark, this.domainClass);
- val proxy = wrapperFactory.wrap(lookup, executionModesAsync);
- return action.call(proxy, arg1, arg2);
- });
- }
-
- return CompletableFuture.completedFuture(null);
- }
-
-
- @Override
- public <R, A1, A2, A3> Future<R> call(Call4<? extends R, ? super T, A1, A2, A3> action,
- A1 arg1, A2 arg2, A3 arg3) {
-
- if(shouldValidateSync()) {
- T lookup = bookmarkService.lookup(bookmark, this.domainClass);
- val proxy = wrapperFactory.wrap(lookup, executionModesSync);
- action.call(proxy, arg1, arg2, arg3);
- }
-
- if(shouldValidateAsync() || shouldExecuteAsync()) {
- return submit(()-> {
-
- final T lookup = bookmarkService.lookup(bookmark, this.domainClass);
- val proxy = wrapperFactory.wrap(lookup, executionModesAsync);
- return action.call(proxy, arg1, arg2, arg3);
- });
- }
-
- return CompletableFuture.completedFuture(null);
- }
-
-
- @Override
- public <R, A1, A2, A3, A4> Future<R> call(Call5<? extends R, ? super T, A1, A2, A3, A4> action,
- A1 arg1, A2 arg2, A3 arg3, A4 arg4) {
-
- if(shouldValidateSync()) {
- T lookup = bookmarkService.lookup(bookmark, this.domainClass);
- val proxy = wrapperFactory.wrap(lookup, executionModesSync);
- action.call(proxy, arg1, arg2, arg3, arg4);
- }
-
- if(shouldValidateAsync() || shouldExecuteAsync()) {
- return submit(()-> {
-
- final T lookup = bookmarkService.lookup(bookmark, this.domainClass);
- val proxy = wrapperFactory.wrap(lookup, executionModesAsync);
- return action.call(proxy, arg1, arg2, arg3, arg4);
- });
- }
-
- return CompletableFuture.completedFuture(null);
- }
-
-
- // -- SUBMISSION
-
- private <R> Future<R> submit(Supplier<R> actionInvocation) {
-
- val authenticationSession = authenticationSessionTracker.getAuthenticationSessionElseFail();
-
- Callable<R> asyncTask = ()->{
-
- try {
- return isisSessionFactory.callAuthenticated(authenticationSession,
- ()->transactionService.executeWithinTransaction(actionInvocation));
-
- } catch (Exception e) {
-
-// val wrappedMethod = (Method)
-// proxy.getClass().getMethod("__isis_wrappedMethod", _Constants.emptyClasses);
-
- Object lookup = bookmarkService.lookup(bookmark);
- val msg =
- String.format("Async execution of action '%s' on domain object '%s' failed.",
- "[cannot resolve method name - not implemented]",//wrappedMethod.getName(),
- bookmark);
-
- log.warn(msg, e);
-
- exceptionHandler.accept(_Exceptions.unrecoverable(msg, e));
-
- return null;
- }
- };
-
- return executorService.submit(asyncTask);
- }
-
- // -- HELPER
-
- private boolean shouldValidateSync() {
- return !this.executionModesSync.contains(ExecutionMode.SKIP_RULE_VALIDATION);
- }
-
- private boolean shouldValidateAsync() {
- return !this.executionModesAsync.contains(ExecutionMode.SKIP_RULE_VALIDATION);
- }
-
- private boolean shouldExecuteAsync() {
- return !executionModesAsync.contains(ExecutionMode.SKIP_EXECUTION);
- }
-
-}
diff --git a/core/runtimeservices/src/main/java/org/apache/isis/core/runtimeservices/wrapper/WrapperFactoryDefault.java b/core/runtimeservices/src/main/java/org/apache/isis/core/runtimeservices/wrapper/WrapperFactoryDefault.java
index c3cf248..7267b25 100644
--- a/core/runtimeservices/src/main/java/org/apache/isis/core/runtimeservices/wrapper/WrapperFactoryDefault.java
+++ b/core/runtimeservices/src/main/java/org/apache/isis/core/runtimeservices/wrapper/WrapperFactoryDefault.java
@@ -18,17 +18,23 @@
*/
package org.apache.isis.core.runtimeservices.wrapper;
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.Method;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import java.util.concurrent.ForkJoinPool;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Future;
import java.util.function.BiConsumer;
import javax.annotation.PostConstruct;
import javax.inject.Inject;
import javax.inject.Named;
+import javax.inject.Provider;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Primary;
@@ -37,8 +43,10 @@ import org.springframework.stereotype.Service;
import org.apache.isis.applib.annotation.OrderPrecedence;
import org.apache.isis.applib.services.bookmark.BookmarkService;
+import org.apache.isis.applib.services.command.Command;
+import org.apache.isis.applib.services.command.CommandContext;
+import org.apache.isis.applib.services.command.CommandExecutorService;
import org.apache.isis.applib.services.factory.FactoryService;
-import org.apache.isis.applib.services.wrapper.AsyncWrap;
import org.apache.isis.applib.services.wrapper.WrapperFactory;
import org.apache.isis.applib.services.wrapper.WrappingObject;
import org.apache.isis.applib.services.wrapper.events.ActionArgumentEvent;
@@ -63,14 +71,30 @@ import org.apache.isis.applib.services.xactn.TransactionService;
import org.apache.isis.core.commons.collections.ImmutableEnumSet;
import org.apache.isis.core.commons.internal.base._Casts;
import org.apache.isis.core.commons.internal.exceptions._Exceptions;
+import org.apache.isis.core.commons.internal.plugins.codegen.ProxyFactory;
import org.apache.isis.core.commons.internal.plugins.codegen.ProxyFactoryService;
+import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
import org.apache.isis.core.metamodel.context.MetaModelContext;
+import org.apache.isis.core.metamodel.facets.actions.action.invocation.CommandUtil;
+import org.apache.isis.core.metamodel.objectmanager.ObjectManager;
+import org.apache.isis.core.metamodel.services.command.CommandDtoServiceInternal;
+import org.apache.isis.core.metamodel.spec.ManagedObject;
+import org.apache.isis.core.metamodel.spec.ObjectSpecification;
+import org.apache.isis.core.metamodel.spec.feature.ObjectAction;
+import org.apache.isis.core.metamodel.spec.feature.ObjectMember;
+import org.apache.isis.core.metamodel.specloader.SpecificationLoader;
+import org.apache.isis.core.metamodel.specloader.specimpl.dflt.ObjectSpecificationDefault;
+import org.apache.isis.core.runtime.session.IsisSession;
import org.apache.isis.core.runtime.session.IsisSessionFactory;
+import org.apache.isis.core.runtime.session.IsisSessionTracker;
+import org.apache.isis.core.runtime.session.init.InitialisationSession;
import org.apache.isis.core.runtimeservices.wrapper.dispatchers.InteractionEventDispatcher;
import org.apache.isis.core.runtimeservices.wrapper.dispatchers.InteractionEventDispatcherTypeSafe;
import org.apache.isis.core.runtimeservices.wrapper.handlers.ProxyContextHandler;
import org.apache.isis.core.runtimeservices.wrapper.proxy.ProxyCreator;
+import org.apache.isis.core.security.authentication.AuthenticationSession;
import org.apache.isis.core.security.authentication.AuthenticationSessionTracker;
+import org.apache.isis.schema.cmd.v2.CommandDto;
import lombok.val;
import lombok.extern.log4j.Log4j2;
@@ -91,10 +115,14 @@ public class WrapperFactoryDefault implements WrapperFactory {
@Inject private FactoryService factoryService;
@Inject private BookmarkService bookmarkService;
@Inject private MetaModelContext metaModelContext;
+ @Inject private SpecificationLoader specificationLoader;
+ @Inject private IsisSessionTracker isisSessionTracker;
@Inject private IsisSessionFactory isisSessionFactory;
+ @Inject private CommandExecutorService commandExecutorService;
+ @Inject private Provider<CommandContext> commandContextProvider;
@Inject private TransactionService transactionService;
@Inject protected ProxyFactoryService proxyFactoryService; // protected to allow JUnit test
- @Inject private AuthenticationSessionTracker authenticationSessionTracker;
+ @Inject private CommandDtoServiceInternal commandDtoServiceInternal;
private final List<InteractionListener> listeners = new ArrayList<InteractionListener>();
private final Map<Class<? extends InteractionEvent>, InteractionEventDispatcher>
@@ -108,22 +136,22 @@ public class WrapperFactoryDefault implements WrapperFactory {
val proxyCreator = new ProxyCreator(proxyFactoryService);
proxyContextHandler = new ProxyContextHandler(proxyCreator);
- putDispatcher(ObjectTitleEvent.class, (listener, event)->listener.objectTitleRead(event));
- putDispatcher(PropertyVisibilityEvent.class, (listener, event)->listener.propertyVisible(event));
- putDispatcher(PropertyUsabilityEvent.class, (listener, event)->listener.propertyUsable(event));
- putDispatcher(PropertyAccessEvent.class, (listener, event)->listener.propertyAccessed(event));
- putDispatcher(PropertyModifyEvent.class, (listener, event)->listener.propertyModified(event));
- putDispatcher(CollectionVisibilityEvent.class, (listener, event)->listener.collectionVisible(event));
- putDispatcher(CollectionUsabilityEvent.class, (listener, event)->listener.collectionUsable(event));
- putDispatcher(CollectionAccessEvent.class, (listener, event)->listener.collectionAccessed(event));
- putDispatcher(CollectionAddToEvent.class, (listener, event)->listener.collectionAddedTo(event));
- putDispatcher(CollectionRemoveFromEvent.class, (listener, event)->listener.collectionRemovedFrom(event));
- putDispatcher(ActionVisibilityEvent.class, (listener, event)->listener.actionVisible(event));
- putDispatcher(ActionUsabilityEvent.class, (listener, event)->listener.actionUsable(event));
- putDispatcher(ActionArgumentEvent.class, (listener, event)->listener.actionArgument(event));
- putDispatcher(ActionInvocationEvent.class, (listener, event)->listener.actionInvoked(event));
- putDispatcher(ObjectValidityEvent.class, (listener, event)->listener.objectPersisted(event));
- putDispatcher(CollectionMethodEvent.class, (listener, event)->listener.collectionMethodInvoked(event));
+ putDispatcher(ObjectTitleEvent.class, InteractionListener::objectTitleRead);
+ putDispatcher(PropertyVisibilityEvent.class, InteractionListener::propertyVisible);
+ putDispatcher(PropertyUsabilityEvent.class, InteractionListener::propertyUsable);
+ putDispatcher(PropertyAccessEvent.class, InteractionListener::propertyAccessed);
+ putDispatcher(PropertyModifyEvent.class, InteractionListener::propertyModified);
+ putDispatcher(CollectionVisibilityEvent.class, InteractionListener::collectionVisible);
+ putDispatcher(CollectionUsabilityEvent.class, InteractionListener::collectionUsable);
+ putDispatcher(CollectionAccessEvent.class, InteractionListener::collectionAccessed);
+ putDispatcher(CollectionAddToEvent.class, InteractionListener::collectionAddedTo);
+ putDispatcher(CollectionRemoveFromEvent.class, InteractionListener::collectionRemovedFrom);
+ putDispatcher(ActionVisibilityEvent.class, InteractionListener::actionVisible);
+ putDispatcher(ActionUsabilityEvent.class, InteractionListener::actionUsable);
+ putDispatcher(ActionArgumentEvent.class, InteractionListener::actionArgument);
+ putDispatcher(ActionInvocationEvent.class, InteractionListener::actionInvoked);
+ putDispatcher(ObjectValidityEvent.class, InteractionListener::objectPersisted);
+ putDispatcher(CollectionMethodEvent.class, InteractionListener::collectionMethodInvoked);
}
// -- WRAPPING
@@ -154,21 +182,23 @@ public class WrapperFactoryDefault implements WrapperFactory {
}
@Override
- public <T> T wrap(T domainObject, ImmutableEnumSet<ExecutionMode> mode) {
+ public <T> T wrap(
+ final T domainObject,
+ final ImmutableEnumSet<ExecutionMode> modes) {
if (domainObject instanceof WrappingObject) {
val wrapperObject = (WrappingObject) domainObject;
val executionMode = wrapperObject.__isis_executionMode();
- if(executionMode != mode) {
+ if(executionMode != modes) {
val underlyingDomainObject = wrapperObject.__isis_wrapped();
- return _Casts.uncheckedCast(createProxy(underlyingDomainObject, mode));
+ return _Casts.uncheckedCast(createProxy(underlyingDomainObject, modes));
}
return domainObject;
}
- return createProxy(domainObject, mode);
+ return createProxy(domainObject, modes);
}
- protected <T> T createProxy(T domainObject, ImmutableEnumSet<ExecutionMode> mode) {
- return proxyContextHandler.proxy(metaModelContext, domainObject, mode);
+ protected <T> T createProxy(T domainObject, ImmutableEnumSet<ExecutionMode> modes) {
+ return proxyContextHandler.proxy(metaModelContext, domainObject, modes);
}
@Override
@@ -185,25 +215,151 @@ public class WrapperFactoryDefault implements WrapperFactory {
return possibleWrappedDomainObject;
}
+
// -- ASYNC WRAPPING
-
@Override
- public <T> T async(T domainObject, ImmutableEnumSet<ExecutionMode> modes) {
- val executor = ForkJoinPool.commonPool(); // default, but can be overwritten through withers on the returned AsyncWrap
- AsyncWrapDefault<T> tAsyncWrapDefault = new AsyncWrapDefault<>(
- this, isisSessionFactory,
- authenticationSessionTracker, transactionService, bookmarkService,
- domainObject, modes, executor, log::error, RuleCheckingPolicy.ASYNC);
- return proxyFactoryService.factory()tAsyncWrapDefault;
+ public <T> T async(
+ final T domainObject,
+ final ImmutableEnumSet<ExecutionMode> executionModes,
+ final RuleCheckingPolicy ruleCheckingPolicy,
+ final ExecutorService executorService) {
+
+ Class<T> domainClass = (Class<T>) domainObject.getClass();
+ ProxyFactory<T> factory = proxyFactoryService.factory(domainClass, WrappingObject.class);
+
+ return factory.createInstance((Object proxy, Method method, Object[] args) -> {
+
+ val executionModesAsync = determineExecutionModesAsync(executionModes, ruleCheckingPolicy);
+ if (!shouldValidateAsync(executionModesAsync) && !shouldExecuteAsync(executionModesAsync)) {
+ // nothing to be done.
+ return null;
+ }
+
+ //
+ // executed in the same thread as caller..
+ //
+ final boolean inheritedFromObject = method.getDeclaringClass().equals(Object.class);
+ if(inheritedFromObject) {
+ return method.invoke(domainObject, args);
+ }
+
+ val executionModesSync = determineExecutionModesSync(executionModes, ruleCheckingPolicy);
+ if(shouldValidateSync(executionModesSync)) {
+ // normal wrapped object...
+ T syncProxy = createProxy(domainObject, executionModesSync);
+ method.invoke(syncProxy, args);
+ }
+
+ //
+ // submit async stuff
+ //
+ final ObjectSpecificationDefault targetObjSpec = (ObjectSpecificationDefault) specificationLoader.loadSpecification(method.getDeclaringClass());
+ final ObjectMember member = targetObjSpec.getMember(method);
+
+ if(member == null) {
+ return method.invoke(domainObject, args);
+ }
+
+ if(!(member instanceof ObjectAction)) {
+ throw new UnsupportedOperationException(
+ "Only actions can be executed in the background "
+ + "(method " + method.getName() + " represents a " + member.getFeatureType().name() + "')");
+ }
+
+ ObjectAction action = (ObjectAction) member;
+
+ val isisSession = isisSessionTracker.currentSession().orElseThrow(() -> new RuntimeException("No IsisSession is open"));
+ val authSession = isisSession.getAuthenticationSession();
+
+ final ManagedObject domainObjectAdapter = isisSession.getObjectManager().adapt(domainObject);
+ final String domainObjectClassName = CommandUtil.targetClassNameFor(domainObjectAdapter);
+
+ final String targetActionName = CommandUtil.targetMemberNameFor(action);
+
+ final List<ManagedObject> argAdapters = Arrays.asList(adaptersFor(args));
+ final String targetArgs = CommandUtil.argDescriptionFor(action, argAdapters);
+
+ final Command command = commandContextProvider.get().getCommand();
+
+ final List<ManagedObject> targetList = Collections.singletonList(domainObjectAdapter);
+ final CommandDto dto =
+ commandDtoServiceInternal.asCommandDto(targetList, action, argAdapters);
+
+ executorService.submit(() -> {
+
+ isisSessionFactory.runAuthenticated(authSession, () -> {
+
+ if (shouldValidateAsync(executionModesAsync)) {
+ // TODO...
+ }
+ if (shouldExecuteAsync(executionModesAsync)) {
+ commandExecutorService.executeCommand(dto);
+ }
+
+ });
+ });
+ return null;
+
+
+ }, false);
}
-
+
@Override
- public <T> AsyncWrap<T> asyncMixin(Class<T> mixinClass, Object mixedIn, ImmutableEnumSet<ExecutionMode> mode) {
- val mixin = factoryService.<T>mixin(mixinClass, mixedIn);
- return async(mixin, mode);
+ public <T> T asyncMixin(
+ Class<T> mixinClass, Object mixedIn,
+ ImmutableEnumSet<ExecutionMode> modes,
+ RuleCheckingPolicy ruleCheckingPolicy,
+ ExecutorService executorService) {
+
+ throw new RuntimeException("TODO");
+ }
+
+ private ManagedObject[] adaptersFor(final Object[] args) {
+ final ObjectManager objectManager =
+ isisSessionTracker.currentSession().get().getObjectManager();
+ return CommandUtil.adaptersFor(args, objectManager);
}
+ private static ImmutableEnumSet<ExecutionMode> determineExecutionModesSync(
+ ImmutableEnumSet<ExecutionMode> executionModes,
+ RuleCheckingPolicy ruleCheckingPolicy) {
+ return executionModes.contains(ExecutionMode.SKIP_RULE_VALIDATION) ||
+ ruleCheckingPolicy != RuleCheckingPolicy.SYNC
+ ? ExecutionModes.NOOP
+ : ExecutionModes.NO_EXECUTE;
+ }
+
+ private static ImmutableEnumSet<ExecutionMode> determineExecutionModesAsync(
+ ImmutableEnumSet<ExecutionMode> executionModes,
+ RuleCheckingPolicy ruleCheckingPolicy) {
+ return executionModes.contains(ExecutionMode.SKIP_RULE_VALIDATION) ||
+ RuleCheckingPolicy.SYNC == ruleCheckingPolicy
+ ? join(executionModes, ExecutionMode.SKIP_RULE_VALIDATION)
+ : executionModes;
+ }
+
+ private static ImmutableEnumSet<ExecutionMode> join(
+ ImmutableEnumSet<ExecutionMode> executionModes,
+ ExecutionMode skipRuleValidation) {
+ val tmp = executionModes.toEnumSet();
+ tmp.add(skipRuleValidation);
+ return ImmutableEnumSet.from(tmp);
+ }
+
+ private boolean shouldValidateSync(ImmutableEnumSet<ExecutionMode> executionModesSync) {
+ return !executionModesSync.contains(ExecutionMode.SKIP_RULE_VALIDATION);
+ }
+
+ private boolean shouldValidateAsync(ImmutableEnumSet<ExecutionMode> executionModesAsync) {
+ return !executionModesAsync.contains(ExecutionMode.SKIP_RULE_VALIDATION);
+ }
+
+ private boolean shouldExecuteAsync(ImmutableEnumSet<ExecutionMode> executionModesAsync) {
+ return !executionModesAsync.contains(ExecutionMode.SKIP_EXECUTION);
+ }
+
+
// -- LISTENERS
@Override
@@ -250,4 +406,5 @@ public class WrapperFactoryDefault implements WrapperFactory {
}
+
}
diff --git a/core/runtimeservices/src/main/java/org/apache/isis/core/runtimeservices/wrapper/proxy/ProxyCreator.java b/core/runtimeservices/src/main/java/org/apache/isis/core/runtimeservices/wrapper/proxy/ProxyCreator.java
index dea3aeb..28f18eb 100644
--- a/core/runtimeservices/src/main/java/org/apache/isis/core/runtimeservices/wrapper/proxy/ProxyCreator.java
+++ b/core/runtimeservices/src/main/java/org/apache/isis/core/runtimeservices/wrapper/proxy/ProxyCreator.java
@@ -19,7 +19,6 @@
package org.apache.isis.core.runtimeservices.wrapper.proxy;
-import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Proxy;
import org.apache.isis.applib.services.wrapper.WrappingObject;
@@ -44,20 +43,11 @@ public class ProxyCreator {
final Class<T> base = _Casts.uncheckedCast(toProxy.getClass());
if (base.isInterface()) {
- return createInstanceForInterface(base, handler, WrappingObject.class);
+ return (T) Proxy.newProxyInstance(base.getClassLoader(), _Arrays.combine(base, (Class<?>[]) new Class[]{WrappingObject.class}) , handler);
} else {
final ProxyFactory<T> proxyFactory = proxyFactoryService.factory(base, WrappingObject.class);
return proxyFactory.createInstance(handler, false);
}
}
- // -- HELPER
-
-
- @SuppressWarnings("unchecked")
- private static <T> T createInstanceForInterface(
- final Class<T> base, final InvocationHandler handler, final Class<?>... auxiliaryTypes) {
- return (T) Proxy.newProxyInstance(base.getClassLoader(), _Arrays.combine(base, auxiliaryTypes) , handler);
- }
-
}
diff --git a/core/runtimeservices/src/test/java/org/apache/isis/core/runtimeservices/wrapper/WrapperFactoryDefaultTest.java b/core/runtimeservices/src/test/java/org/apache/isis/core/runtimeservices/wrapper/WrapperFactoryDefaultTest.java
index 6b54786..9434440 100644
--- a/core/runtimeservices/src/test/java/org/apache/isis/core/runtimeservices/wrapper/WrapperFactoryDefaultTest.java
+++ b/core/runtimeservices/src/test/java/org/apache/isis/core/runtimeservices/wrapper/WrapperFactoryDefaultTest.java
@@ -82,8 +82,8 @@ public class WrapperFactoryDefaultTest {
}
@Override
- protected <T> T createProxy(T domainObject, ImmutableEnumSet<WrapperFactory.ExecutionMode> mode) {
- WrapperFactoryDefaultTest.this.createProxyCalledWithMode = mode;
+ protected <T> T createProxy(T domainObject, ImmutableEnumSet<WrapperFactory.ExecutionMode> modes) {
+ WrapperFactoryDefaultTest.this.createProxyCalledWithMode = modes;
WrapperFactoryDefaultTest.this.createProxyCalledWithDomainObject = (DomainObject) domainObject;
return domainObject;
}
diff --git a/examples/demo/src/main/java/demoapp/dom/events/DemoEventSubscriber.java b/examples/demo/src/main/java/demoapp/dom/events/DemoEventSubscriber.java
index 18e43a0..2856a5f 100644
--- a/examples/demo/src/main/java/demoapp/dom/events/DemoEventSubscriber.java
+++ b/examples/demo/src/main/java/demoapp/dom/events/DemoEventSubscriber.java
@@ -54,13 +54,12 @@ public class DemoEventSubscriber {
val eventLogWriter = factoryService.get(EventLogWriter.class); // <-- get a new writer
- wrapper.async(eventLogWriter)
- .run(EventLogWriter::storeEvent, event);
+ wrapper.async(eventLogWriter).storeEvent(event);
}
@DomainObject(
- nature = Nature.BEAN, // <-- have this Object's lifecycle managed by Spring (EXPERIMENTAL)
+ nature = Nature.BEAN, // <-- have this Object's lifecycle managed by Spring
objectType = "demoapp.eventLogWriter")
public static class EventLogWriter {
diff --git a/examples/smoketests/src/test/java/org/apache/isis/testdomain/auditing/AuditerServiceTest.java b/examples/smoketests/src/test/java/org/apache/isis/testdomain/auditing/AuditerServiceTest.java
index ab4d7c1..5f1e204 100644
--- a/examples/smoketests/src/test/java/org/apache/isis/testdomain/auditing/AuditerServiceTest.java
+++ b/examples/smoketests/src/test/java/org/apache/isis/testdomain/auditing/AuditerServiceTest.java
@@ -131,11 +131,8 @@ class AuditerServiceTest extends IsisIntegrationTestAbstract {
kvStore.clear(AuditerServiceForTesting.class);
// when - running within its own background task
- val future = wrapper.async(book, WrapperFactory.ExecutionModes.SKIP_RULES) // don't enforce rules for this test
- .run(JdoBook::setName, "Book #2");
+ wrapper.async(book, WrapperFactory.ExecutionModes.SKIP_RULES).setName("Book #2"); // don't enforce rules for this test
- future.get(1000, TimeUnit.SECONDS);
-
// then - after the commit
assertEquals("targetClassName=Jdo Book,propertyName=name,preValue=Sample Book,postValue=Book #2;",
kvStore.get(AuditerServiceForTesting.class, "audit").orElse(null));
@@ -154,10 +151,9 @@ class AuditerServiceTest extends IsisIntegrationTestAbstract {
// when - running within its own background task
assertThrows(DisabledException.class, ()->{
- val future = wrapper.async(book, WrapperFactory.ExecutionModes.EXECUTE)
- .run(JdoBook::setName, "Book #2");
+ wrapper.async(book, WrapperFactory.ExecutionModes.EXECUTE).setName("Book #2");
- future.get(1000, TimeUnit.SECONDS);
+ //future.get(1000, TimeUnit.SECONDS);
});
diff --git a/examples/smoketests/src/test/java/org/apache/isis/testdomain/commandexecution/WrapperAsyncTest.java b/examples/smoketests/src/test/java/org/apache/isis/testdomain/commandexecution/WrapperAsyncTest.java
index a0bcf6e..12c416c 100644
--- a/examples/smoketests/src/test/java/org/apache/isis/testdomain/commandexecution/WrapperAsyncTest.java
+++ b/examples/smoketests/src/test/java/org/apache/isis/testdomain/commandexecution/WrapperAsyncTest.java
@@ -119,15 +119,15 @@ class WrapperAsyncTest {
actionDomainEventListener.prepareLatch();
- Future<JdoProduct> invocationResult = wrapper.async(inventoryManager)
- .withExecutor(Executors.newCachedThreadPool()) // use of custom executor (optional)
- .call(JdoInventoryManager::updateProductPrice, product, 123d);
+ // use of custom executor (optional)
+ wrapper.async(inventoryManager, WrapperFactory.ExecutionModes.EXECUTE, WrapperFactory.RuleCheckingPolicy.ASYNC, Executors.newCachedThreadPool())
+ .updateProductPrice(product, 123d);
//XXX type-safety should prevent this snippet from being compiled!
// Future<String> invocationResult2 = wrapper.async(inventoryManager)
// .invoke(Product::toString);
- assertNotNull(invocationResult);
+ // assertNotNull(invocationResult);
assertTrue(
@@ -136,9 +136,9 @@ class WrapperAsyncTest {
assertEquals(123d, product.getPrice(), 1E-6);
- val product_asReturnedByTheAsyncTask = invocationResult.get();
- assertNotNull(product_asReturnedByTheAsyncTask);
- assertEquals(123d, product_asReturnedByTheAsyncTask.getPrice(), 1E-6);
+// val product_asReturnedByTheAsyncTask = invocationResult.get();
+// assertNotNull(product_asReturnedByTheAsyncTask);
+// assertEquals(123d, product_asReturnedByTheAsyncTask.getPrice(), 1E-6);
}
diff --git a/examples/smoketests/src/test/java/org/apache/isis/testdomain/publishing/PublisherServiceTest.java b/examples/smoketests/src/test/java/org/apache/isis/testdomain/publishing/PublisherServiceTest.java
index 24b13ef..6210a85 100644
--- a/examples/smoketests/src/test/java/org/apache/isis/testdomain/publishing/PublisherServiceTest.java
+++ b/examples/smoketests/src/test/java/org/apache/isis/testdomain/publishing/PublisherServiceTest.java
@@ -143,10 +143,9 @@ class PublisherServiceTest extends IsisIntegrationTestAbstract {
val latch = kvStore.latch(PublisherServiceForTesting.class);
// when - running within its own background task
- val future = wrapper.async(book, WrapperFactory.ExecutionModes.SKIP_RULES) // don't enforce rules for this test
- .run(JdoBook::setName, "Book #2");
+ wrapper.async(book, WrapperFactory.ExecutionModes.SKIP_RULES).setName("Book #2"); // don't enforce rules for this test
- future.get(10, TimeUnit.SECONDS);
+ //future.get(10, TimeUnit.SECONDS);
latch.await(2, TimeUnit.SECONDS);
@@ -173,10 +172,9 @@ class PublisherServiceTest extends IsisIntegrationTestAbstract {
// when - running within its own background task
assertThrows(DisabledException.class, ()->{
- val future = wrapper.async(book, WrapperFactory.ExecutionModes.EXECUTE)
- .run(JdoBook::setName, "Book #2");
+ wrapper.async(book, WrapperFactory.ExecutionModes.EXECUTE).setName("Book #2");
- future.get(10, TimeUnit.SECONDS);
+ //future.get(10, TimeUnit.SECONDS);
});