本文整理汇总了Java中com.google.common.eventbus.AsyncEventBus类的典型用法代码示例。如果您正苦于以下问题:Java AsyncEventBus类的具体用法?Java AsyncEventBus怎么用?Java AsyncEventBus使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
AsyncEventBus类属于com.google.common.eventbus包,在下文中一共展示了AsyncEventBus类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: registerResources
import com.google.common.eventbus.AsyncEventBus; //导入依赖的package包/类
private void registerResources(Environment environment) {
EventStore eventStore = new InMemoryEventStore();
EventBus eventBus = new AsyncEventBus(newSingleThreadExecutor());
// domain model
AccountService accountService = new AccountService(eventStore, eventBus);
environment.jersey().register(new AccountsResource(accountService));
environment.jersey().register(new AccountResource(accountService));
environment.jersey().register(new DepositsResource(accountService));
environment.jersey().register(new WithdrawalsResource(accountService));
ClientService clientService = new ClientService(eventStore);
environment.jersey().register(new ClientsResource(clientService));
environment.jersey().register(new ClientResource(clientService));
// read model
TransactionsRepository transactionsRepository = new InMemoryTransactionsRepository();
eventBus.register(new TransactionsListener(transactionsRepository));
environment.jersey().register(new AccountTransactionsResource(transactionsRepository));
AccountsRepository accountsRepository = new InMemoryAccountsRepository();
eventBus.register(new AccountsListener(accountsRepository));
environment.jersey().register(new ClientAccountsResource(accountsRepository));
}
示例2: provideEventBus
import com.google.common.eventbus.AsyncEventBus; //导入依赖的package包/类
@Provides
@Singleton
EventBus provideEventBus(@AsyncExecutor Executor executor, StatsProvider statsProvider) {
final AtomicLong subscriberExceptions = statsProvider.makeCounter(EXCEPTIONS_STAT);
EventBus eventBus = new AsyncEventBus(
executor,
(exception, context) -> {
subscriberExceptions.incrementAndGet();
log.error(
"Failed to dispatch event to " + context.getSubscriberMethod() + ": " + exception,
exception);
}
);
eventBus.register(new DeadEventHandler());
return eventBus;
}
示例3: main
import com.google.common.eventbus.AsyncEventBus; //导入依赖的package包/类
public static void main(String[] args) {
ExecutorService executor = Executors.newFixedThreadPool(5);
EventBus eventBus = new AsyncEventBus("alert-bus", executor);
SmtpClientConfig smtpClientconfig = new SmtpClientConfig(MAIL_SERVER, MAIL_PORT, AUTH, USE_SSL);
Alerter alerter = new SmtpAlerter(new SmtpAlerterConfig(RECIPIENTS, "[email protected]", "alert message",
"WARN|ERROR", smtpClientconfig));
eventBus.register(alerter);
// should NOT be sent (doesn't match severity filter)
eventBus.post(new Alert("/topic", AlertSeverity.INFO, UtcTime.now(), "hello info", null));
// should be sent (matches severity filter)
eventBus.post(new Alert("/topic", AlertSeverity.WARN, UtcTime.now(), "hello warning", null));
eventBus.unregister(alerter);
executor.shutdownNow();
}
示例4: main
import com.google.common.eventbus.AsyncEventBus; //导入依赖的package包/类
public static void main(String[] args) {
ExecutorService executor = Executors.newFixedThreadPool(5);
EventBus eventBus = new AsyncEventBus("alert-bus", executor);
Map<String, JsonElement> standardMetadata = ImmutableMap.of("key", JsonUtils.toJson("value"));
Alerter alerter = new HttpAlerter(new HttpAlerterConfig(Arrays.asList(DESTINATION_URL), ".*", null),
standardMetadata);
eventBus.register(alerter);
// should NOT be sent (doesn't match severity filter)
eventBus.post(new Alert("/topic", AlertSeverity.INFO, UtcTime.now(), "hello info", null));
// should be sent (matches severity filter)
eventBus.post(new Alert("/topic", AlertSeverity.WARN, UtcTime.now(), "hello warning", null));
eventBus.unregister(alerter);
executor.shutdownNow();
}
示例5: configure
import com.google.common.eventbus.AsyncEventBus; //导入依赖的package包/类
@Override
protected void configure() {
bind(ActionRepository.class).to(CassandraActionRepository.class);
bind(PlayerRepository.class).to(CassandraPlayerRepository.class);
bind(BadgeRepository.class).to(CassandraBadgeRepository.class);
bind(EventRepository.class).to(CassandraEventRepository.class);
bind(EventTypeRepository.class).to(CassandraEventTypeRepository.class);
this.eventBus = new AsyncEventBus(java.util.concurrent.Executors.newCachedThreadPool());
bind(EventBus.class).toInstance(eventBus);
bindListener(Matchers.any(), new TypeListener() {
public <I> void hear(TypeLiteral<I> typeLiteral, TypeEncounter<I> typeEncounter) {
typeEncounter.register(new InjectionListener<I>() {
public void afterInjection(I i) {
eventBus.register(i);
}
});
}
});
}
示例6: KubernetesCloudPool
import com.google.common.eventbus.AsyncEventBus; //导入依赖的package包/类
/**
* Creates a {@link KubernetesCloudPool}.
*
* @param apiServerClient
* A client that can be configured to execute (authenticated)
* HTTP requests against the REST API of a certain Kubernetes API
* server.
* @param executor
* Executor used to schedule periodical tasks.
* @param eventBus
* {@link EventBus} used to push {@link Alert}s. May be
* <code>null</code>, in which case a default one is created.
*/
public KubernetesCloudPool(ApiServerClient apiServerClient, ScheduledExecutorService executor, EventBus eventBus) {
checkArgument(apiServerClient != null, "apiServerClient cannot be null");
checkArgument(executor != null, "executor cannot be null");
this.apiServerClient = apiServerClient;
this.executor = executor;
this.eventBus = eventBus != null ? eventBus : new AsyncEventBus(executor);
this.alerter = new MultiplexingAlerter();
this.eventBus.register(this.alerter);
this.podPool = null;
this.config = null;
this.started = false;
}
示例7: initialize
import com.google.common.eventbus.AsyncEventBus; //导入依赖的package包/类
synchronized public void initialize() throws Exception {
if (executor != null) {
throw new IllegalStateException("Already initialized");
}
executor = Executors.newScheduledThreadPool(1);
eventBus = new AsyncEventBus(executor);
}
示例8: setEventBus
import com.google.common.eventbus.AsyncEventBus; //导入依赖的package包/类
@SuppressWarnings("rawtypes")
public void setEventBus(AsyncEventBus eventBus) {
// if (callable instanceof PersistenceRequest) {
// PersistenceRequest<?> request = (PersistenceRequest)callable;
// request.setEventBus(eventBus);
// }
}
示例9: SessionEventBus
import com.google.common.eventbus.AsyncEventBus; //导入依赖的package包/类
SessionEventBus(final Session session) {
this.session = session;
this.executorService = Executors.newCachedThreadPool();
this.eventBus =
new AsyncEventBus(
executorService,
(throwable, subscriberExceptionContext) -> {
if (!(throwable instanceof RejectedExecutionException)) {
log.error(throwable.getMessage(), throwable);
}
});
}
示例10: AbstractBot
import com.google.common.eventbus.AsyncEventBus; //导入依赖的package包/类
public AbstractBot() {
eventBus = new AsyncEventBus(
ThreadUtil.newCachedThreadPool("event-dispatcher-%d"),
(exception, context) -> {
App.logger.catching(exception);
Watcher.logException();
}
);
eventBus.register(new MessageEventHandler());
channels = new ConcurrentHashMap<>();
channelManager = new ChannelManager(channels);
}
示例11: _createEventBusInstance
import com.google.common.eventbus.AsyncEventBus; //导入依赖的package包/类
@Override
protected EventBus _createEventBusInstance() {
ExecutorService execService = _executorServiceManager.getExecutorService();
_eventBusInstance = new AsyncEventBus("R01 ASYNC EventBus",
execService);
return _eventBusInstance;
}
示例12: EventBusSubscriberBeanPostProcessor
import com.google.common.eventbus.AsyncEventBus; //导入依赖的package包/类
@Autowired
public EventBusSubscriberBeanPostProcessor(final EventBus eventBus, final AsyncEventBus asyncEventBus) {
Assert.notNull(eventBus, "EventBus should not be null");
Assert.notNull(asyncEventBus, "AsyncEventBus should not be null");
this.eventBus = eventBus;
this.asyncEventBus = asyncEventBus;
}
示例13: GoogleContainerEngineCloudPool
import com.google.common.eventbus.AsyncEventBus; //导入依赖的package包/类
public GoogleContainerEngineCloudPool(ContainerClusterClient gkeClient, EventBus eventBus,
ScheduledExecutorService executor) {
this.client = gkeClient;
this.executor = executor;
this.eventBus = Optional.ofNullable(eventBus).orElse(new AsyncEventBus(this.executor));
this.alerter = new MultiplexingAlerter();
this.eventBus.register(this.alerter);
this.desiredSize = null;
}
示例14: BuckEventBus
import com.google.common.eventbus.AsyncEventBus; //导入依赖的package包/类
@VisibleForTesting
BuckEventBus(Clock clock,
ExecutorService executorService,
BuildId buildId,
int shutdownTimeoutMillis) {
this.clock = Preconditions.checkNotNull(clock);
this.executorService = Preconditions.checkNotNull(executorService);
this.eventBus = new AsyncEventBus("buck-build-events", executorService);
this.threadIdSupplier = DEFAULT_THREAD_ID_SUPPLIER;
this.buildId = Preconditions.checkNotNull(buildId);
this.shutdownTimeoutMillis = shutdownTimeoutMillis;
}
示例15: newAsyncEventBus
import com.google.common.eventbus.AsyncEventBus; //导入依赖的package包/类
/**
* Creates a new asynchronous event bus.
*
* @return Async event bus
*/
private EventBus newAsyncEventBus() {
if (EnvironmentUtil.isUnitTest()) {
return new EventBus();
} else {
ThreadPoolExecutor executor = new ThreadPoolExecutor(1, 1,
0L, TimeUnit.MILLISECONDS,
new LinkedBlockingQueue<Runnable>());
asyncExecutorList.add(executor);
return new AsyncEventBus(executor);
}
}