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

Add EventListener to HiveConnector #3358

Merged

Conversation

s2lomon
Copy link
Member

@s2lomon s2lomon commented Apr 6, 2020

opens up the possibility to add external event listeners
that live in hive plugin ecosystem

@cla-bot cla-bot bot added the cla-signed label Apr 6, 2020
Copy link
Member

@kokosing kokosing left a comment

Choose a reason for hiding this comment

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

Few minor comments. Otherwise looks good.

List<EventListener> eventListeners = injector.getInstance(Key.get(new TypeLiteral<Set<EventListener>>() {}))
.stream()
.map(listener -> new ClassLoaderSafeEventListener(listener, classLoader))
.collect(toImmutableList());
Copy link
Member

Choose a reason for hiding this comment

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

Why not to toImmutableSet()?

Copy link
Member

Choose a reason for hiding this comment

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

there is not point to even attempt any deduplication

Copy link
Member

Choose a reason for hiding this comment

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

I had two points, none of them serious:

  • injector.getInstance(Key.get(new TypeLiteral<Set<EventListener>>() {})) returns a set, so why do we change this?
  • Using list here could make a false impression that this could contain duplicates (set still can, but it is less obvious). I don't see a reason why one would need even thing about it.

Any way, I will it leave up to author.

Copy link
Member

Choose a reason for hiding this comment

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

Since ClassLoaderSafeEventListener doesn't (and shouldn't) implement equals, using set is pointless.

@@ -104,6 +109,7 @@ public static Connector createConnector(String catalogName, Map<String, String>
binder.bind(PageSorter.class).toInstance(context.getPageSorter());
binder.bind(CatalogName.class).toInstance(new CatalogName(catalogName));
Copy link
Member

Choose a reason for hiding this comment

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

Just add newSetBinder(binder, EventListener.class); here. I don't see a need for defaultEventListenerModule() method.

Copy link
Member Author

Choose a reason for hiding this comment

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

better reading experience along with expressing the intention of it, so that the reader doesn't have to guess that it's a necessary default Event Listener.

Copy link
Member

Choose a reason for hiding this comment

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

It is a matter of taste. I would prefer not to over-optimize reading experience, but rather follow the current layout.

Copy link
Member

Choose a reason for hiding this comment

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

Agreed, we should just bind an empty set here.

Copy link
Member Author

Choose a reason for hiding this comment

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

ok

private final EventListener delegate;
private final ClassLoader classLoader;

public ClassLoaderSafeEventListener(EventListener delegate, ClassLoader classLoader)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
public ClassLoaderSafeEventListener(EventListener delegate, ClassLoader classLoader)
public ClassLoaderSafeEventListener(@ForClassLoaderSafe EventListener delegate, ClassLoader classLoader)

Copy link
Member Author

Choose a reason for hiding this comment

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

What would that annotation do? This class is used as a decorator inside a stream/for-loop operation. Nothing will be injected into it through guice, as there are potentially many EventListeners etc. For me adding it there would be misleading, but maybe I don't get the full purpose.

Copy link
Member

Choose a reason for hiding this comment

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

ClassLoaderSafe* classes are also designed to be used with guice. I wanted to add this annotation to make sure it follows the convention and behaves like any other ClassLoaderSafe* class.

Copy link
Member

Choose a reason for hiding this comment

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

Please don't get me wrong. I don't want you to use it ;)

Copy link
Member Author

Choose a reason for hiding this comment

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

ok I get it :)

@findepi findepi changed the title Add EventListenes to HiveConnector Add EventListeners to HiveConnector Apr 7, 2020
@findepi findepi changed the title Add EventListeners to HiveConnector Add EventListener to HiveConnector Apr 7, 2020
@s2lomon s2lomon force-pushed the hive-plugin-event-listener-extension branch from 9d1fc6c to c6e4a43 Compare April 7, 2020 11:27
private static Module defaultEventListenerModule()
{
return binder -> {
Multibinder.newSetBinder(binder, EventListener.class)
Copy link
Member

Choose a reason for hiding this comment

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

static import

@s2lomon s2lomon force-pushed the hive-plugin-event-listener-extension branch from c6e4a43 to 4eaf459 Compare April 7, 2020 12:25
@@ -104,6 +109,7 @@ public static Connector createConnector(String catalogName, Map<String, String>
binder.bind(PageSorter.class).toInstance(context.getPageSorter());
binder.bind(CatalogName.class).toInstance(new CatalogName(catalogName));
Copy link
Member

Choose a reason for hiding this comment

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

Agreed, we should just bind an empty set here.

{
return binder -> {
newSetBinder(binder, EventListener.class)
.addBinding().toInstance(new EventListener() {});
Copy link
Member

Choose a reason for hiding this comment

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

There's no need to create a no-op listener. The default implementation of Connector.getEventListeners() returns an empty set, so empty iterable is legal. We just need to create the set binder.

Copy link
Member Author

Choose a reason for hiding this comment

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

fair point

@s2lomon s2lomon force-pushed the hive-plugin-event-listener-extension branch from 4eaf459 to ef9202d Compare April 8, 2020 13:09
@kokosing kokosing merged commit b5e3aff into trinodb:master Apr 9, 2020
@kokosing
Copy link
Member

kokosing commented Apr 9, 2020

Merged, thanks!

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

Successfully merging this pull request may close these issues.

4 participants