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

Introduce a formal ExtensionPoint class to stream line extensions #12826

Merged
merged 1 commit into from
Aug 13, 2015

Conversation

s1monw
Copy link
Contributor

@s1monw s1monw commented Aug 12, 2015

This commit tries to add some infrastructure to streamline how extension
points should be strucutred. It's a simple approache with 4 implementations
for highlighter, suggester, allocation_decider and shards_allocator.
It simplifies adding new extension points and forces to register classes instead
of strings.

@rjernst
Copy link
Member

rjernst commented Aug 12, 2015

One thought here is to split ExtensionPoint into two different variants, one for a Set and one for a Map. Right now it looks like we have a switch for this, with if/else in the impl. We just have those two types of extension points, either we keep a set of class impls, or we keep a map from name to impl. I think separating them would make the module code a little clearer, and less error prone when adding these (must choose the type of extension when defining, instead of accidentally calling the wrong register method).

@@ -116,7 +116,7 @@ protected void configure() {

// bind ShardsAllocator
final String shardsAllocatorType = settings.get(AllocationModule.SHARDS_ALLOCATOR_TYPE_KEY, AllocationModule.BALANCED_ALLOCATOR);
final Class<? extends ShardsAllocator> shardsAllocator = shardsAllocators.get(shardsAllocatorType);
final Class<? extends ShardsAllocator> shardsAllocator = shardsAllocators.getExtension(shardsAllocatorType);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we could also factor out the lookup in settings and selection of the class? So we could have a bind method like below, but which takes the binder, Settings and the setting name? In this case, we can just have a lone if to check for the type and log the deprecation message (a little more work here, but a very unusual case)?

@rjernst
Copy link
Member

rjernst commented Aug 12, 2015

This looks great in general, I think it will simplify a lot where we have extension points, so we get the same logic/exception checking. I left a few comments/questions.

}


public static class MapExtensionPoint<T> extends ExtensionPoint<T> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Personally I would do these as two separate classes. Then the ctor here can take a map of builtins instead of set of names (which relies on registering those names independently)?

@rjernst
Copy link
Member

rjernst commented Aug 12, 2015

LGTM. I left two more questions but those can be follow ups or ignored.

This commit tries to add some infrastructure to streamline how extension
points should be strucutred. It's a simple approache with 4 implementations
for `highlighter`, `suggester`, `allocation_decider` and `shards_allocator`.
It simplifies adding new extension points and forces to register classes instead
of strings.
@s1monw s1monw merged commit 74f18d8 into elastic:master Aug 13, 2015
* all extensions by a single name and ensures that extensions are not registered
* more than once.
*/
public abstract class ExtensionPoint<T> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like these as they wrap guice ceremony.

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

Successfully merging this pull request may close these issues.

5 participants