Skip to content

Commit

Permalink
Set ClassLoader when calling EventListenerFactory
Browse files Browse the repository at this point in the history
Before the change, certain libraries cannot be used in an event
listener implementation.
  • Loading branch information
gray-eb committed Dec 4, 2018
1 parent c6134c4 commit 2b71271
Showing 1 changed file with 5 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
*/
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;
Expand Down Expand Up @@ -79,8 +80,10 @@ protected void setConfiguredEventListener(String name, Map<String, String> prope
EventListenerFactory eventListenerFactory = eventListenerFactories.get(name);
checkState(eventListenerFactory != null, "Event listener %s is not registered", name);

EventListener eventListener = eventListenerFactory.create(ImmutableMap.copyOf(properties));
this.configuredEventListener.set(Optional.of(eventListener));
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);
}
Expand Down

0 comments on commit 2b71271

Please sign in to comment.