Skip to content

Commit c413c14

Browse files
committed
Clarify that plugins can be closed
Plugins are closed if they implement java.io.Closeable but this is not clear from the plugin interface. This commit clarifies this by declaring that Plugins implement java.io.Closeable and adding an empty implementation to the base Plugin class. Relates #21669
1 parent 4ef9bd0 commit c413c14

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

core/src/main/java/org/elasticsearch/node/Node.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -741,7 +741,7 @@ public synchronized void close() throws IOException {
741741
toClose.add(() -> stopWatch.stop().start("plugin(" + plugin.getClass().getName() + ")"));
742742
toClose.add(plugin);
743743
}
744-
toClose.addAll(pluginsService.filterPlugins(Closeable.class));
744+
toClose.addAll(pluginsService.filterPlugins(Plugin.class));
745745

746746
toClose.add(() -> stopWatch.stop().start("script"));
747747
toClose.add(injector.getInstance(ScriptService.class));

core/src/main/java/org/elasticsearch/plugins/Plugin.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919

2020
package org.elasticsearch.plugins;
2121

22+
import java.io.Closeable;
23+
import java.io.IOException;
2224
import java.util.Collection;
2325
import java.util.Collections;
2426
import java.util.List;
@@ -70,7 +72,7 @@
7072
* methods should cause any extensions of {@linkplain Plugin} that used the pre-5.x style extension syntax to fail to build and point the
7173
* plugin author at the new extension syntax. We hope that these make the process of upgrading a plugin from 2.x to 5.x only mildly painful.
7274
*/
73-
public abstract class Plugin {
75+
public abstract class Plugin implements Closeable {
7476

7577
/**
7678
* Node level guice modules.
@@ -162,6 +164,16 @@ public List<ExecutorBuilder<?>> getExecutorBuilders(Settings settings) {
162164
return Collections.emptyList();
163165
}
164166

167+
/**
168+
* Close the resources opened by this plugin.
169+
*
170+
* @throws IOException if the plugin failed to close its resources
171+
*/
172+
@Override
173+
public void close() throws IOException {
174+
175+
}
176+
165177
/**
166178
* Old-style guice index level extension point. {@code @Deprecated} and {@code final} to act as a signpost for plugin authors upgrading
167179
* from 2.x.

0 commit comments

Comments
 (0)