下面列出了org.springframework.context.ApplicationContextAware#org.springframework.context.ApplicationEventPublisher 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
public SqsMessageQueueReceiverEndpoint(final @Nonnull String channelName,
final @Nonnull MessageInterceptorRegistry interceptorRegistry,
final @Nonnull SqsAsyncClient sqsAsyncClient,
final @Nonnull ExecutorService executorService,
final @Nullable ApplicationEventPublisher eventPublisher) {
super(channelName, interceptorRegistry, eventPublisher);
this.sqsAsyncClient = sqsAsyncClient;
this.executorService = executorService;
try {
this.queueUrl = sqsAsyncClient.getQueueUrl(GetQueueUrlRequest
.builder()
.queueName(channelName)
.overrideConfiguration(AwsRequestOverrideConfiguration.builder()
.apiCallAttemptTimeout(ofMillis(2000))
.build())
.build())
.get()
.queueUrl();
} catch (Exception e) {
stopped.complete(null);
throw new RuntimeException(e.getMessage(), e);
}
}
public BackupServiceImpl(AttachmentService attachmentService, CategoryService categoryService, CommentBlackListService commentBlackListService, JournalService journalService, JournalCommentService journalCommentService, LinkService linkService, LogService logService, MenuService menuService, OptionService optionService, PhotoService photoService, PostService postService, PostCategoryService postCategoryService, PostCommentService postCommentService, PostMetaService postMetaService, PostTagService postTagService, SheetService sheetService, SheetCommentService sheetCommentService, SheetMetaService sheetMetaService, TagService tagService, ThemeSettingService themeSettingService, UserService userService, OneTimeTokenService oneTimeTokenService, HaloProperties haloProperties, ApplicationEventPublisher eventPublisher) {
this.attachmentService = attachmentService;
this.categoryService = categoryService;
this.commentBlackListService = commentBlackListService;
this.journalService = journalService;
this.journalCommentService = journalCommentService;
this.linkService = linkService;
this.logService = logService;
this.menuService = menuService;
this.optionService = optionService;
this.photoService = photoService;
this.postService = postService;
this.postCategoryService = postCategoryService;
this.postCommentService = postCommentService;
this.postMetaService = postMetaService;
this.postTagService = postTagService;
this.sheetService = sheetService;
this.sheetCommentService = sheetCommentService;
this.sheetMetaService = sheetMetaService;
this.tagService = tagService;
this.themeSettingService = themeSettingService;
this.userService = userService;
this.oneTimeTokenService = oneTimeTokenService;
this.haloProperties = haloProperties;
this.eventPublisher = eventPublisher;
}
@Bean(destroyMethod = "shutdown")
public DefaultDecodedClientMessageHandler defaultDecodedClientMessageHandler(MessageHandler handler,
DeviceMessageConnector messageConnector,
DeviceSessionManager deviceSessionManager,
ApplicationEventPublisher eventPublisher) {
DefaultDecodedClientMessageHandler clientMessageHandler = new DefaultDecodedClientMessageHandler(handler, deviceSessionManager,
EmitterProcessor.create(false)
);
// TODO: 2019/12/31 应该统一由消息网关处理
clientMessageHandler
.subscribe()
.parallel()
.runOn(Schedulers.parallel())
.flatMap(msg -> messageConnector.onMessage(msg).onErrorContinue((err, r) -> log.error(err.getMessage(), err)))
.subscribe();
return clientMessageHandler;
}
@Test
public void shouldWriteConfigurationFile() throws IOException {
new ObjectMapper().writeValue(rewritableJoalFoldersPath.getConfPath().resolve("config.json").toFile(), defaultConfig);
try {
final JoalConfigProvider provider = new JoalConfigProvider(new ObjectMapper(), rewritableJoalFoldersPath, Mockito.mock(ApplicationEventPublisher.class));
final Random rand = new Random();
final AppConfiguration newConf = new AppConfiguration(
rand.longs(1, 200).findFirst().getAsLong(),
rand.longs(201, 400).findFirst().getAsLong(),
rand.ints(1, 5).findFirst().getAsInt(),
RandomStringUtils.random(60),
false
);
provider.saveNewConf(newConf);
assertThat(provider.loadConfiguration()).isEqualTo(newConf);
} finally {
Files.deleteIfExists(rewritableJoalFoldersPath.getConfPath().resolve("config.json"));
}
}
JobService(final JobRepository jobRepository,
final JobMetaService jobMetaService,
final List<JobRunnable> jobRunnables,
final ScheduledExecutorService executor,
final ApplicationEventPublisher applicationEventPublisher,
final Clock clock,
final SystemInfo systemInfo,
final UuidProvider uuidProvider) {
this.jobRepository = jobRepository;
this.jobMetaService = jobMetaService;
this.jobRunnables = jobRunnables;
this.executor = executor;
this.applicationEventPublisher = applicationEventPublisher;
this.clock = clock;
this.systemInfo = systemInfo;
this.uuidProvider = uuidProvider;
}
@Autowired
public AttendanceUploadService(
AttendanceUploadAdapter attendanceUploadAdapter,
AttendanceService attendanceService, ApplicationEventPublisher eventPublisher) {
this.attendanceUploadAdapter = attendanceUploadAdapter;
this.attendanceService = attendanceService;
this.eventPublisher = eventPublisher;
}
@Autowired
public EventSourcingServiceImpl(
EventStoreRepository eventStore,
EventSerializer eventSerializer,
ApplicationEventPublisher eventPublisher
) {
this.eventStoreRepository = eventStore;
this.eventSerializer = eventSerializer;
}
public List listForCriteria() {
Datastore datastore = session.getDatastore();
ApplicationEventPublisher publisher = datastore.getApplicationEventPublisher();
if(publisher != null) {
publisher.publishEvent(new PreQueryEvent(datastore, this));
}
List results = criteria.list();
if(publisher != null) {
publisher.publishEvent(new PostQueryEvent(datastore, this, results));
}
return results;
}
public ReleaseController(
final ReleaseService releaseService,
final ApplicationEventPublisher publisher,
final PortalConfig portalConfig,
final PermissionValidator permissionValidator,
final UserInfoHolder userInfoHolder) {
this.releaseService = releaseService;
this.publisher = publisher;
this.portalConfig = portalConfig;
this.permissionValidator = permissionValidator;
this.userInfoHolder = userInfoHolder;
}
public BaseCommentServiceImpl(BaseCommentRepository<COMMENT> baseCommentRepository,
OptionService optionService,
UserService userService, ApplicationEventPublisher eventPublisher) {
super(baseCommentRepository);
this.baseCommentRepository = baseCommentRepository;
this.optionService = optionService;
this.userService = userService;
this.eventPublisher = eventPublisher;
}
@Autowired
public HtmlReportsEraserScheduler(MetadataRepository metadataRepository, ExecutionStateRepository stateRepository,
ApplicationEventPublisher publisher) {
this.metadataRepository = metadataRepository;
this.stateRepository = stateRepository;
this.publisher = publisher;
daysToKeep = Configuration.INSTANCE.readInt(ConfigProps.DAYS_TO_KEEP_HTML_REPORTS);
if (daysToKeep > 0) {
enabled = true;
} else {
log.debug("Html reports eraser is disabled");
}
}
public NamespaceBranchController(
final PermissionValidator permissionValidator,
final ReleaseService releaseService,
final NamespaceBranchService namespaceBranchService,
final ApplicationEventPublisher publisher,
final PortalConfig portalConfig) {
this.permissionValidator = permissionValidator;
this.releaseService = releaseService;
this.namespaceBranchService = namespaceBranchService;
this.publisher = publisher;
this.portalConfig = portalConfig;
}
@SuppressWarnings({"unchecked", "ResultOfMethodCallIgnored"})
@Test
public void shouldRemoveAnnouncerFromRunningListOnTooManyFailsAndEnqueueAnother() {
final AppConfiguration appConfiguration = this.createMockedConf();
doReturn(1).when(appConfiguration).getSimultaneousSeed();
final TorrentFileProvider torrentFileProvider = createMockedTorrentFileProviderWithTorrent(Lists.newArrayList(
MockedTorrentTest.createOneMock("abc"),
MockedTorrentTest.createOneMock("def")
));
final DelayQueue<AnnounceRequest> delayQueue = mock(DelayQueue.class);
final AnnouncerFactory mockedAnnouncerFactory = createMockedAnnouncerFactory();
final Client client = (Client) ClientBuilder.builder()
.withAnnouncerFactory(mockedAnnouncerFactory)
.withBandwidthDispatcher(mock(BandwidthDispatcher.class))
.withAppConfiguration(appConfiguration)
.withTorrentFileProvider(torrentFileProvider)
.withEventPublisher(mock(ApplicationEventPublisher.class))
.withDelayQueue(delayQueue)
.build();
final AnnouncerExecutor announcerExecutor = mock(AnnouncerExecutor.class);
client.setAnnouncerExecutor(announcerExecutor);
final ArgumentCaptor<AnnounceRequest> argumentCaptor = ArgumentCaptor.forClass(AnnounceRequest.class);
client.start();
verify(delayQueue, times(1)).addOrReplace(argumentCaptor.capture(), anyInt(), any(TemporalUnit.class));
assertThat(client.getCurrentlySeedingAnnouncer()).hasSize(1);
final Announcer firstAnnouncer = argumentCaptor.getValue().getAnnouncer();
client.onTooManyFailedInARaw(firstAnnouncer);
verify(torrentFileProvider, times(1)).moveToArchiveFolder(eq(firstAnnouncer.getTorrentInfoHash()));
verify(delayQueue, times(2)).addOrReplace(argumentCaptor.capture(), anyInt(), any(TemporalUnit.class));
assertThat(argumentCaptor.getValue().getInfoHash()).isNotEqualTo(firstAnnouncer.getTorrentInfoHash());
assertThat(argumentCaptor.getValue().getInfoHash().value()).isEqualTo("def");
assertThat(client.getCurrentlySeedingAnnouncer()).hasSize(1);
}
@Bean( "org.hisp.dhis.pushanalysis.PushAnalysisStore" )
public HibernateIdentifiableObjectStore<PushAnalysis> indicatorTypeStore( SessionFactory sessionFactory,
JdbcTemplate jdbcTemplate, ApplicationEventPublisher publisher, CurrentUserService currentUserService,
AclService aclService )
{
return new HibernateIdentifiableObjectStore<PushAnalysis>( sessionFactory,
jdbcTemplate, publisher, PushAnalysis.class, currentUserService, aclService, false );
}
public HibernateDataApprovalAuditStore( SessionFactory sessionFactory, JdbcTemplate jdbcTemplate,
ApplicationEventPublisher publisher, CurrentUserService currentUserService )
{
super( sessionFactory, jdbcTemplate, publisher, DataApprovalAudit.class, false );
checkNotNull( currentUserService );
this.currentUserService = currentUserService;
}
public HibernateMinMaxDataElementStore( SessionFactory sessionFactory, JdbcTemplate jdbcTemplate,
ApplicationEventPublisher publisher, QueryParser queryParser, QueryPlanner queryPlanner, SchemaService schemaService )
{
super( sessionFactory, jdbcTemplate, publisher, MinMaxDataElement.class, false );
checkNotNull(queryParser);
checkNotNull(queryPlanner);
checkNotNull(schemaService);
this.queryParser = queryParser;
this.queryPlanner = queryPlanner;
this.schemaService = schemaService;
}
@Autowired
public RelationLayerSupport(FeatureSupportRegistry aFeatureSupportRegistry,
ApplicationEventPublisher aEventPublisher,
LayerBehaviorRegistry aLayerBehaviorsRegistry)
{
super(aFeatureSupportRegistry);
eventPublisher = aEventPublisher;
layerBehaviorsRegistry = aLayerBehaviorsRegistry;
}
@Autowired
public TkTask(
TkService tkService,
ApplicationEventPublisher publisher) {
this.tkService = tkService;
this.publisher = publisher;
}
@Override
public void init(ServiceProviderBuilder builder) throws Exception {
authenticationManager = builder.getSharedObject(AuthenticationManager.class);
config = builder.getSharedObject(SAMLSSOProperties.class);
endpoints = builder.getSharedObject(ServiceProviderEndpoints.class);
if ( config.isEnableEventPublisher() )
eventPublisher = builder.getSharedObject(ApplicationEventPublisher.class);
else eventPublisher = null;
}
@SuppressWarnings({"ResultOfMethodCallIgnored", "unchecked"})
@Test
public void shouldClearDelayQueueOnStopAndSendStopAnnounceToExecutor() throws AnnounceException, TooMuchAnnouncesFailedInARawException {
final AppConfiguration appConfiguration = this.createMockedConf();
doReturn(1).when(appConfiguration).getSimultaneousSeed();
final TorrentFileProvider torrentFileProvider = createMockedTorrentFileProviderWithTorrent(Lists.newArrayList(
MockedTorrentTest.createOneMock("abc")
));
final DelayQueue<AnnounceRequest> delayQueue = mock(DelayQueue.class);
doReturn(Lists.newArrayList(AnnounceRequest.createRegular(null))).when(delayQueue).drainAll();
final AnnouncerFactory mockedAnnouncerFactory = mock(AnnouncerFactory.class);
final Client client = (Client) ClientBuilder.builder()
.withAnnouncerFactory(mockedAnnouncerFactory)
.withBandwidthDispatcher(mock(BandwidthDispatcher.class))
.withAppConfiguration(appConfiguration)
.withTorrentFileProvider(torrentFileProvider)
.withEventPublisher(mock(ApplicationEventPublisher.class))
.withDelayQueue(delayQueue)
.build();
final AnnouncerExecutor announcerExecutor = mock(AnnouncerExecutor.class);
client.setAnnouncerExecutor(announcerExecutor);
client.start();
verify(delayQueue, times(1)).addOrReplace(any(AnnounceRequest.class), anyInt(), any(TemporalUnit.class));
Thread.yield();
client.stop();
verify(delayQueue, times(1)).drainAll();
verify(announcerExecutor, times(1)).execute(argThat(new ArgumentMatcher<AnnounceRequest>() {
@Override
public boolean matches(final AnnounceRequest argument) {
return argument.getEvent() == RequestEvent.STOPPED;
}
}));
}
public CloudEurekaClient(ApplicationInfoManager applicationInfoManager,
EurekaClientConfig config, AbstractDiscoveryClientOptionalArgs<?> args,
ApplicationEventPublisher publisher) {
super(applicationInfoManager, config, args);
this.applicationInfoManager = applicationInfoManager;
this.publisher = publisher;
this.eurekaTransportField = ReflectionUtils.findField(DiscoveryClient.class,
"eurekaTransport");
ReflectionUtils.makeAccessible(this.eurekaTransportField);
}
protected ArangoExtCursor(final InternalArangoDatabase<?, ?> db, final ArangoCursorExecute execute,
final Class<T> type, final CursorEntity result, final ArangoConverter converter,
final ApplicationEventPublisher eventPublisher) {
super(db, execute, type, result);
final ArangoExtCursorIterator<?> it = (ArangoExtCursorIterator<?>) iterator;
it.setConverter(converter);
it.setEventPublisher(eventPublisher);
}
public EurekaStatusSubscriber(
ApplicationEventPublisher publisher, EventBus eventBus, DiscoveryClient discoveryClient) {
this.publisher = Objects.requireNonNull(publisher, "publisher");
this.eventBus = Objects.requireNonNull(eventBus, "eventBus");
publish(
new StatusChangeEvent(
InstanceInfo.InstanceStatus.UNKNOWN, discoveryClient.getInstanceRemoteStatus()));
try {
eventBus.registerSubscriber(this);
} catch (InvalidSubscriberException ise) {
throw new SystemException(ise);
}
}
@Autowired(required = false)
public AppAuthServiceImpl(final AppAuthMapper appAuthMapper,
final ApplicationEventPublisher eventPublisher,
final AuthParamMapper authParamMapper,
final AuthPathMapper authPathMapper) {
this.appAuthMapper = appAuthMapper;
this.eventPublisher = eventPublisher;
this.authParamMapper = authParamMapper;
this.authPathMapper = authPathMapper;
}
@Autowired
public EventPublishingEntityListenerAdapter(EntityManager eventRepository, ApplicationEventPublisher eventPublisher,
ObjectMapper objectMapper) {
this.eventRepository = eventRepository;
this.eventPublisher = eventPublisher;
this.objectMapper = objectMapper;
}
@Test
public void watchPublishesEvent() {
ApplicationEventPublisher eventPublisher = mock(ApplicationEventPublisher.class);
setupWatch(eventPublisher, "/app/");
verify(eventPublisher, times(1)).publishEvent(ArgumentMatchers.any(RefreshEvent.class));
}
public AdminServiceImpl(PostService postService,
SheetService sheetService,
AttachmentService attachmentService,
PostCommentService postCommentService,
SheetCommentService sheetCommentService,
JournalCommentService journalCommentService,
OptionService optionService,
UserService userService,
LinkService linkService,
MailService mailService,
AbstractStringCacheStore cacheStore,
RestTemplate restTemplate,
HaloProperties haloProperties,
ApplicationEventPublisher eventPublisher) {
this.postService = postService;
this.sheetService = sheetService;
this.attachmentService = attachmentService;
this.postCommentService = postCommentService;
this.sheetCommentService = sheetCommentService;
this.journalCommentService = journalCommentService;
this.optionService = optionService;
this.userService = userService;
this.linkService = linkService;
this.mailService = mailService;
this.cacheStore = cacheStore;
this.restTemplate = restTemplate;
this.haloProperties = haloProperties;
this.eventPublisher = eventPublisher;
}
public TelemetryServiceImpl(
@Lazy @Autowired(required = false) List<TelemetrySupport> aTelemetrySupports,
ApplicationEventPublisher aEventPublisher)
{
telemetrySupportsProxy = aTelemetrySupports;
eventPublisher = aEventPublisher;
}
private void setupWatchThrowException(ApplicationEventPublisher eventPublisher, String context) {
ConsulClient consul = mock(ConsulClient.class);
OperationException operationException = new OperationException(403, null, null);
when(consul.getKVValues(ArgumentMatchers.eq(context), nullable(String.class),
ArgumentMatchers.any(QueryParams.class))).thenThrow(operationException);
LinkedHashMap<String, Long> initialIndexes = new LinkedHashMap<>();
initialIndexes.put(context, 0L);
startWatch(eventPublisher, consul, initialIndexes);
}
public SecurityService(JPAQueryFactory jpaQueryFactory,
PasswordEncoder passwordEncoder, MailService mailService,
ApplicationEventPublisher applicationEventPublisher) {
this.jpaQueryFactory = jpaQueryFactory;
this.passwordEncoder = passwordEncoder;
this.mailService = mailService;
this.applicationEventPublisher = applicationEventPublisher;
}