當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。