com.google.common.eventbus.AsyncEventBus Java Examples
The following examples show how to use
com.google.common.eventbus.AsyncEventBus.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: EventControllerFactory.java From BootNettyRpc with Apache License 2.0 | 6 votes |
public static EventController get(String identifier, EventControllerType type) { switch (type) { case SYN: EventController synController = SYN_EVENT_CONTROLLER.get( identifier ); if (synController == null) { synController = new EventControllerImpl( new EventBus( identifier ) ); SYN_EVENT_CONTROLLER.putIfAbsent( identifier, synController ); } return synController; case ASYN: EventController asynController = ASYNC_EVENT_CONTROLLER.get( identifier ); if (asynController == null) { asynController = new EventControllerImpl( new AsyncEventBus( identifier, ThreadPoolFactory.createThreadPoolDefaultExecutor() ) ); ASYNC_EVENT_CONTROLLER.putIfAbsent( identifier, asynController ); } return asynController; } return null; }
Example #2
Source File: Executor.java From meghanada-server with GNU General Public License v3.0 | 6 votes |
private Executor() { this.executorService = getExecutorService(); this.eventBus = new AsyncEventBus( executorService, (throwable, subscriberExceptionContext) -> { if (!(throwable instanceof RejectedExecutionException)) { log.catching(throwable); } }); Runtime.getRuntime() .addShutdownHook( new Thread( () -> { try { shutdown(1); } catch (Throwable t) { // log.catching(t); } })); }
Example #3
Source File: DefaultAsyncEventBus.java From j360-dubbo-app-all with Apache License 2.0 | 6 votes |
public DefaultAsyncEventBus() { this.blockingQueue = new LinkedBlockingQueue<>(1000); this.executor = new ThreadPoolExecutor(30, 100, 3, TimeUnit.SECONDS, blockingQueue, ThreadPoolUtil.buildThreadFactory("DefaultAsyncEventBus", true), new ThreadPoolExecutor.AbortPolicy()); this.eventBus = new AsyncEventBus(executor, new SubscriberExceptionHandler() { @Override public void handleException(Throwable exception, SubscriberExceptionContext context) { log.error("异步消息队列异常: [subscribeMethod={}, event={} ]",context.getSubscriberMethod(), context.getEvent().toString(),exception); } }); }
Example #4
Source File: StyxServerComponents.java From styx with Apache License 2.0 | 6 votes |
private static Environment newEnvironment(StyxConfig config, MetricRegistry metricRegistry) { SanitisedHttpHeaderFormatter headerFormatter = new SanitisedHttpHeaderFormatter( config.get("request-logging.hideHeaders", List.class).orElse(emptyList()), config.get("request-logging.hideCookies", List.class).orElse(emptyList())); SanitisedHttpMessageFormatter sanitisedHttpMessageFormatter = new SanitisedHttpMessageFormatter(headerFormatter); return new Environment.Builder() .configuration(config) .metricRegistry(metricRegistry) .buildInfo(readBuildInfo()) .eventBus(new AsyncEventBus("styx", newSingleThreadExecutor())) .httpMessageFormatter(sanitisedHttpMessageFormatter) .build(); }
Example #5
Source File: BankServiceApplication.java From event-sourcing-cqrs-examples with MIT License | 6 votes |
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)); }
Example #6
Source File: ListingConnector.java From connector-sdk with Apache License 2.0 | 5 votes |
@Override public void init(IndexingConnectorContext context) throws Exception { checkState(Configuration.isInitialized(), "configuration not initialized"); exceptionHandler = TraverseExceptionHandlerFactory.createFromConfig(); indexingService = checkNotNull(context.getIndexingService()); for (String traverseName : traverserConfigKey.get()) { context.registerTraverser( new TraverserConfiguration.Builder(traverseName).itemRetriever(this).build()); } defaultAcl = DefaultAcl.fromConfiguration(indexingService); threadPoolExecutor = new ThreadPoolExecutor( DEFAULT_THREAD_NUM, DEFAULT_THREAD_NUM, 0, TimeUnit.MILLISECONDS, new ArrayBlockingQueue<Runnable>(10 * DEFAULT_THREAD_NUM), new ThreadPoolExecutor.CallerRunsPolicy()); listeningExecutorService = MoreExecutors.listeningDecorator(threadPoolExecutor); repositoryContext = new RepositoryContext.Builder() .setEventBus( new AsyncEventBus( "EventBus-" + ListingConnector.class.getName(), listeningExecutorService)) .setDefaultAclMode(defaultAcl.getDefaultAclMode()) .build(); if (checkpointHandler == null) { checkpointHandler = LocalFileCheckpointHandler.fromConfiguration(); } repositoryContext.getEventBus().register(this); repository.init(repositoryContext); }
Example #7
Source File: PubsubEventModule.java From attic-aurora with Apache License 2.0 | 5 votes |
@Provides @RegisteredEvents @Singleton EventBus provideRegisteredEventBus(SubscriberExceptionHandler subscriberExceptionHandler, @DeadEventHandler Object deadEventHandler) { EventBus eventBus = new AsyncEventBus(registeredExecutor, subscriberExceptionHandler); eventBus.register(deadEventHandler); return eventBus; }
Example #8
Source File: PubsubEventModule.java From attic-aurora with Apache License 2.0 | 5 votes |
@Provides @Singleton EventBus provideEventBus(@AsyncExecutor Executor executor, SubscriberExceptionHandler subscriberExceptionHandler, @DeadEventHandler Object deadEventHandler) { EventBus eventBus = new AsyncEventBus(executor, subscriberExceptionHandler); eventBus.register(deadEventHandler); return eventBus; }
Example #9
Source File: EventBusSubscriberBeanPostProcessor.java From booties with Apache License 2.0 | 5 votes |
@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; }
Example #10
Source File: SchedulerMonitor.java From jeesuite-libs with Apache License 2.0 | 5 votes |
public SchedulerMonitor(String registryType, String servers) { if("zookeeper".equals(registryType)) { ZkConnection zkConnection = new ZkConnection(servers); zkClient = new ZkClient(zkConnection, 3000); }else{ asyncEventBus = new AsyncEventBus(JobContext.getContext().getSyncExecutor()); asyncEventBus.register(JobContext.getContext().getRegistry()); } }
Example #11
Source File: DefaultAsyncEventBus.java From j360-dubbo-app-all with Apache License 2.0 | 5 votes |
public DefaultAsyncEventBus() { this.blockingQueue = new LinkedBlockingQueue<>(1000); this.executor = new ThreadPoolExecutor(30, 100, 3, TimeUnit.SECONDS, blockingQueue, ThreadPoolUtil.buildThreadFactory("DefaultAsyncEventBus", true), new ThreadPoolExecutor.AbortPolicy()); this.eventBus = new AsyncEventBus(executor, new SubscriberExceptionHandler() { @Override public void handleException(Throwable exception, SubscriberExceptionContext context) { log.error("异步消息队列异常: [subscribeMethod={}, event={} ]",context.getSubscriberMethod(), context.getEvent().toString(),exception); } }); }
Example #12
Source File: AsyncTaskProduceClient.java From oneplatform with Apache License 2.0 | 5 votes |
private AsyncTaskProduceClient() { try { topicProducer = InstanceFactory.getInstance(TopicProducerSpringProvider.class); } catch (Exception e) {} if(topicProducer == null){ executorService = Executors.newFixedThreadPool(2,new StandardThreadFactory("async-event-executor")); asyncEventBus = new AsyncEventBus(executorService); Collection<MessageHandler> handlers = InstanceFactory.getInstanceProvider().getInterfaces(MessageHandler.class).values(); for (MessageHandler messageHandler : handlers) { asyncEventBus.register(messageHandler); } } }
Example #13
Source File: BeaconNode.java From teku with Apache License 2.0 | 5 votes |
public BeaconNode(final TekuConfiguration config) { LoggingConfigurator.update( new LoggingConfiguration( config.isLogColorEnabled(), config.isLogIncludeEventsEnabled(), config.isLogIncludeValidatorDutiesEnabled(), config.getLogDestination(), config.getLogFile(), config.getLogFileNamePattern())); STATUS_LOG.onStartup(VersionProvider.VERSION); this.metricsEndpoint = new MetricsEndpoint(config, vertx); final MetricsSystem metricsSystem = metricsEndpoint.getMetricsSystem(); final TekuDefaultExceptionHandler subscriberExceptionHandler = new TekuDefaultExceptionHandler(); this.eventChannels = new EventChannels(subscriberExceptionHandler, metricsSystem); final EventBus eventBus = new AsyncEventBus(threadPool, subscriberExceptionHandler); final ServiceConfig serviceConfig = new ServiceConfig( asyncRunnerFactory, new SystemTimeProvider(), eventBus, eventChannels, metricsSystem, config); serviceConfig.getConfig().validateConfig(); Constants.setConstants(config.getConstants()); final String transitionRecordDir = config.getTransitionRecordDirectory(); if (transitionRecordDir != null) { SSZTransitionRecorder sszTransitionRecorder = new SSZTransitionRecorder(Path.of(transitionRecordDir)); eventBus.register(sszTransitionRecorder); } this.serviceController = new ServiceController(serviceConfig); STATUS_LOG.dataPathSet(serviceConfig.getConfig().getDataPath()); }
Example #14
Source File: TekuDefaultExceptionHandlerTest.java From teku with Apache License 2.0 | 5 votes |
@BeforeEach void setupBus() { lenient() .doAnswer( invocation -> { handledException.complete(invocation.getArgument(1)); logLevelFuture.complete(Level.WARN); return null; }) .when(log) .specificationFailure(anyString(), any(Exception.class)); lenient() .doAnswer( invocation -> { handledException.complete(invocation.getArgument(1)); logLevelFuture.complete(Level.FATAL); return null; }) .when(log) .unexpectedFailure(anyString(), any(Exception.class)); final var exceptionHandlerRecordingWrapper = new SubscriberExceptionHandler() { private final SubscriberExceptionHandler delegate = new TekuDefaultExceptionHandler(log); @Override public void handleException( final Throwable exception, final SubscriberExceptionContext context) { try { delegate.handleException(exception, context); } catch (final RuntimeException thrown) { unhandledExceptionFuture.complete(thrown); throw thrown; } } }; bus = new AsyncEventBus(executor, exceptionHandlerRecordingWrapper); }
Example #15
Source File: GuavaCommandBus.java From bookstore-cqrs-example with Apache License 2.0 | 4 votes |
public static CommandBus asyncGuavaCommandBus() { ExecutorService executorService = Executors.newFixedThreadPool(1); return new GuavaCommandBus(new AsyncEventBus("commandbus", executorService)); }
Example #16
Source File: SimpleAsyncEventSender.java From booties with Apache License 2.0 | 4 votes |
@Autowired public SimpleAsyncEventSender(final AsyncEventBus asyncEventSender) { this.asyncEventBus = asyncEventSender; }
Example #17
Source File: MultiEventBusSender.java From booties with Apache License 2.0 | 4 votes |
@Autowired public MultiEventBusSender(final AsyncEventBus asyncEventBus, final EventBus eventBus) { this.asyncEventBus = asyncEventBus; this.eventBus = eventBus; }
Example #18
Source File: OpcUaServer.java From ua-server-sdk with GNU Affero General Public License v3.0 | 4 votes |
public OpcUaServer(OpcUaServerConfig config) { this.config = config; stackServer = new UaTcpStackServer(config); stackServer.addServiceSet((AttributeServiceSet) sessionManager); stackServer.addServiceSet((MethodServiceSet) sessionManager); stackServer.addServiceSet((MonitoredItemServiceSet) sessionManager); stackServer.addServiceSet((NodeManagementServiceSet) sessionManager); stackServer.addServiceSet((SessionServiceSet) sessionManager); stackServer.addServiceSet((SubscriptionServiceSet) sessionManager); stackServer.addServiceSet((ViewServiceSet) sessionManager); namespaceManager.addNamespace(uaNamespace = new OpcUaNamespace(this)); vendorNamespace = namespaceManager.registerAndAdd( config.getApplicationUri(), index -> new VendorNamespace(OpcUaServer.this, config.getApplicationUri())); serverTable.addUri(stackServer.getApplicationDescription().getApplicationUri()); for (ReferenceType referenceType : BuiltinReferenceType.values()) { referenceTypes.put(referenceType.getNodeId(), referenceType); } String configuredHostname = config.getHostname(); for (String bindAddress : config.getBindAddresses()) { Set<String> hostnames = Sets.union( newHashSet(configuredHostname), getHostnames(bindAddress)); for (String hostname : hostnames) { for (SecurityPolicy securityPolicy : config.getSecurityPolicies()) { MessageSecurityMode messageSecurity = securityPolicy == SecurityPolicy.None ? MessageSecurityMode.None : MessageSecurityMode.SignAndEncrypt; String endpointUrl = endpointUrl(hostname, config.getBindPort(), config.getServerName()); Set<X509Certificate> certificates = config.getCertificateManager().getCertificates(); if (certificates.isEmpty() && securityPolicy == SecurityPolicy.None) { logger.info("Binding endpoint {} to {} [{}/{}]", endpointUrl, bindAddress, securityPolicy, messageSecurity); stackServer.addEndpoint(endpointUrl, bindAddress, null, securityPolicy, messageSecurity); } else { for (X509Certificate certificate : certificates) { logger.info("Binding endpoint {} to {} [{}/{}]", endpointUrl, bindAddress, securityPolicy, messageSecurity); stackServer.addEndpoint(endpointUrl, bindAddress, certificate, securityPolicy, messageSecurity); } } } } } eventBus = new AsyncEventBus("server", stackServer.getExecutorService()); logger.info("digitalpetri opc-ua stack version: {}", Stack.VERSION); logger.info("digitalpetri opc-ua sdk version: {}", SDK_VERSION); }
Example #19
Source File: ManagedEventBus.java From jesos with Apache License 2.0 | 4 votes |
public ManagedEventBus(final String name) { checkNotNull(name, "name is null"); this.executor = Executors.newScheduledThreadPool(10, new ThreadFactoryBuilder().setDaemon(true).setNameFormat("eventbus-" + name + "-%d").build()); this.eventBus = new AsyncEventBus(executor, new EventBusExceptionHandler(name)); }
Example #20
Source File: TestGenericSubscribe.java From kamike.divide with GNU Lesser General Public License v3.0 | 4 votes |
public TestGenericSubscribe(AsyncEventBus asyncEventBus) { asyncEventBus.register(this); }
Example #21
Source File: EventInst.java From kamike.divide with GNU Lesser General Public License v3.0 | 4 votes |
private EventInst() { eventBus=new EventBus(); asyncEventBus = new AsyncEventBus(Executors.newFixedThreadPool(20)); }
Example #22
Source File: EventInst.java From kamike.divide with GNU Lesser General Public License v3.0 | 4 votes |
/** * @return the eventBus */ public AsyncEventBus getAsyncEventBus() { return asyncEventBus; }
Example #23
Source File: EventBusService.java From mangooio with Apache License 2.0 | 4 votes |
public EventBusService() { this.asyncEventBus = new AsyncEventBus(Executors.newCachedThreadPool()); }
Example #24
Source File: GuavaDomainEventBus.java From bookstore-cqrs-example with Apache License 2.0 | 4 votes |
public GuavaDomainEventBus() { ExecutorService executorService = Executors.newFixedThreadPool(1); eventBus = new AsyncEventBus("eventbus", executorService); replayBus = new AsyncEventBus("replaybus", executorService); }
Example #25
Source File: GuavaInternalEventBus.java From foxtrot with Apache License 2.0 | 4 votes |
public GuavaInternalEventBus() { eventBus = new AsyncEventBus(Executors.newFixedThreadPool(10)); }
Example #26
Source File: BugEditForm.java From mycollab with GNU Affero General Public License v3.0 | 4 votes |
@Override public AbstractComponent getLayout() { MVerticalLayout layout = new MVerticalLayout().withMargin(false); wrappedLayoutFactory = new DefaultDynaFormLayout(ProjectTypeConstants.BUG, BugDefaultFormLayoutFactory.getAddForm()); AbstractComponent gridLayout = wrappedLayoutFactory.getLayout(); gridLayout.addStyleName(WebThemes.SCROLLABLE_CONTAINER); gridLayout.addStyleName("window-max-height"); MButton saveBtn = new MButton(UserUIContext.getMessage(GenericI18Enum.BUTTON_SAVE), clickEvent -> { if (bean.getStatus() == null) { bean.setStatus(StatusI18nEnum.Open.name()); } if (validateForm()) { BugService bugService = AppContextUtil.getSpringBean(BugService.class); Integer bugId; if (bean.getId() == null) { bugId = bugService.saveWithSession(bean, UserUIContext.getUsername()); } else { bugService.updateWithSession(bean, UserUIContext.getUsername()); bugId = bean.getId(); } AsyncEventBus asyncEventBus = AppContextUtil.getSpringBean(AsyncEventBus.class); // save component BugEditFormFieldFactory bugEditFormFieldFactory = (BugEditFormFieldFactory) fieldFactory; TicketRelationService ticketRelationService = AppContextUtil.getSpringBean(TicketRelationService.class); ticketRelationService.saveAffectedVersionsOfTicket(bugId, ProjectTypeConstants.BUG, bugEditFormFieldFactory.getAffectedVersionSelect().getSelectedItems()); ticketRelationService.saveFixedVersionsOfTicket(bugId, ProjectTypeConstants.BUG, bugEditFormFieldFactory.getFixedVersionSelect().getSelectedItems()); ticketRelationService.saveComponentsOfTicket(bugId, ProjectTypeConstants.BUG, bugEditFormFieldFactory.getComponentSelect().getSelectedItems()); asyncEventBus.post(new CleanCacheEvent(AppUI.getAccountId(), new Class[]{BugService.class})); AttachmentUploadField uploadField = bugEditFormFieldFactory.getAttachmentUploadField(); String attachPath = AttachmentUtils.getProjectEntityAttachmentPath(AppUI.getAccountId(), bean.getProjectid(), ProjectTypeConstants.BUG, "" + bugId); uploadField.saveContentsToRepo(attachPath); EventBusFactory.getInstance().post(new TicketEvent.NewTicketAdded(BugEditForm.this, ProjectTypeConstants.BUG, bugId)); ProjectSubscribersComp subcribersComp = bugEditFormFieldFactory.getSubscribersComp(); List<String> followers = subcribersComp.getFollowers(); if (followers.size() > 0) { List<MonitorItem> monitorItems = new ArrayList<>(); for (String follower : followers) { MonitorItem monitorItem = new MonitorItem(); monitorItem.setSaccountid(AppUI.getAccountId()); monitorItem.setType(ProjectTypeConstants.BUG); monitorItem.setTypeid(bugId + ""); monitorItem.setUsername(follower); monitorItem.setExtratypeid(bean.getProjectid()); monitorItems.add(monitorItem); monitorItem.setCreatedtime(LocalDateTime.now()); } MonitorItemService monitorItemService = AppContextUtil.getSpringBean(MonitorItemService.class); monitorItemService.saveMonitorItems(monitorItems); } postExecution(); } }).withIcon(VaadinIcons.CLIPBOARD).withStyleName(WebThemes.BUTTON_ACTION).withClickShortcut(KeyCode.ENTER); MButton cancelBtn = new MButton(UserUIContext.getMessage(GenericI18Enum.BUTTON_CANCEL), clickEvent -> postExecution()) .withStyleName(WebThemes.BUTTON_OPTION); MCssLayout buttonControls = new MCssLayout(new MHorizontalLayout(cancelBtn, saveBtn).withStyleName(WebThemes.ALIGN_RIGHT) .withMargin(new MarginInfo(true, false, false, false))).withFullWidth().withStyleName(WebThemes.BORDER_TOP); layout.with(gridLayout, buttonControls).expand(gridLayout); return layout; }
Example #27
Source File: AirpalModule.java From airpal with Apache License 2.0 | 4 votes |
@Singleton @Provides public EventBus provideEventBus(@Named("event-bus") ExecutorService executor) { return new AsyncEventBus(executor); }
Example #28
Source File: ChanceryService.java From chancery with Apache License 2.0 | 4 votes |
private EventBus buildCallbackBus(final ChanceryConfig config) { return new AsyncEventBus( Executors.newFixedThreadPool(config.getHandlerThreads()) ); }
Example #29
Source File: AsyncEventBusFactory.java From qconfig with MIT License | 4 votes |
public static AsyncEventBus newAsyncEventBus() { return new AsyncEventBus("async-event", Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors(), new NamedThreadFactory("qconfig-async-event"))); }
Example #30
Source File: JobEventBus.java From mykit-delay with Apache License 2.0 | 4 votes |
private JobEventBus() { bus = new AsyncEventBus(MoreExecutors.newDirectExecutorService()); }