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 2018/06/27 08:08:02 UTC
[isis] 01/04: ISIS-1960: applib: remove BackgroundService2 and
BackgroundCommandService2
This is an automated email from the ASF dual-hosted git repository.
ahuber pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/isis.git
commit bbdad22b392cf910ae196ca7304edc86b117b7f6
Author: Andi Huber <ah...@apache.org>
AuthorDate: Wed Jun 27 07:41:53 2018 +0200
ISIS-1960: applib: remove BackgroundService2 and
BackgroundCommandService2
Task-Url: https://issues.apache.org/jira/browse/ISIS-1960
---
.../background/BackgroundCommandService.java | 10 ++++
.../services/background/BackgroundService.java | 6 ++
.../background/BackgroundCommandService2.java | 13 +----
.../services/background/BackgroundService2.java | 13 ++---
.../background/BackgroundServiceDefault.java | 67 +++++++++++++---------
.../background/CommandInvocationHandler.java | 6 +-
6 files changed, 65 insertions(+), 50 deletions(-)
diff --git a/core/applib/src/main/java/org/apache/isis/applib/services/background/BackgroundCommandService.java b/core/applib/src/main/java/org/apache/isis/applib/services/background/BackgroundCommandService.java
index 11621d8..c086d2b 100644
--- a/core/applib/src/main/java/org/apache/isis/applib/services/background/BackgroundCommandService.java
+++ b/core/applib/src/main/java/org/apache/isis/applib/services/background/BackgroundCommandService.java
@@ -16,6 +16,9 @@
*/
package org.apache.isis.applib.services.background;
+import org.apache.isis.applib.services.command.Command;
+import org.apache.isis.schema.cmd.v1.CommandDto;
+
/**
* Persists a {@link org.apache.isis.schema.cmd.v1.CommandDto command-reified} action such that it can be executed asynchronously,
* for example through a Quartz scheduler.
@@ -34,5 +37,12 @@ package org.apache.isis.applib.services.background;
*
*/
public interface BackgroundCommandService {
+
+ public void schedule(
+ final CommandDto dto,
+ final Command parentCommand,
+ final String targetClassName,
+ final String targetActionName,
+ final String targetArgs);
}
diff --git a/core/applib/src/main/java/org/apache/isis/applib/services/background/BackgroundService.java b/core/applib/src/main/java/org/apache/isis/applib/services/background/BackgroundService.java
index 158a86a..f22af39 100644
--- a/core/applib/src/main/java/org/apache/isis/applib/services/background/BackgroundService.java
+++ b/core/applib/src/main/java/org/apache/isis/applib/services/background/BackgroundService.java
@@ -47,5 +47,11 @@ public interface BackgroundService {
@Programmatic
<T> T execute(final T object);
+ /**
+ * Returns a proxy around the mixin object which is then used to obtain the
+ * signature of the action to be invoked in the background.
+ */
+ @Programmatic
+ <T> T executeMixin(Class<T> mixinClass, Object mixedIn);
}
diff --git a/core/applib/src/main/java/org/apache/isis/applib/services/background/BackgroundCommandService2.java b/core/legacy/applib-legacy/src/main/java/org/apache/isis/applib/services/background/BackgroundCommandService2.java
similarity index 77%
rename from core/applib/src/main/java/org/apache/isis/applib/services/background/BackgroundCommandService2.java
rename to core/legacy/applib-legacy/src/main/java/org/apache/isis/applib/services/background/BackgroundCommandService2.java
index e693592..7c3ed13 100644
--- a/core/applib/src/main/java/org/apache/isis/applib/services/background/BackgroundCommandService2.java
+++ b/core/legacy/applib-legacy/src/main/java/org/apache/isis/applib/services/background/BackgroundCommandService2.java
@@ -16,20 +16,13 @@
*/
package org.apache.isis.applib.services.background;
-import org.apache.isis.applib.services.command.Command;
-import org.apache.isis.schema.cmd.v1.CommandDto;
-
/**
* Persists a {@link org.apache.isis.schema.cmd.v1.CommandDto memento-ized} command such that it can be
* executed asynchronously, for example through a Quartz scheduler.
- *
+ * @deprecated use BackgroundCommandService instead
*/
+@Deprecated
public interface BackgroundCommandService2 extends BackgroundCommandService {
- void schedule(
- final CommandDto dto,
- final Command parentCommand,
- final String targetClassName,
- final String targetActionName,
- final String targetArgs);
+
}
diff --git a/core/applib/src/main/java/org/apache/isis/applib/services/background/BackgroundService2.java b/core/legacy/applib-legacy/src/main/java/org/apache/isis/applib/services/background/BackgroundService2.java
similarity index 77%
rename from core/applib/src/main/java/org/apache/isis/applib/services/background/BackgroundService2.java
rename to core/legacy/applib-legacy/src/main/java/org/apache/isis/applib/services/background/BackgroundService2.java
index 529aa85..7f68327 100644
--- a/core/applib/src/main/java/org/apache/isis/applib/services/background/BackgroundService2.java
+++ b/core/legacy/applib-legacy/src/main/java/org/apache/isis/applib/services/background/BackgroundService2.java
@@ -16,18 +16,13 @@
*/
package org.apache.isis.applib.services.background;
-import org.apache.isis.applib.annotation.Programmatic;
-
/**
* Submit actions to be invoked in the background.
+ * @deprecated use BackgroundService instead
+ *
*/
+@Deprecated
public interface BackgroundService2 extends BackgroundService {
-
- /**
- * Returns a proxy around the mixin object which is then used to obtain the
- * signature of the action to be invoked in the background.
- */
- @Programmatic
- <T> T executeMixin(Class<T> mixinClass, Object mixedIn);
+
}
diff --git a/core/runtime/src/main/java/org/apache/isis/core/runtime/services/background/BackgroundServiceDefault.java b/core/runtime/src/main/java/org/apache/isis/core/runtime/services/background/BackgroundServiceDefault.java
index 75d20b3..b19d921 100644
--- a/core/runtime/src/main/java/org/apache/isis/core/runtime/services/background/BackgroundServiceDefault.java
+++ b/core/runtime/src/main/java/org/apache/isis/core/runtime/services/background/BackgroundServiceDefault.java
@@ -30,8 +30,7 @@ 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.services.background.BackgroundCommandService;
-import org.apache.isis.applib.services.background.BackgroundCommandService2;
-import org.apache.isis.applib.services.background.BackgroundService2;
+import org.apache.isis.applib.services.background.BackgroundService;
import org.apache.isis.applib.services.command.CommandContext;
import org.apache.isis.applib.services.factory.FactoryService;
import org.apache.isis.commons.internal._Constants;
@@ -55,43 +54,55 @@ import org.slf4j.LoggerFactory;
nature = NatureOfService.DOMAIN,
menuOrder = "" + Integer.MAX_VALUE
)
-public class BackgroundServiceDefault implements BackgroundService2 {
+public class BackgroundServiceDefault implements BackgroundService {
static final Logger LOG = LoggerFactory.getLogger(BackgroundServiceDefault.class);
- /*
- * For the fixed thread-pool let there be 1-4 concurrent threads,
- * limited by the number of available (logical) processor cores.
- *
- * Note: Future improvements might make these values configurable,
- * but for now lets try to be reasonably nice here.
- *
- */
- private final int minThreadCount = 1; // only used if there is no BackgroundCommandService
- private final int maxThreadCount = 4; // only used if there is no BackgroundCommandService
-
- private final int threadCount = // only used if there is no BackgroundCommandService
- Math.max(minThreadCount,
- Math.min(maxThreadCount,
- Runtime.getRuntime().availableProcessors()));
-
// only used if there is no BackgroundCommandService
- private ExecutorService backgroundExecutorService;
+ private static class BuiltinExecutor {
+ /*
+ * For the fixed thread-pool let there be 1-4 concurrent threads,
+ * limited by the number of available (logical) processor cores.
+ *
+ * Note: Future improvements might make these values configurable,
+ * but for now lets try to be reasonably nice here.
+ *
+ */
+ private final int minThreadCount = 1;
+ private final int maxThreadCount = 4;
+
+ private final int threadCount =
+ Math.max(minThreadCount,
+ Math.min(maxThreadCount,
+ Runtime.getRuntime().availableProcessors()));
+
+ public final ExecutorService backgroundExecutorService =
+ Executors.newFixedThreadPool(threadCount);
+
+ public void shutdown() {
+ backgroundExecutorService.shutdownNow();
+ }
+ }
+
+ private BuiltinExecutor builtinExecutor; // only used if there is no BackgroundCommandService
+
+ private boolean usesBuiltinExecutor() {
+ return backgroundCommandService==null;
+ }
@Programmatic
@PostConstruct
public void init(Map<String,String> props) {
- if(backgroundCommandService==null) {
- backgroundExecutorService = Executors.newFixedThreadPool(threadCount);
+ if(usesBuiltinExecutor()) {
+ builtinExecutor = new BuiltinExecutor();
}
}
@Programmatic
@PreDestroy
public void shutdown() {
- if(backgroundExecutorService!=null) {
- backgroundExecutorService.shutdownNow();
- backgroundExecutorService = null;
+ if(builtinExecutor!=null) {
+ builtinExecutor.shutdown();
}
}
@@ -149,12 +160,12 @@ public class BackgroundServiceDefault implements BackgroundService2 {
*/
private <T> InvocationHandler newMethodHandler(final T target, final Object mixedInIfAny) {
- if(backgroundCommandService==null) {
- return new ForkingInvocationHandler<T>(target, mixedInIfAny, backgroundExecutorService);
+ if(usesBuiltinExecutor()) {
+ return new ForkingInvocationHandler<T>(target, mixedInIfAny, builtinExecutor.backgroundExecutorService);
}
return new CommandInvocationHandler<T>(
- (BackgroundCommandService2) backgroundCommandService,
+ backgroundCommandService,
target,
mixedInIfAny,
specificationLoader,
diff --git a/core/runtime/src/main/java/org/apache/isis/core/runtime/services/background/CommandInvocationHandler.java b/core/runtime/src/main/java/org/apache/isis/core/runtime/services/background/CommandInvocationHandler.java
index 0c1b090..437d591 100644
--- a/core/runtime/src/main/java/org/apache/isis/core/runtime/services/background/CommandInvocationHandler.java
+++ b/core/runtime/src/main/java/org/apache/isis/core/runtime/services/background/CommandInvocationHandler.java
@@ -24,7 +24,7 @@ import java.util.Collections;
import java.util.List;
import java.util.function.Supplier;
-import org.apache.isis.applib.services.background.BackgroundCommandService2;
+import org.apache.isis.applib.services.background.BackgroundCommandService;
import org.apache.isis.applib.services.command.Command;
import org.apache.isis.applib.services.command.CommandContext;
import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
@@ -42,7 +42,7 @@ import org.apache.isis.schema.cmd.v1.CommandDto;
class CommandInvocationHandler<T> implements InvocationHandler {
- private final BackgroundCommandService2 backgroundCommandService;
+ private final BackgroundCommandService backgroundCommandService;
private final T target;
private final Object mixedInIfAny;
private final SpecificationLoader specificationLoader;
@@ -51,7 +51,7 @@ class CommandInvocationHandler<T> implements InvocationHandler {
private final Supplier<AdapterManager> adapterManagerSupplier;
CommandInvocationHandler(
- BackgroundCommandService2 backgroundCommandService,
+ BackgroundCommandService backgroundCommandService,
T target,
Object mixedInIfAny,
SpecificationLoader specificationLoader,