Set ClassLoader when calling EventListenerFactory
Before the change, certain libraries cannot be used in an event
listener implementation.
*/
package com.facebook.presto.eventlistener;
+import com.facebook.presto.spi.classloader.ThreadContextClassLoader;
import com.facebook.presto.spi.eventlistener.EventListener;
import com.facebook.presto.spi.eventlistener.EventListenerFactory;
import com.facebook.presto.spi.eventlistener.QueryCompletedEvent;
@@ -79,8 +80,10 @@ public class EventListenerManager
EventListenerFactory eventListenerFactory = eventListenerFactories.get(name);
checkState(eventListenerFactory != null, "Event listener %s is not registered", name);
+ try (ThreadContextClassLoader ignored = new ThreadContextClassLoader(eventListenerFactory.getClass().getClassLoader())) {
EventListener eventListener = eventListenerFactory.create(ImmutableMap.copyOf(properties));
this.configuredEventListener.set(Optional.of(eventListener));
+ }
log.info("-- Loaded event listener %s --", name);
}
