aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorradeklos <radeklos@users.noreply.github.com>2020-02-04 19:04:02 +0100
committerGitHub <noreply@github.com>2020-02-04 20:04:02 +0200
commited1f7fde6e3369dfdb4597ca22f0af839c54ce72 (patch)
tree2d7d8bf5a0b2447072a4c4e03650ee8f7a5d67a9
parente524ac2ca5c18e469c9855da2d2c36ef8a32d1a5 (diff)
downloadpf4j-ed1f7fde6e3369dfdb4597ca22f0af839c54ce72.tar.gz
pf4j-ed1f7fde6e3369dfdb4597ca22f0af839c54ce72.zip
Failed plugin state added. When plugin failed to start previous state was kept (#364)
-rw-r--r--pf4j/src/main/java/org/pf4j/AbstractPluginManager.java7
-rw-r--r--pf4j/src/main/java/org/pf4j/PluginState.java11
-rw-r--r--pf4j/src/main/java/org/pf4j/PluginWrapper.java14
3 files changed, 27 insertions, 5 deletions
diff --git a/pf4j/src/main/java/org/pf4j/AbstractPluginManager.java b/pf4j/src/main/java/org/pf4j/AbstractPluginManager.java
index e69acd3..d94b0c2 100644
--- a/pf4j/src/main/java/org/pf4j/AbstractPluginManager.java
+++ b/pf4j/src/main/java/org/pf4j/AbstractPluginManager.java
@@ -330,11 +330,14 @@ public abstract class AbstractPluginManager implements PluginManager {
log.info("Start plugin '{}'", getPluginLabel(pluginWrapper.getDescriptor()));
pluginWrapper.getPlugin().start();
pluginWrapper.setPluginState(PluginState.STARTED);
+ pluginWrapper.setFailedException(null);
startedPlugins.add(pluginWrapper);
-
- firePluginStateEvent(new PluginStateEvent(this, pluginWrapper, pluginState));
} catch (Exception e) {
+ pluginWrapper.setPluginState(PluginState.FAILED);
+ pluginWrapper.setFailedException(e);
log.error(e.getMessage(), e);
+ } finally {
+ firePluginStateEvent(new PluginStateEvent(this, pluginWrapper, pluginState));
}
}
}
diff --git a/pf4j/src/main/java/org/pf4j/PluginState.java b/pf4j/src/main/java/org/pf4j/PluginState.java
index 7b5037a..e28fc30 100644
--- a/pf4j/src/main/java/org/pf4j/PluginState.java
+++ b/pf4j/src/main/java/org/pf4j/PluginState.java
@@ -24,12 +24,12 @@ public enum PluginState {
* The runtime knows the plugin is there. It knows about the plugin path, the plugin descriptor.
*/
CREATED("CREATED"),
-
+
/**
* The plugin cannot be used.
*/
DISABLED("DISABLED"),
-
+
/**
* The plugin is created. All the dependencies are created and resolved.
* The plugin is ready to be started.
@@ -44,7 +44,12 @@ public enum PluginState {
/**
* The {@link Plugin#stop()} has executed.
*/
- STOPPED("STOPPED");
+ STOPPED("STOPPED"),
+
+ /**
+ * Plugin failed to start.
+ */
+ FAILED("FAILED");
private String status;
diff --git a/pf4j/src/main/java/org/pf4j/PluginWrapper.java b/pf4j/src/main/java/org/pf4j/PluginWrapper.java
index 0af0d93..8e472f8 100644
--- a/pf4j/src/main/java/org/pf4j/PluginWrapper.java
+++ b/pf4j/src/main/java/org/pf4j/PluginWrapper.java
@@ -32,6 +32,8 @@ public class PluginWrapper {
private PluginState pluginState;
private RuntimeMode runtimeMode;
+ private Exception failedException;
+
Plugin plugin; // cache
public PluginWrapper(PluginManager pluginManager, PluginDescriptor descriptor, Path pluginPath, ClassLoader pluginClassLoader) {
@@ -139,4 +141,16 @@ public class PluginWrapper {
this.pluginFactory = pluginFactory;
}
+ /**
+ * Returns the exception with which the plugin fails to start.
+ * See @{link PluginStatus#FAILED}.
+ */
+ public Exception getFailedException() {
+ return failedException;
+ }
+
+ public void setFailedException(Exception failedException) {
+ this.failedException = failedException;
+ }
+
}