1 /* 2 * Copyright (C) 2007 The Guava Authors 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 * in compliance with the License. You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software distributed under the License 10 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 * or implied. See the License for the specific language governing permissions and limitations under 12 * the License. 13 */ 14 15 package com.google.common.eventbus; 16 17 import com.google.common.annotations.Beta; 18 import java.util.concurrent.Executor; 19 20 /** 21 * An {@link EventBus} that takes the Executor of your choice and uses it to dispatch events, 22 * allowing dispatch to occur asynchronously. 23 * 24 * @author Cliff Biffle 25 * @since 10.0 26 */ 27 @Beta 28 public class AsyncEventBus extends EventBus { 29 30 /** 31 * Creates a new AsyncEventBus that will use {@code executor} to dispatch events. Assigns {@code 32 * identifier} as the bus's name for logging purposes. 33 * 34 * @param identifier short name for the bus, for logging purposes. 35 * @param executor Executor to use to dispatch events. It is the caller's responsibility to shut 36 * down the executor after the last event has been posted to this event bus. 37 */ AsyncEventBus(String identifier, Executor executor)38 public AsyncEventBus(String identifier, Executor executor) { 39 super(identifier, executor, Dispatcher.legacyAsync(), LoggingHandler.INSTANCE); 40 } 41 42 /** 43 * Creates a new AsyncEventBus that will use {@code executor} to dispatch events. 44 * 45 * @param executor Executor to use to dispatch events. It is the caller's responsibility to shut 46 * down the executor after the last event has been posted to this event bus. 47 * @param subscriberExceptionHandler Handler used to handle exceptions thrown from subscribers. 48 * See {@link SubscriberExceptionHandler} for more information. 49 * @since 16.0 50 */ AsyncEventBus(Executor executor, SubscriberExceptionHandler subscriberExceptionHandler)51 public AsyncEventBus(Executor executor, SubscriberExceptionHandler subscriberExceptionHandler) { 52 super("default", executor, Dispatcher.legacyAsync(), subscriberExceptionHandler); 53 } 54 55 /** 56 * Creates a new AsyncEventBus that will use {@code executor} to dispatch events. 57 * 58 * @param executor Executor to use to dispatch events. It is the caller's responsibility to shut 59 * down the executor after the last event has been posted to this event bus. 60 */ AsyncEventBus(Executor executor)61 public AsyncEventBus(Executor executor) { 62 super("default", executor, Dispatcher.legacyAsync(), LoggingHandler.INSTANCE); 63 } 64 } 65