当前位置: 首页>>代码示例>>Java>>正文


Java AsyncEventBus类代码示例

本文整理汇总了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));
}
 
开发者ID:andreschaffer,项目名称:event-sourcing-cqrs-examples,代码行数:25,代码来源:BankServiceApplication.java

示例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;
}
 
开发者ID:PacktPublishing,项目名称:Mastering-Mesos,代码行数:18,代码来源:PubsubEventModule.java

示例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();
}
 
开发者ID:elastisys,项目名称:scale.commons,代码行数:18,代码来源:SmtpAlerterLab.java

示例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();
}
 
开发者ID:elastisys,项目名称:scale.commons,代码行数:18,代码来源:HttpAlerterLab.java

示例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);
                }
            });
        }
    });
}
 
开发者ID:rridgley1,项目名称:agon,代码行数:22,代码来源:AgonModule.java

示例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;
}
 
开发者ID:elastisys,项目名称:scale.cloudpool,代码行数:29,代码来源:KubernetesCloudPool.java

示例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);
}
 
开发者ID:OasisDigital,项目名称:nges,代码行数:8,代码来源:AbstractMessageGroup.java

示例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);
//		}
	}
 
开发者ID:sjclemen,项目名称:peten,代码行数:8,代码来源:BackendListenableFutureTask.java

示例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);
            }
          });
}
 
开发者ID:mopemope,项目名称:meghanada-server,代码行数:14,代码来源:SessionEventBus.java

示例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);
}
 
开发者ID:OTBProject,项目名称:OTBProject,代码行数:14,代码来源:AbstractBot.java

示例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;
}
 
开发者ID:opendata-euskadi,项目名称:r01fb,代码行数:8,代码来源:AsyncEventBusProvider.java

示例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;
}
 
开发者ID:zalando-stups,项目名称:booties,代码行数:8,代码来源:EventBusSubscriberBeanPostProcessor.java

示例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;
}
 
开发者ID:elastisys,项目名称:scale.cloudpool,代码行数:12,代码来源:GoogleContainerEngineCloudPool.java

示例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;
}
 
开发者ID:saleehk,项目名称:buck-cutom,代码行数:13,代码来源:BuckEventBus.java

示例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);
    }
}
 
开发者ID:sismics,项目名称:books,代码行数:17,代码来源:AppContext.java


注:本文中的com.google.common.eventbus.AsyncEventBus类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。