From 84b8c9de194ef019d1efd239485343673bc3164d Mon Sep 17 00:00:00 2001 From: javanna Date: Thu, 1 Sep 2016 18:59:51 +0200 Subject: [PATCH] PluginInfo to implement Writeable rather than Streamable --- .../cluster/node/info/PluginsAndModules.java | 4 +- .../org/elasticsearch/plugins/PluginInfo.java | 52 ++++++++----------- 2 files changed, 23 insertions(+), 33 deletions(-) diff --git a/core/src/main/java/org/elasticsearch/action/admin/cluster/node/info/PluginsAndModules.java b/core/src/main/java/org/elasticsearch/action/admin/cluster/node/info/PluginsAndModules.java index 4c7fa7fa2ce..3a9658ea816 100644 --- a/core/src/main/java/org/elasticsearch/action/admin/cluster/node/info/PluginsAndModules.java +++ b/core/src/main/java/org/elasticsearch/action/admin/cluster/node/info/PluginsAndModules.java @@ -47,13 +47,13 @@ public class PluginsAndModules implements Writeable, ToXContent { int pluginsSize = in.readInt(); List plugins = new ArrayList<>(pluginsSize); for (int i = 0; i < pluginsSize; i++) { - plugins.add(PluginInfo.readFromStream(in)); + plugins.add(new PluginInfo(in)); } this.plugins = Collections.unmodifiableList(plugins); int modulesSize = in.readInt(); List modules = new ArrayList<>(modulesSize); for (int i = 0; i < modulesSize; i++) { - modules.add(PluginInfo.readFromStream(in)); + modules.add(new PluginInfo(in)); } this.modules = Collections.unmodifiableList(modules); } diff --git a/core/src/main/java/org/elasticsearch/plugins/PluginInfo.java b/core/src/main/java/org/elasticsearch/plugins/PluginInfo.java index 500861d8999..d2b5e0368c4 100644 --- a/core/src/main/java/org/elasticsearch/plugins/PluginInfo.java +++ b/core/src/main/java/org/elasticsearch/plugins/PluginInfo.java @@ -22,7 +22,7 @@ import org.elasticsearch.Version; import org.elasticsearch.bootstrap.JarHell; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; -import org.elasticsearch.common.io.stream.Streamable; +import org.elasticsearch.common.io.stream.Writeable; import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.XContentBuilder; @@ -32,7 +32,7 @@ import java.nio.file.Files; import java.nio.file.Path; import java.util.Properties; -public class PluginInfo implements Streamable, ToXContent { +public class PluginInfo implements Writeable, ToXContent { public static final String ES_PLUGIN_PROPERTIES = "plugin-descriptor.properties"; public static final String ES_PLUGIN_POLICY = "plugin-security.policy"; @@ -45,13 +45,10 @@ public class PluginInfo implements Streamable, ToXContent { static final String CLASSNAME = "classname"; } - private String name; - private String description; - private String version; - private String classname; - - public PluginInfo() { - } + private final String name; + private final String description; + private final String version; + private final String classname; /** * Information about plugins @@ -67,6 +64,21 @@ public class PluginInfo implements Streamable, ToXContent { this.classname = classname; } + public PluginInfo(StreamInput in) throws IOException { + this.name = in.readString(); + this.description = in.readString(); + this.version = in.readString(); + this.classname = in.readString(); + } + + @Override + public void writeTo(StreamOutput out) throws IOException { + out.writeString(name); + out.writeString(description); + out.writeString(version); + out.writeString(classname); + } + /** reads (and validates) plugin metadata descriptor file */ public static PluginInfo readFromProperties(Path dir) throws IOException { Path descriptor = dir.resolve(ES_PLUGIN_PROPERTIES); @@ -138,28 +150,6 @@ public class PluginInfo implements Streamable, ToXContent { return version; } - public static PluginInfo readFromStream(StreamInput in) throws IOException { - PluginInfo info = new PluginInfo(); - info.readFrom(in); - return info; - } - - @Override - public void readFrom(StreamInput in) throws IOException { - this.name = in.readString(); - this.description = in.readString(); - this.version = in.readString(); - this.classname = in.readString(); - } - - @Override - public void writeTo(StreamOutput out) throws IOException { - out.writeString(name); - out.writeString(description); - out.writeString(version); - out.writeString(classname); - } - @Override public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { builder.startObject();