-
Notifications
You must be signed in to change notification settings - Fork 25.1k
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
Deguice ActionFilters #26691
Deguice ActionFilters #26691
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,7 @@ | |
package org.elasticsearch.http; | ||
|
||
import org.apache.http.message.BasicHeader; | ||
import org.apache.lucene.util.SetOnce; | ||
import org.elasticsearch.action.ActionListener; | ||
import org.elasticsearch.action.ActionRequest; | ||
import org.elasticsearch.action.admin.indices.refresh.RefreshRequest; | ||
|
@@ -31,12 +32,14 @@ | |
import org.elasticsearch.action.termvectors.MultiTermVectorsRequest; | ||
import org.elasticsearch.client.Client; | ||
import org.elasticsearch.client.Response; | ||
import org.elasticsearch.common.inject.AbstractModule; | ||
import org.elasticsearch.common.inject.Inject; | ||
import org.elasticsearch.common.inject.Module; | ||
import org.elasticsearch.cluster.service.ClusterService; | ||
import org.elasticsearch.common.io.stream.NamedWriteableRegistry; | ||
import org.elasticsearch.common.network.NetworkModule; | ||
import org.elasticsearch.common.settings.Settings; | ||
import org.elasticsearch.common.xcontent.NamedXContentRegistry; | ||
import org.elasticsearch.common.xcontent.XContentType; | ||
import org.elasticsearch.env.Environment; | ||
import org.elasticsearch.env.NodeEnvironment; | ||
import org.elasticsearch.index.query.BoolQueryBuilder; | ||
import org.elasticsearch.index.query.GeoShapeQueryBuilder; | ||
import org.elasticsearch.index.query.MoreLikeThisQueryBuilder; | ||
|
@@ -46,8 +49,10 @@ | |
import org.elasticsearch.indices.TermsLookup; | ||
import org.elasticsearch.plugins.ActionPlugin; | ||
import org.elasticsearch.plugins.Plugin; | ||
import org.elasticsearch.script.ScriptService; | ||
import org.elasticsearch.test.ESIntegTestCase.ClusterScope; | ||
import org.elasticsearch.threadpool.ThreadPool; | ||
import org.elasticsearch.watcher.ResourceWatcherService; | ||
import org.junit.After; | ||
import org.junit.Before; | ||
|
||
|
@@ -282,21 +287,20 @@ private Client transportClient() { | |
|
||
public static class ActionLoggingPlugin extends Plugin implements ActionPlugin { | ||
|
||
@Override | ||
public Collection<Module> createGuiceModules() { | ||
return Collections.<Module>singletonList(new ActionLoggingModule()); | ||
} | ||
private final SetOnce<LoggingFilter> loggingFilter = new SetOnce<>(); | ||
|
||
@Override | ||
public List<Class<? extends ActionFilter>> getActionFilters() { | ||
return singletonList(LoggingFilter.class); | ||
public Collection<Object> createComponents(Client client, ClusterService clusterService, ThreadPool threadPool, | ||
ResourceWatcherService resourceWatcherService, ScriptService scriptService, | ||
NamedXContentRegistry xContentRegistry, Environment environment, | ||
NodeEnvironment nodeEnvironment, NamedWriteableRegistry namedWriteableRegistry) { | ||
loggingFilter.set(new LoggingFilter(clusterService.getSettings(), threadPool)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this is a sign that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As this is meant to be extended by plugins, it's unclear what parameters would be useful to them. I think it's best to keep the interface lean. |
||
return Collections.emptyList(); | ||
} | ||
} | ||
|
||
public static class ActionLoggingModule extends AbstractModule { | ||
@Override | ||
protected void configure() { | ||
bind(LoggingFilter.class).asEagerSingleton(); | ||
public List<ActionFilter> getActionFilters() { | ||
return singletonList(loggingFilter.get()); | ||
} | ||
|
||
} | ||
|
@@ -305,7 +309,6 @@ public static class LoggingFilter extends ActionFilter.Simple { | |
|
||
private final ThreadPool threadPool; | ||
|
||
@Inject | ||
public LoggingFilter(Settings settings, ThreadPool pool) { | ||
super(settings); | ||
this.threadPool = pool; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The purpose of createComponents is to create services. This creates an unenforcible ordering dependency between creating these services and calling
getActionFilters()
.getActionFilters
should take whatever is necessary to creation action filters.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
getActionFilters
is meant to be used by plugins, for which we don't know about the parameters that they require. We have the same situation for a lot of other methods (e.g. getRestHandlers). In case of incorrect ordering, our tests will blow up.