# Replacing standard actions from a Java plugin

**URL:** <https://discuss.elastic.co/t/replacing-standard-actions-from-a-java-plugin/9278>\
**Category:** Elasticsearch\
**Created:** [October 8, 2012, 6:56pm UTC](https://discuss.elastic.co/t/replacing-standard-actions-from-a-java-plugin/9278 "2012-10-08T18:56:41Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![andreasch](https://avatars.discourse-cdn.com/v4/letter/a/90db22/32.png) [@andreasch](https://discuss.elastic.co/u/andreasch)\
**Post date:** [October 8, 2012, 6:56pm UTC](https://discuss.elastic.co/t/replacing-standard-actions-from-a-java-plugin/9278/1 "2012-10-08T18:56:41Z")

</div>

I created a plugin that tries to replace the standard index action with my  
own implementation. In my plugin, I have the following method:  
@Override  
public void processModule(Module module) {

```
            logger.info("Processing module");

```

if (module instanceof ActionModule) {  
ActionModule actionModule = (ActionModule) module;  
logger.info("Found action module");  
actionModule.registerAction(IndexAction.INSTANCE, CustomIndexAction.class);  
logger.info("Registered custom index action in  
place of standard index action");  
}  
}  
I can see all the log statements during startup. However, the custom action  
never gets executed. I debugged the custom plugin and action in an embedded  
ElasticSearch and I noticed that the processModule() of my custom plugin  
gets called first and then the configure() method of the ActionModule is  
called overriding my custom action.

Is this intentional or is this a defect?

Thanks,  
Andreas

--

---

<div class="post-metadata">

**Author:** ![Ivan](https://avatars.discourse-cdn.com/v4/letter/i/df788c/32.png) [@Ivan](https://discuss.elastic.co/u/Ivan)\
**Post date:** [October 8, 2012, 8:10pm UTC](https://discuss.elastic.co/t/replacing-standard-actions-from-a-java-plugin/9278/2 "2012-10-08T20:10:27Z")

</div>

I cannot say if it is intentional or not, but it definitely seems like your  
custom action is getting added to the action map first, and then  
getting overridden later.

I wonder if the flow would be different if you used the onModule method  
instead of processModule:

```
public void onModule(ActionModule actionModule ) {
    actionModule.registerAction(IndexAction.INSTANCE,

```

CustomIndexAction.class);  
}

Probably not, but worth a try.

--  
Ivan

On Mon, Oct 8, 2012 at 11:56 AM, Andreas Christoforides \<  
[andreas.christoforides@gmail.com](mailto:andreas.christoforides@gmail.com)\> wrote:

> I created a plugin that tries to replace the standard index action with my  
> own implementation. In my plugin, I have the following method:  
> @Override  
> public void processModule(Module module) {
> 
> ```
> logger.info("Processing module");
> 
> ```
> 
> if (module instanceof ActionModule) {  
> ActionModule actionModule = (ActionModule) module;  
> logger.info("Found action module");  
> actionModule.registerAction(IndexAction.INSTANCE, CustomIndexAction.class);  
> logger.info("Registered custom index action in  
> place of standard index action");  
> }  
> }  
> I can see all the log statements during startup. However, the custom  
> action never gets executed. I debugged the custom plugin and action in an  
> embedded Elasticsearch and I noticed that the processModule() of my custom  
> plugin gets called first and then the configure() method of the  
> ActionModule is called overriding my custom action.
> 
> Is this intentional or is this a defect?
> 
> Thanks,  
> Andreas
> 
> --

--

---

<div class="post-metadata">

**Author:** ![andreasch](https://avatars.discourse-cdn.com/v4/letter/a/90db22/32.png) [@andreasch](https://discuss.elastic.co/u/andreasch)\
**Post date:** [October 8, 2012, 8:24pm UTC](https://discuss.elastic.co/t/replacing-standard-actions-from-a-java-plugin/9278/3 "2012-10-08T20:24:44Z")

</div>

Ivan,

I cannot find onModule() anywhere in the Elasticsearch API.

Andreas

On Monday, October 8, 2012 1:10:37 PM UTC-7, Ivan Brusic wrote:

> I cannot say if it is intentional or not, but it definitely seems like  
> your custom action is getting added to the action map first, and then  
> getting overridden later.
> 
> I wonder if the flow would be different if you used the onModule method  
> instead of processModule:
> 
> ```
> public void onModule(ActionModule actionModule ) {
> actionModule.registerAction(IndexAction.INSTANCE, 
> 
> ```
> 
> CustomIndexAction.class);  
> }
> 
> Probably not, but worth a try.
> 
> --  
> Ivan
> 
> On Mon, Oct 8, 2012 at 11:56 AM, Andreas Christoforides \<  
> [andreas.chr...@gmail.com](mailto:andreas.chr...@gmail.com) \<javascript:\>\> wrote:
> 
> > I created a plugin that tries to replace the standard index action with  
> > my own implementation. In my plugin, I have the following method:  
> > @Override  
> > public void processModule(Module module) {
> > 
> > ```
> > logger.info("Processing module");
> > 
> > ```
> > 
> > if (module instanceof ActionModule) {  
> > ActionModule actionModule = (ActionModule) module;  
> > logger.info("Found action module");
> > 
> > actionModule.registerAction(IndexAction.INSTANCE, CustomIndexAction.class);  
> > logger.info("Registered custom index action in  
> > place of standard index action");  
> > }  
> > }  
> > I can see all the log statements during startup. However, the custom  
> > action never gets executed. I debugged the custom plugin and action in an  
> > embedded Elasticsearch and I noticed that the processModule() of my custom  
> > plugin gets called first and then the configure() method of the  
> > ActionModule is called overriding my custom action.
> > 
> > Is this intentional or is this a defect?
> > 
> > Thanks,  
> > Andreas
> > 
> > --

--

---

<div class="post-metadata">

**Author:** ![Ivan](https://avatars.discourse-cdn.com/v4/letter/i/df788c/32.png) [@Ivan](https://discuss.elastic.co/u/Ivan)\
**Post date:** [October 8, 2012, 8:43pm UTC](https://discuss.elastic.co/t/replacing-standard-actions-from-a-java-plugin/9278/4 "2012-10-08T20:43:55Z")

</div>

The method is called via reflection, so it is not overridden from the base  
class. See more info here:

> <https://github.com/elastic/elasticsearch/issues/1613>
>
> Currently, to add custom injections to different modules, plugins need to implem…ent \`processModule\` method and then do instanceof checks.
> 
> Allow for plugins to implement an \`onModule\` method that will be injected automatically with the parameter module type. For example: \`onModule(AnalyzerModule module) {...}\`.

All of the official plugins should no longer use processModule. For  
example, this is the RabbitMQ plugin:

> <https://github.com/elastic/elasticsearch-river-rabbitmq/blob/master/src/main/java/org/elasticsearch/plugin/river/rabbitmq/RabbitmqRiverPlugin.java>

--  
Ivan

On Mon, Oct 8, 2012 at 1:24 PM, Andreas Christoforides \<  
[andreas.christoforides@gmail.com](mailto:andreas.christoforides@gmail.com)\> wrote:

> Ivan,
> 
> I cannot find onModule() anywhere in the Elasticsearch API.
> 
> Andreas
> 
> On Monday, October 8, 2012 1:10:37 PM UTC-7, Ivan Brusic wrote:
> 
> > I cannot say if it is intentional or not, but it definitely seems like  
> > your custom action is getting added to the action map first, and then  
> > getting overridden later.
> > 
> > I wonder if the flow would be different if you used the onModule method  
> > instead of processModule:
> > 
> > ```
> > public void onModule(ActionModule actionModule ) {
> > actionModule.registerAction(**IndexAction.INSTANCE,
> > 
> > ```
> > 
> > CustomIndexAction.class);  
> > }
> > 
> > Probably not, but worth a try.
> > 
> > --  
> > Ivan
> > 
> > On Mon, Oct 8, 2012 at 11:56 AM, Andreas Christoforides \<  
> > andreas.chr...@gmail.\*\*com\> wrote:
> > 
> > > I created a plugin that tries to replace the standard index action with  
> > > my own implementation. In my plugin, I have the following method:  
> > > @Override  
> > > public void processModule(Module module) {
> > > 
> > > ```
> > > logger.info("Processing module");
> > > 
> > > ```
> > > 
> > > if (module instanceof ActionModule) {  
> > > ActionModule actionModule = (ActionModule) module;  
> > > logger.info("Found action module");  
> > > actionModule.registerAction(\*\*IndexAction.INSTANCE, \*\*  
> > > CustomIndexAction.class);  
> > > logger.info("Registered custom index action in  
> > > place of standard index action");  
> > > }  
> > > }  
> > > I can see all the log statements during startup. However, the custom  
> > > action never gets executed. I debugged the custom plugin and action in an  
> > > embedded Elasticsearch and I noticed that the processModule() of my custom  
> > > plugin gets called first and then the configure() method of the  
> > > ActionModule is called overriding my custom action.
> > > 
> > > Is this intentional or is this a defect?
> > > 
> > > Thanks,  
> > > Andreas
> > > 
> > > --
> > 
> > --

--

---

<div class="post-metadata">

**Author:** ![andreasch](https://avatars.discourse-cdn.com/v4/letter/a/90db22/32.png) [@andreasch](https://discuss.elastic.co/u/andreasch)\
**Post date:** [October 8, 2012, 8:50pm UTC](https://discuss.elastic.co/t/replacing-standard-actions-from-a-java-plugin/9278/5 "2012-10-08T20:50:18Z")

</div>

I added the onModule method in the plugin. Both methods are called before  
the initialization of the ActionModule.

I am trying to change the way the index action executes Specifically, I  
would like to change the routing before the index action executes.

Any other way I can accomplish that besides using a plugin that registers a  
custom action?

Andreas

On Monday, October 8, 2012 1:24:44 PM UTC-7, Andreas Christoforides wrote:

> Ivan,
> 
> I cannot find onModule() anywhere in the Elasticsearch API.
> 
> Andreas
> 
> On Monday, October 8, 2012 1:10:37 PM UTC-7, Ivan Brusic wrote:
> 
> > I cannot say if it is intentional or not, but it definitely seems like  
> > your custom action is getting added to the action map first, and then  
> > getting overridden later.
> > 
> > I wonder if the flow would be different if you used the onModule method  
> > instead of processModule:
> > 
> > ```
> > public void onModule(ActionModule actionModule ) {
> > actionModule.registerAction(IndexAction.INSTANCE, 
> > 
> > ```
> > 
> > CustomIndexAction.class);  
> > }
> > 
> > Probably not, but worth a try.
> > 
> > --  
> > Ivan
> > 
> > On Mon, Oct 8, 2012 at 11:56 AM, Andreas Christoforides \<  
> > [andreas.chr...@gmail.com](mailto:andreas.chr...@gmail.com)\> wrote:
> > 
> > > I created a plugin that tries to replace the standard index action with  
> > > my own implementation. In my plugin, I have the following method:  
> > > @Override  
> > > public void processModule(Module module) {
> > > 
> > > ```
> > > logger.info("Processing module");
> > > 
> > > ```
> > > 
> > > if (module instanceof ActionModule) {  
> > > ActionModule actionModule = (ActionModule) module;  
> > > logger.info("Found action module");
> > > 
> > > actionModule.registerAction(IndexAction.INSTANCE, CustomIndexAction.class);  
> > > logger.info("Registered custom index action in  
> > > place of standard index action");  
> > > }  
> > > }  
> > > I can see all the log statements during startup. However, the custom  
> > > action never gets executed. I debugged the custom plugin and action in an  
> > > embedded Elasticsearch and I noticed that the processModule() of my custom  
> > > plugin gets called first and then the configure() method of the  
> > > ActionModule is called overriding my custom action.
> > > 
> > > Is this intentional or is this a defect?
> > > 
> > > Thanks,  
> > > Andreas
> > > 
> > > --

--

---

<div class="post-metadata">

**Author:** ![andreasch](https://avatars.discourse-cdn.com/v4/letter/a/90db22/32.png) [@andreasch](https://discuss.elastic.co/u/andreasch)\
**Post date:** [October 9, 2012, 4:22pm UTC](https://discuss.elastic.co/t/replacing-standard-actions-from-a-java-plugin/9278/6 "2012-10-09T16:22:06Z")

</div>

Should I submit a feature request/issue for this?

On Monday, October 8, 2012 1:50:18 PM UTC-7, Andreas Christoforides wrote:

> I added the onModule method in the plugin. Both methods are called before  
> the initialization of the ActionModule.
> 
> I am trying to change the way the index action executes Specifically, I  
> would like to change the routing before the index action executes.
> 
> Any other way I can accomplish that besides using a plugin that registers  
> a custom action?
> 
> Andreas
> 
> On Monday, October 8, 2012 1:24:44 PM UTC-7, Andreas Christoforides wrote:
> 
> > Ivan,
> > 
> > I cannot find onModule() anywhere in the Elasticsearch API.
> > 
> > Andreas
> > 
> > On Monday, October 8, 2012 1:10:37 PM UTC-7, Ivan Brusic wrote:
> > 
> > > I cannot say if it is intentional or not, but it definitely seems like  
> > > your custom action is getting added to the action map first, and then  
> > > getting overridden later.
> > > 
> > > I wonder if the flow would be different if you used the onModule method  
> > > instead of processModule:
> > > 
> > > ```
> > > public void onModule(ActionModule actionModule ) {
> > > actionModule.registerAction(IndexAction.INSTANCE, 
> > > 
> > > ```
> > > 
> > > CustomIndexAction.class);  
> > > }
> > > 
> > > Probably not, but worth a try.
> > > 
> > > --  
> > > Ivan
> > > 
> > > On Mon, Oct 8, 2012 at 11:56 AM, Andreas Christoforides \<  
> > > [andreas.chr...@gmail.com](mailto:andreas.chr...@gmail.com)\> wrote:
> > > 
> > > > I created a plugin that tries to replace the standard index action with  
> > > > my own implementation. In my plugin, I have the following method:  
> > > > @Override  
> > > > public void processModule(Module module) {
> > > > 
> > > > ```
> > > > logger.info("Processing module");
> > > > 
> > > > ```
> > > > 
> > > > if (module instanceof ActionModule) {  
> > > > ActionModule actionModule = (ActionModule) module;  
> > > > logger.info("Found action module");
> > > > 
> > > > actionModule.registerAction(IndexAction.INSTANCE, CustomIndexAction.class);  
> > > > logger.info("Registered custom index action in  
> > > > place of standard index action");  
> > > > }  
> > > > }  
> > > > I can see all the log statements during startup. However, the custom  
> > > > action never gets executed. I debugged the custom plugin and action in an  
> > > > embedded Elasticsearch and I noticed that the processModule() of my custom  
> > > > plugin gets called first and then the configure() method of the  
> > > > ActionModule is called overriding my custom action.
> > > > 
> > > > Is this intentional or is this a defect?
> > > > 
> > > > Thanks,  
> > > > Andreas
> > > > 
> > > > --

--

---

<div class="post-metadata">

**Author:** ![andreasch](https://avatars.discourse-cdn.com/v4/letter/a/90db22/32.png) [@andreasch](https://discuss.elastic.co/u/andreasch)\
**Post date:** [October 9, 2012, 4:39pm UTC](https://discuss.elastic.co/t/replacing-standard-actions-from-a-java-plugin/9278/7 "2012-10-09T16:39:50Z")

</div>

I submitted an issue about this:

> <https://github.com/elastic/elasticsearch/issues/2311>
>
> The plugin module is loaded before the actions module and therefore plugins are …loaded before registering the default actions. If a custom plugin registers a custom action in place of the default ones , the custom action is removed when the action module is loaded.
> 
> For more details see:
> 
> https://groups.google.com/d/topic/elasticsearch/OFNkDUcnJGA/discussion

On Tuesday, October 9, 2012 9:22:06 AM UTC-7, Andreas Christoforides wrote:

> Should I submit a feature request/issue for this?
> 
> On Monday, October 8, 2012 1:50:18 PM UTC-7, Andreas Christoforides wrote:
> 
> > I added the onModule method in the plugin. Both methods are called before  
> > the initialization of the ActionModule.
> > 
> > I am trying to change the way the index action executes Specifically, I  
> > would like to change the routing before the index action executes.
> > 
> > Any other way I can accomplish that besides using a plugin that registers  
> > a custom action?
> > 
> > Andreas
> > 
> > On Monday, October 8, 2012 1:24:44 PM UTC-7, Andreas Christoforides wrote:
> > 
> > > Ivan,
> > > 
> > > I cannot find onModule() anywhere in the Elasticsearch API.
> > > 
> > > Andreas
> > > 
> > > On Monday, October 8, 2012 1:10:37 PM UTC-7, Ivan Brusic wrote:
> > > 
> > > > I cannot say if it is intentional or not, but it definitely seems like  
> > > > your custom action is getting added to the action map first, and then  
> > > > getting overridden later.
> > > > 
> > > > I wonder if the flow would be different if you used the onModule method  
> > > > instead of processModule:
> > > > 
> > > > ```
> > > > public void onModule(ActionModule actionModule ) {
> > > > actionModule.registerAction(IndexAction.INSTANCE, 
> > > > 
> > > > ```
> > > > 
> > > > CustomIndexAction.class);  
> > > > }
> > > > 
> > > > Probably not, but worth a try.
> > > > 
> > > > --  
> > > > Ivan
> > > > 
> > > > On Mon, Oct 8, 2012 at 11:56 AM, Andreas Christoforides \<  
> > > > [andreas.chr...@gmail.com](mailto:andreas.chr...@gmail.com)\> wrote:
> > > > 
> > > > > I created a plugin that tries to replace the standard index action  
> > > > > with my own implementation. In my plugin, I have the following method:  
> > > > > @Override  
> > > > > public void processModule(Module module) {
> > > > > 
> > > > > ```
> > > > > logger.info("Processing module");
> > > > > 
> > > > > ```
> > > > > 
> > > > > if (module instanceof ActionModule) {  
> > > > > ActionModule actionModule = (ActionModule) module;  
> > > > > logger.info("Found action module");
> > > > > 
> > > > > actionModule.registerAction(IndexAction.INSTANCE, CustomIndexAction.class);  
> > > > > logger.info("Registered custom index action  
> > > > > in place of standard index action");  
> > > > > }  
> > > > > }  
> > > > > I can see all the log statements during startup. However, the custom  
> > > > > action never gets executed. I debugged the custom plugin and action in an  
> > > > > embedded Elasticsearch and I noticed that the processModule() of my custom  
> > > > > plugin gets called first and then the configure() method of the  
> > > > > ActionModule is called overriding my custom action.
> > > > > 
> > > > > Is this intentional or is this a defect?
> > > > > 
> > > > > Thanks,  
> > > > > Andreas
> > > > > 
> > > > > --

--

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 6, 2017, 3:09am UTC](https://discuss.elastic.co/t/replacing-standard-actions-from-a-java-plugin/9278/8 "2017-07-06T03:09:32Z")

</div>


