Prevent duplicate loading of plugins in PluginLoader #948
Conversation
final Set<Plugin> sorted = ImmutableSortedSet.orderedBy(new PluginComparator()) | ||
.addAll(loadClassPathPlugins()) | ||
.addAll(loadJarPlugins()) | ||
.build(); |
kroepke
Feb 10, 2015
Member
Will this always add the classpath plugins before the jar plugins and always load the oldest plugin version?
I think it should be the other way around, allowing jar plugins to overlay classpath one's and later plugin versions to be preferred.
Will this always add the classpath plugins before the jar plugins and always load the oldest plugin version?
I think it should be the other way around, allowing jar plugins to overlay classpath one's and later plugin versions to be preferred.
joschi
Feb 10, 2015
Author
Contributor
The Plugin
interface doesn't require equals
and hashcode
and if plugin authors don't override those methods, the set could still contain duplicates (i. e. same plugin in different versions) as the default method implementations in Object
will be used.
The Plugin
interface doesn't require equals
and hashcode
and if plugin authors don't override those methods, the set could still contain duplicates (i. e. same plugin in different versions) as the default method implementations in Object
will be used.
joschi
Feb 10, 2015
Author
Contributor
As a matter of fact, the plugins in the classpath will also be contained in the collection returned by loadJarPlugins()
because the same classloader is used as parent classloader for the URLClassLoader
instances created in that method.
As a matter of fact, the plugins in the classpath will also be contained in the collection returned by loadJarPlugins()
because the same classloader is used as parent classloader for the URLClassLoader
instances created in that method.
kroepke
Feb 10, 2015
Member
fair enough, let's address this in a later iteration, then.
fair enough, let's address this in a later iteration, then.
plugins.addAll(loadJarPlugins()); | ||
final ImmutableSet.Builder<Plugin> unique = ImmutableSet.builder(); | ||
for (Plugin plugin : sorted) { | ||
unique.add(new PluginAdapter(plugin)); |
kroepke
Feb 10, 2015
Member
same as above?
why do we need a second set here?
same as above?
why do we need a second set here?
joschi
Feb 10, 2015
Author
Contributor
The PluginAdapter
class takes care of eliminating duplicate plugins (in different versions) by only taking the unique ID and the name of the plugins into account for equals()
and hashcode()
. The sorted
set can still contain duplicates (as described in #948 (comment)).
The PluginAdapter
class takes care of eliminating duplicate plugins (in different versions) by only taking the unique ID and the name of the plugins into account for equals()
and hashcode()
. The sorted
set can still contain duplicates (as described in #948 (comment)).
kroepke
Feb 10, 2015
Member
ah, missed that comment.
ah, missed that comment.
I think that a plugin's name is only used for display purposes, right? If that's true, then I think the name itself should not be used for comparisons, instead we should define what the unique id should look like. |
otherwise lgtm |
When plugins were available multiple times on the classpath or in the plugin directory of Graylog, the PluginLoader used to load identical plugins multiple times. By using a sorted set and a specialized Comparator<Plugin> in PluginLoader we prevent that behaviour. Fixes #946
Prevent duplicate loading of plugins in PluginLoader Fixes #946
When plugins were available multiple times on the class path or in the plugin directory of Graylog, the PluginLoader used to load identical plugins multiple times. By using a sorted set and a specialized Comparator in PluginLoader we prevent that behaviour.