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 */ 026public class AsyncEventBus extends EventBus { 027 028 /** 029 * Creates a new AsyncEventBus that will use {@code executor} to dispatch events. Assigns {@code 030 * identifier} as the bus's name for logging purposes. 031 * 032 * @param identifier short name for the bus, for logging purposes. 033 * @param executor Executor to use to dispatch events. It is the caller's responsibility to shut 034 * down the executor after the last event has been posted to this event bus. 035 */ 036 public AsyncEventBus(String identifier, Executor executor) { 037 super(identifier, executor, Dispatcher.legacyAsync(), LoggingHandler.INSTANCE); 038 } 039 040 /** 041 * Creates a new AsyncEventBus that will use {@code executor} to dispatch events. 042 * 043 * @param executor Executor to use to dispatch events. It is the caller's responsibility to shut 044 * down the executor after the last event has been posted to this event bus. 045 * @param subscriberExceptionHandler Handler used to handle exceptions thrown from subscribers. 046 * See {@link SubscriberExceptionHandler} for more information. 047 * @since 16.0 048 */ 049 public AsyncEventBus(Executor executor, SubscriberExceptionHandler subscriberExceptionHandler) { 050 super("default", executor, Dispatcher.legacyAsync(), subscriberExceptionHandler); 051 } 052 053 /** 054 * Creates a new AsyncEventBus that will use {@code executor} to dispatch events. 055 * 056 * @param executor Executor to use to dispatch events. It is the caller's responsibility to shut 057 * down the executor after the last event has been posted to this event bus. 058 */ 059 public AsyncEventBus(Executor executor) { 060 super("default", executor, Dispatcher.legacyAsync(), LoggingHandler.INSTANCE); 061 } 062}