In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly introduces "how to implement classes in elasticsearch plug-ins". In daily operation, I believe many people have doubts about how to implement classes in elasticsearch plug-ins. The editor consulted all kinds of materials and sorted out simple and easy-to-use methods of operation. I hope it will be helpful to answer the doubts about "how to implement classes in elasticsearch plug-ins". Next, please follow the editor to study!
The basic classes of elasticsearch are mainly divided into Component (components) and Module (modules).
module
CloseableComponent shutoff component
AbstractComponent Configurable component
The LifecycleComponent activity closes the component
AbstractLifecycleComponent configurable activities can close the component (. It's a little long)
Module
Module module
PreProcessModule preprocessing module
New SpawnModules module
one。 AbstractPlugin class, a plug-in class that inherits from it or implements the Plugin interface
The plug-in class needs to implement the Plugin interface, and the component type corresponding to each method is
Modules () Module
Services () LifecycleComponent
IndexModules () Module
IndexServices () CloseableIndexComponent
ShardModules () Module
ShardServices () CloseableIndexComponent
two。 Now that the plug-in implementation class has it, how does it get loaded into the whole system? Then we need to invite all the members of our plug-in group.
PluginManager class, plug-in management class, responsible for plug-in installation, uninstallation, download and other work.
The PluginsHelper class, the plug-in helper class, is responsible for listing all the site plug-ins under the environment.
The PluginsService class, the plug-in service class, is responsible for loading, instantiating and maintaining plug-in information.
When the entire node starts, after the configuration file is loaded in the InternalNode constructor, the PluginsService class and the PluginsModule module are first instantiated.
This.pluginsService = new PluginsService (tuple.v1 (), tuple.v2 ()); this.settings = pluginsService.updatedSettings (); this.environment = tuple.v2 (); CompressorFactory.configure (settings); NodeEnvironment nodeEnvironment = new NodeEnvironment (this.settings, this.environment); ModulesBuilder modules = new ModulesBuilder (); modules.add (new PluginsModule (settings, pluginsService)); modules.add (new SettingsModule (settings)); modules.add (new NodeModule (this))
In the constructor of the PluginsService class, the plug-in class starts to load from the configuration file and Classpath, and handles strongly dependent plug-ins for plugin.mandatory configuration, and module references
Public PluginsService (Settings settings, Environment environment) {super (settings); this.environment = environment; Map plugins = Maps.newHashMap (); / / first, we load from the configuration file, the default plug-in class String [] defaultPluginsClasses = settings.getAsArray ("plugin.types"); for (String pluginClass: defaultPluginsClasses) {Plugin plugin = loadPlugin (pluginClass, settings) Plugins.put (plugin.name (), plugin);} / now, we find all the plug-ins under ClassPath loadPluginsIntoClassLoader (); plugins.putAll (loadPluginsFromClasspath (settings)); / / load the JVM plug-in Set sitePlugins = PluginsHelper.sitePlugins (this.environment) / / load site plug-ins / / mandatory dependent plug-ins. If String [] mandatoryPlugins = settings.getAsArray ("plugin.mandatory", null) is not found; if (mandatoryPlugins! = null) {Set missingPlugins = Sets.newHashSet () For (String mandatoryPlugin: mandatoryPlugins) {if (! plugins.containsKey (mandatoryPlugin) & &! sitePlugins.contains (mandatoryPlugin) & &! missingPlugins.contains (mandatoryPlugin)) {missingPlugins.add (mandatoryPlugin) }} if (! missingPlugins.isEmpty ()) {/ / throws an exception and the entire node fails to start! Throw new ElasticSearchException ("Missing mandatory plugins [" + Strings.collectionToDelimitedString (missingPlugins, ",") + "]);} logger.info (" loaded {}, sites {} ", plugins.keySet (), sitePlugins); this.plugins = ImmutableMap.copyOf (plugins); / / now that all plug-ins are loaded to handle references to onModule methods of plug-in implementation classes, there is the secret of dependency injection. MapBuilder onModuleReferences = MapBuilder.newMapBuilder (); for (Plugin plugin: plugins.values ()) {List list = Lists.newArrayList (); / /.... } this.onModuleReferences = onModuleReferences.immutableMap (); this.refreshInterval = componentSettings.getAsTime ("info_refresh_interval", TimeValue.timeValueSeconds (10));}
The PluginsService.info () method, which is the plug-in information class, is called by NodeService and is part of the node information class, which is the content returned by the REST interface / nodes.
/ / fields of PluginInfo class static final class Fields {static final XContentBuilderString NAME = new XContentBuilderString ("name"); static final XContentBuilderString DESCRIPTION = new XContentBuilderString ("description"); static final XContentBuilderString URL = new XContentBuilderString ("url"); static final XContentBuilderString JVM = new XContentBuilderString ("jvm"); static final XContentBuilderString SITE = new XContentBuilderString ("site");}
InternalNode continues to call the modules.createInjector () method to instantiate all modules. The PluginsModule module will de-instantiate and call our plug-in
/ / create a module @ Override public Iterable in which the Plugin class overrides the modules method
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.