You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@aurora.apache.org by ke...@apache.org on 2014/11/08 02:20:23 UTC

incubator-aurora git commit: Use async eventbus

Repository: incubator-aurora
Updated Branches:
  refs/heads/master 66bd6fec9 -> 54b026272


Use async eventbus

This change uses AsyncEventBus in production code. Some test code
still expects eventSink.post() to block. I plan to address in a
follow-up review.

Testing Done:
./gradlew -Pq build

Bugs closed: AURORA-920

Reviewed at https://reviews.apache.org/r/27762/


Project: http://git-wip-us.apache.org/repos/asf/incubator-aurora/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-aurora/commit/54b02627
Tree: http://git-wip-us.apache.org/repos/asf/incubator-aurora/tree/54b02627
Diff: http://git-wip-us.apache.org/repos/asf/incubator-aurora/diff/54b02627

Branch: refs/heads/master
Commit: 54b02627229b347edfb46644b0aa56fa0dd5cbd5
Parents: 66bd6fe
Author: Kevin Sweeney <ke...@apache.org>
Authored: Fri Nov 7 16:54:12 2014 -0800
Committer: Kevin Sweeney <ke...@apache.org>
Committed: Fri Nov 7 16:54:12 2014 -0800

----------------------------------------------------------------------
 .../scheduler/events/PubsubEventModule.java     | 28 ++++++++++++++++----
 1 file changed, 23 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-aurora/blob/54b02627/src/main/java/org/apache/aurora/scheduler/events/PubsubEventModule.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/aurora/scheduler/events/PubsubEventModule.java b/src/main/java/org/apache/aurora/scheduler/events/PubsubEventModule.java
index cd5aa17..0ba31ac 100644
--- a/src/main/java/org/apache/aurora/scheduler/events/PubsubEventModule.java
+++ b/src/main/java/org/apache/aurora/scheduler/events/PubsubEventModule.java
@@ -14,15 +14,20 @@
 package org.apache.aurora.scheduler.events;
 
 import java.util.Set;
+import java.util.concurrent.Executor;
+import java.util.concurrent.Executors;
 import java.util.logging.Logger;
 
 import javax.inject.Inject;
 import javax.inject.Singleton;
 
 import com.google.common.annotations.VisibleForTesting;
+import com.google.common.eventbus.AsyncEventBus;
 import com.google.common.eventbus.DeadEvent;
 import com.google.common.eventbus.EventBus;
 import com.google.common.eventbus.Subscribe;
+import com.google.common.util.concurrent.MoreExecutors;
+import com.google.common.util.concurrent.ThreadFactoryBuilder;
 import com.google.inject.AbstractModule;
 import com.google.inject.Binder;
 import com.google.inject.multibindings.Multibinder;
@@ -42,24 +47,37 @@ public final class PubsubEventModule extends AbstractModule {
 
   private static final Logger LOG = Logger.getLogger(PubsubEventModule.class.getName());
 
-  private PubsubEventModule() {
+  private final boolean async;
+
+  private PubsubEventModule(boolean async) {
     // Must be constructed through factory.
+    this.async = async;
   }
 
   @VisibleForTesting
   public static void installForTest(Binder binder) {
-    binder.install(new PubsubEventModule());
+    binder.install(new PubsubEventModule(false));
   }
 
   @Override
   protected void configure() {
-    final EventBus eventBus = new EventBus("TaskEvents");
+    final Executor executor;
+    if (async) {
+      executor = Executors.newCachedThreadPool(
+          new ThreadFactoryBuilder()
+              .setDaemon(true)
+              .setNameFormat("AsyncTaskEvents-%d")
+              .build());
+    } else {
+      executor = MoreExecutors.sameThreadExecutor();
+    }
+
+    final EventBus eventBus = new AsyncEventBus("AsyncTaskEvents", executor);
     eventBus.register(new Object() {
       @Subscribe public void logDeadEvent(DeadEvent event) {
         LOG.warning("Captured dead event " + event.getEvent());
       }
     });
-
     bind(EventBus.class).toInstance(eventBus);
 
     EventSink eventSink = new EventSink() {
@@ -103,7 +121,7 @@ public final class PubsubEventModule extends AbstractModule {
     binder.bind(SchedulingFilter.class).annotatedWith(NotifyDelegate.class).to(filterClass);
     binder.bind(SchedulingFilter.class).to(NotifyingSchedulingFilter.class);
     binder.bind(NotifyingSchedulingFilter.class).in(Singleton.class);
-    binder.install(new PubsubEventModule());
+    binder.install(new PubsubEventModule(true));
   }
 
   private static Multibinder<EventSubscriber> getSubscriberBinder(Binder binder) {