import java.util.List;
import java.util.Set;
-import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.CompletionStage;
/**
* A boot class that start the demo.
// load the plugins
// pluginManager.loadPlugins();
- CompletableFuture<Void> feature = pluginManager.loadPluginsAsync();
- feature.thenRun(() -> System.out.println("Plugins loaded"));
+ CompletionStage<Void> stage = pluginManager.loadPluginsAsync();
+ stage.thenRun(() -> System.out.println("Plugins loaded"));
// enable a disabled plugin
// pluginManager.enablePlugin("welcome-plugin");
// start (active/resolved) the plugins
// pluginManager.startPlugins();
- feature.thenCompose(v -> pluginManager.startPluginsAsync());
- feature.thenRun(() -> System.out.println("Plugins started"));
+ stage.thenCompose(v -> pluginManager.startPluginsAsync());
+ stage.thenRun(() -> System.out.println("Plugins started"));
// block and wait for the future to complete (not the best approach in real applications)
- feature.get();
+ stage.toCompletableFuture().get();
// retrieves the extensions for Greeting extension point
List<Greeting> greetings = pluginManager.getExtensions(Greeting.class);
*/
package org.pf4j;
-import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.CompletionStage;
/**
* A {@link PluginManager} that supports asynchronous operation with the methods ending in {@code Async}.
*/
public interface AsyncPluginManager extends PluginManager {
- CompletableFuture<Void> loadPluginsAsync();
+ CompletionStage<Void> loadPluginsAsync();
- CompletableFuture<Void> startPluginsAsync();
+ CompletionStage<Void> startPluginsAsync();
}
import java.util.List;
import java.util.Objects;
import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.CompletionStage;
/**
* An extension of {@link DefaultPluginManager} that supports asynchronous methods (@{AsyncPluginManager}).
private static final Logger log = LoggerFactory.getLogger(DefaultAsyncPluginManager.class);
@Override
- public CompletableFuture<Void> loadPluginsAsync() {
+ public CompletionStage<Void> loadPluginsAsync() {
Path pluginsRoot = getPluginsRoot();
PluginRepository pluginRepository = getPluginRepository();
}
@Override
- public CompletableFuture<Void> startPluginsAsync() {
+ public CompletionStage<Void> startPluginsAsync() {
/*
// chain start plugins one after another
CompletableFuture<Void> feature = CompletableFuture.completedFuture(null);
.toArray(CompletableFuture[]::new));
}
- protected CompletableFuture<PluginWrapper> loadPluginFromPathAsync(Path pluginPath) {
+ protected CompletionStage<PluginWrapper> loadPluginFromPathAsync(Path pluginPath) {
return CompletableFuture.supplyAsync(() -> {
try {
return loadPluginFromPath(pluginPath);
});
}
- protected CompletableFuture<Void> startPluginAsync(PluginWrapper pluginWrapper) {
+ protected CompletionStage<Void> startPluginAsync(PluginWrapper pluginWrapper) {
return CompletableFuture.runAsync(() -> {
PluginState pluginState = pluginWrapper.getPluginState();
if ((PluginState.DISABLED != pluginState) && (PluginState.STARTED != pluginState)) {