001/*
002 * Copyright (C) 2007 The Guava Authors
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
005 * in compliance with the License. You may obtain a copy of the License at
006 *
007 * http://www.apache.org/licenses/LICENSE-2.0
008 *
009 * Unless required by applicable law or agreed to in writing, software distributed under the License
010 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
011 * or implied. See the License for the specific language governing permissions and limitations under
012 * the License.
013 */
014
015package com.google.common.eventbus;
016
017import java.util.concurrent.Executor;
018
019/**
020 * An {@link EventBus} that takes the Executor of your choice and uses it to dispatch events,
021 * allowing dispatch to occur asynchronously.
022 *
023 * @author Cliff Biffle
024 * @since 10.0
025 */
026@ElementTypesAreNonnullByDefault
027public class AsyncEventBus extends EventBus {
028
029  /**
030   * Creates a new AsyncEventBus that will use {@code executor} to dispatch events. Assigns {@code
031   * identifier} as the bus's name for logging purposes.
032   *
033   * @param identifier short name for the bus, for logging purposes.
034   * @param executor Executor to use to dispatch events. It is the caller's responsibility to shut
035   *     down the executor after the last event has been posted to this event bus.
036   */
037  public AsyncEventBus(String identifier, Executor executor) {
038    super(identifier, executor, Dispatcher.legacyAsync(), LoggingHandler.INSTANCE);
039  }
040
041  /**
042   * Creates a new AsyncEventBus that will use {@code executor} to dispatch events.
043   *
044   * @param executor Executor to use to dispatch events. It is the caller's responsibility to shut
045   *     down the executor after the last event has been posted to this event bus.
046   * @param subscriberExceptionHandler Handler used to handle exceptions thrown from subscribers.
047   *     See {@link SubscriberExceptionHandler} for more information.
048   * @since 16.0
049   */
050  public AsyncEventBus(Executor executor, SubscriberExceptionHandler subscriberExceptionHandler) {
051    super("default", executor, Dispatcher.legacyAsync(), subscriberExceptionHandler);
052  }
053
054  /**
055   * Creates a new AsyncEventBus that will use {@code executor} to dispatch events.
056   *
057   * @param executor Executor to use to dispatch events. It is the caller's responsibility to shut
058   *     down the executor after the last event has been posted to this event bus.
059   */
060  public AsyncEventBus(Executor executor) {
061    super("default", executor, Dispatcher.legacyAsync(), LoggingHandler.INSTANCE);
062  }
063}