-
Notifications
You must be signed in to change notification settings - Fork 3.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
Add EventListener to HiveConnector #3358
Add EventListener to HiveConnector #3358
Conversation
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.
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()); |
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.
Why not to toImmutableSet()
?
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.
there is not point to even attempt any deduplication
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.
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.
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.
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)); |
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.
Just add newSetBinder(binder, EventListener.class);
here. I don't see a need for defaultEventListenerModule()
method.
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.
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.
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.
It is a matter of taste. I would prefer not to over-optimize reading experience, but rather follow the current layout.
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.
Agreed, we should just bind an empty set here.
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.
ok
private final EventListener delegate; | ||
private final ClassLoader classLoader; | ||
|
||
public ClassLoaderSafeEventListener(EventListener delegate, ClassLoader classLoader) |
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.
public ClassLoaderSafeEventListener(EventListener delegate, ClassLoader classLoader) | |
public ClassLoaderSafeEventListener(@ForClassLoaderSafe EventListener delegate, ClassLoader classLoader) |
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.
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.
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.
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.
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.
Please don't get me wrong. I don't want you to use it ;)
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.
ok I get it :)
...toolkit/src/main/java/io/prestosql/plugin/base/classloader/ClassLoaderSafeEventListener.java
Show resolved
Hide resolved
9d1fc6c
to
c6e4a43
Compare
private static Module defaultEventListenerModule() | ||
{ | ||
return binder -> { | ||
Multibinder.newSetBinder(binder, EventListener.class) |
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.
static import
c6e4a43
to
4eaf459
Compare
@@ -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)); |
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.
Agreed, we should just bind an empty set here.
{ | ||
return binder -> { | ||
newSetBinder(binder, EventListener.class) | ||
.addBinding().toInstance(new EventListener() {}); |
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.
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.
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.
fair point
4eaf459
to
ef9202d
Compare
Merged, thanks! |
opens up the possibility to add external event listeners
that live in hive plugin ecosystem