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 com.google.common.annotations.Beta; 018import java.util.concurrent.Executor; 019 020/** 021 * An {@link EventBus} that takes the Executor of your choice and uses it to dispatch events, 022 * allowing dispatch to occur asynchronously. 023 * 024 * @author Cliff Biffle 025 * @since 10.0 026 */ 027@Beta 028public class AsyncEventBus extends EventBus { 029 030 /** 031 * Creates a new AsyncEventBus that will use {@code executor} to dispatch events. Assigns 032 * {@code identifier} as the bus's name for logging purposes. 033 * 034 * @param identifier short name for the bus, for logging purposes. 035 * @param executor Executor to use to dispatch events. It is the caller's responsibility to shut 036 * down the executor after the last event has been posted to this event bus. 037 */ 038 public AsyncEventBus(String identifier, Executor executor) { 039 super(identifier, executor, Dispatcher.legacyAsync(), LoggingHandler.INSTANCE); 040 } 041 042 /** 043 * Creates a new AsyncEventBus that will use {@code executor} to dispatch events. 044 * 045 * @param executor Executor to use to dispatch events. It is the caller's responsibility to shut 046 * down the executor after the last event has been posted to this event bus. 047 * @param subscriberExceptionHandler Handler used to handle exceptions thrown from subscribers. 048 * See {@link SubscriberExceptionHandler} for more information. 049 * @since 16.0 050 */ 051 public AsyncEventBus(Executor executor, SubscriberExceptionHandler subscriberExceptionHandler) { 052 super("default", executor, Dispatcher.legacyAsync(), subscriberExceptionHandler); 053 } 054 055 /** 056 * Creates a new AsyncEventBus that will use {@code executor} to dispatch events. 057 * 058 * @param executor Executor to use to dispatch events. It is the caller's responsibility to shut 059 * down the executor after the last event has been posted to this event bus. 060 */ 061 public AsyncEventBus(Executor executor) { 062 super("default", executor, Dispatcher.legacyAsync(), LoggingHandler.INSTANCE); 063 } 064}