-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
CURATOR-727: Allow watches to be executed asynchronously #514
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If the "asyncExecutor" could in fact always be pre-initialized to a "direct" (same thread Executor like Guava MoreExecutors.newDirectExecutorService), then there'd be no branching check around if it's present or not. Solr uses this technique in SimpleFacets too. That said, there's little complexity here so I'm not going to recommend it. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,6 +22,7 @@ | |
import com.google.common.base.Objects; | ||
import com.google.common.base.Preconditions; | ||
import java.io.Closeable; | ||
import java.util.concurrent.Executor; | ||
import org.apache.curator.framework.api.CuratorWatcher; | ||
import org.apache.curator.utils.ThreadUtils; | ||
import org.apache.zookeeper.WatchedEvent; | ||
|
@@ -65,14 +66,25 @@ public void process(WatchedEvent event) { | |
client.getWatcherRemovalManager().noteTriggeredWatcher(this); | ||
} | ||
|
||
Runnable watchRunnable = null; | ||
if (actualWatcher != null) { | ||
actualWatcher.process(new NamespaceWatchedEvent(client, event)); | ||
watchRunnable = () -> actualWatcher.process(new NamespaceWatchedEvent(client, event)); | ||
} else if (curatorWatcher != null) { | ||
try { | ||
curatorWatcher.process(new NamespaceWatchedEvent(client, event)); | ||
} catch (Exception e) { | ||
ThreadUtils.checkInterrupted(e); | ||
client.logError("Watcher exception", e); | ||
watchRunnable = () -> { | ||
try { | ||
curatorWatcher.process(new NamespaceWatchedEvent(client, event)); | ||
} catch (Exception e) { | ||
ThreadUtils.checkInterrupted(e); | ||
client.logError("Watcher exception", e); | ||
} | ||
}; | ||
} | ||
if (watchRunnable != null) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Perhaps more elegant to add an "else" that returns. Therefore, watchRunnable could be final non-null; no condition to act on it's null-ness. |
||
Executor watchExecutor = client.getAsyncWatchService(); | ||
if (watchExecutor != null) { | ||
watchExecutor.execute(watchRunnable); | ||
} else { | ||
watchRunnable.run(); | ||
} | ||
} | ||
} | ||
|
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.
If one of those long-running processes interacts with curator, I could see it failing. It'd be better to have close() relatively early call shutdown(), after publishing the close event.