Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

subclass of ActionFilter.Simple was invoked twice #14577

Closed
whdwsl opened this issue Nov 6, 2015 · 2 comments
Closed

subclass of ActionFilter.Simple was invoked twice #14577

whdwsl opened this issue Nov 6, 2015 · 2 comments
Assignees

Comments

@whdwsl
Copy link

whdwsl commented Nov 6, 2015

hi, guys, i wrote a Filter whice extends ActionFilter.Simple , and override the method : apply(String action, ActionResponse response, ActionListener listener). when i invoke method: client.prepareSearch, the apply method was invoked twice whice is not i wanted, once is enough. is there sth i missed ? here is my code :

public static class LoggingFilter extends ActionFilter.Simple {

    @Inject
    public LoggingFilter(Settings settings) {
        super(settings);
    }

    @Override
    public int order() {
        return 999;
    }

    @Override
    protected boolean apply(String action, ActionRequest request, ActionListener listener) {
        return true;
    }

    @Override
    protected boolean apply(String action, ActionResponse response, ActionListener listener) {
        if ("indices:data/read/search".equals(action)) {
            System.out.println("=========" + action + "======" + listener);
            System.out.println("=========" + response.hashCode() + "======" );
        }

        return true;
    }
}

public class ActionInvokeModule extends AbstractModule implements PreProcessModule {

    @Override
    protected void configure() {
        bind(LoggingFilter.class).asEagerSingleton();
    }

    @Override
    public void processModule(Module module) {
        if (module instanceof ActionModule) {
            ((ActionModule)module).registerFilter(LoggingFilter.class);
        }
    }
}

public class ActionInvokePlugin extends AbstractPlugin {

@Override
public Collection<Class<? extends Module>> modules() {
    Collection<Class<? extends Module>> modules = new ArrayList<Class<? extends Module>>();
    modules.add(ActionLoggingModule.class);
    System.out.println("==========loaded log plugin");
    return modules;
}

}

this is my client :
@test
public void testSimpleSearch() {
SearchResponse response = client.prepareSearch("twitter2")
.setTypes("tweet2")
.setSearchType(SearchType.DFS_QUERY_THEN_FETCH)
.setQuery(QueryBuilders.termQuery("user", "wangwu")) // Query
.setFrom(0).setSize(60).setExplain(true)
.execute()
.actionGet();
for (SearchHit hit : response.getHits().getHits()) {
System.out.println("======" + hit.getSource());
}

}
@javanna javanna self-assigned this Nov 17, 2015
@javanna
Copy link
Member

javanna commented Nov 23, 2015

I think this is the same as #11710. If it happens only with search, it's because TransportSearchAction delegates to a subaction (depending on the search type) which causes the duplication you are seeing.

@javanna
Copy link
Member

javanna commented Nov 24, 2015

Closing as duplicate of #11710 as it is caused by the same problem. Feel free to reopen if that's not the case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants