當前位置: 首頁>>代碼示例>>Java>>正文


Java EventListener類代碼示例

本文整理匯總了Java中org.springframework.context.event.EventListener的典型用法代碼示例。如果您正苦於以下問題:Java EventListener類的具體用法?Java EventListener怎麽用?Java EventListener使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


EventListener類屬於org.springframework.context.event包,在下文中一共展示了EventListener類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: start

import org.springframework.context.event.EventListener; //導入依賴的package包/類
/**
 * Start the controller
 */
@EventListener(ApplicationReadyEvent.class)
public void start() {
	log.info("Starting sessions");
	// setup reconnect tasks
	for (final GroupSession group : groups.values()) {
		group.start();
		Runnable reconnectTask = new Runnable() {

			@Override
			public void run() {
				try {
					if (group.isStopped()) {
						group.stop();
						log.info("Attempting to reconnect...");
						group.start();
					}
				} catch (Exception e) {
					log.error(e.getLocalizedMessage());
				}
			}
		};
		Schedule.getInstance().at(reconnectTask, reconnectInterval, true);
	}

}
 
開發者ID:mshaw323,項目名稱:stdds-monitor,代碼行數:29,代碼來源:StatusController.java

示例2: handleUserMessage

import org.springframework.context.event.EventListener; //導入依賴的package包/類
@Async
@EventListener
public void handleUserMessage(UserMessageCreatedEvent event){
    log.info("UserMessageCreatedEvent" );
    
    await( 100L );
    
    ConversationMessage message = event.getMessage();
   
    for(BotAnswer answer : answers){
        if(answer.tryAnswer(message)){
            log.info("Bot answered on message {}" , message.getId());
            break;
        }
    }
}
 
開發者ID:peterjurkovic,項目名稱:travel-agency,代碼行數:17,代碼來源:AgencyBot.java

示例3: simulateComments

import org.springframework.context.event.EventListener; //導入依賴的package包/類
@EventListener
public void simulateComments(ApplicationReadyEvent event) {
	Flux
		.interval(Duration.ofMillis(1000))
		.flatMap(tick -> repository.findAll())
		.map(image -> {
			Comment comment = new Comment();
			comment.setImageId(image.getId());
			comment.setComment(
				"Comment #" + counter.getAndIncrement());
			return Mono.just(comment);
		})
		.flatMap(newComment ->
			Mono.defer(() ->
				commentController.addComment(newComment)))
		.subscribe();
}
 
開發者ID:PacktPublishing,項目名稱:Learning-Spring-Boot-2.0-Second-Edition,代碼行數:18,代碼來源:CommentSimulator.java

示例4: onCommandEvent

import org.springframework.context.event.EventListener; //導入依賴的package包/類
@EventListener
public void onCommandEvent(CommandEvent event) {
    LOGGER.debug("Received event: {}", event);

    final String command = event.getCommand();
    if (!availableCommandNames.contains(command)) {

        final String unknownCommandMessage = String.format("Unkown command received: %s", command);
        LOGGER.debug(unknownCommandMessage);

        try {
            telegramService.sendMessage(unknownCommandMessage);
            telegramService.sendMessage(String.format("Available commands: %s", availableCommandNames));
        } catch (TelegramApiException e) {
            LOGGER.warn("Unable to reply to message", e);
        }
    }

}
 
開發者ID:jeperon,項目名稱:freqtrade-java,代碼行數:20,代碼來源:CommandEventListener.java

示例5: sendDefendantNotification

import org.springframework.context.event.EventListener; //導入依賴的package包/類
@EventListener
public void sendDefendantNotification(CitizenClaimIssuedEvent event) {
    Claim claim = event.getClaim();

    if (!claim.getClaimData().isClaimantRepresented()) {
        claim.getClaimData().getDefendant().getEmail()
            .ifPresent(defendantEmail ->
                claimIssuedNotificationService.sendMail(
                    claim,
                    defendantEmail,
                    event.getPin().orElseThrow(IllegalArgumentException::new),
                    getEmailTemplates().getDefendantClaimIssued(),
                    "defendant-issue-notification-" + claim.getReferenceNumber(),
                    event.getSubmitterName()
                ));
    }
}
 
開發者ID:hmcts,項目名稱:cmc-claim-store,代碼行數:18,代碼來源:ClaimIssuedCitizenActionsHandler.java

示例6: handleConfigurationModifiedEvent

import org.springframework.context.event.EventListener; //導入依賴的package包/類
/**
 * Handle configuration modified event.
 *
 * @param event the event
 */
@EventListener
public void handleConfigurationModifiedEvent(final CasConfigurationModifiedEvent event) {
    if (this.contextRefresher == null) {
        LOGGER.warn("Unable to refresh application context, since no refresher is available");
        return;
    }

    if (event.isEligibleForContextRefresh()) {
        LOGGER.info("Received event [{}]. Refreshing CAS configuration...", event);
        Collection<String> keys = null;
        try {
            keys = this.contextRefresher.refresh();
            LOGGER.debug("Refreshed the following settings: [{}].", keys);
        } catch (final Throwable e) {
            LOGGER.trace(e.getMessage(), e);
        } finally {
            rebind();
            LOGGER.info("CAS finished rebinding configuration with new settings [{}]",
                    ObjectUtils.defaultIfNull(keys, Collections.emptyList()));
        }
    }
}
 
開發者ID:mrluo735,項目名稱:cas-5.1.0,代碼行數:28,代碼來源:CasConfigurationEventListener.java

示例7: init

import org.springframework.context.event.EventListener; //導入依賴的package包/類
@EventListener(value = ContextRefreshedEvent.class)
public void init() {
    log.info("start data initialization  ...");
    this.posts
        .deleteAll()
        .thenMany(

            Flux
                .range(1, 1000)
                .flatMap(
                    num -> this.posts.save(Post.builder().title("Title" + num).content("content of " + "Title" + num).build())
                )
        )
        .log()
        .subscribe(
            null,
            null,
            () -> log.info("done initialization...")
        );

}
 
開發者ID:hantsy,項目名稱:spring-reactive-sample,代碼行數:22,代碼來源:DataInitializer.java

示例8: init

import org.springframework.context.event.EventListener; //導入依賴的package包/類
@EventListener(value = ContextRefreshedEvent.class)
public void init() {
    log.info("start data initialization  ...");
    this.posts
        .deleteAll()
        .thenMany(
            Flux
                .just("Post one", "Post two")
                .flatMap(
                    title -> this.posts.save(Post.builder().title(title).content("content of " + title).build())
                )
        )
        .log()
        .subscribe(
            null,
            null,
            () -> log.info("done initialization...")
        );

}
 
開發者ID:hantsy,項目名稱:spring-reactive-sample,代碼行數:21,代碼來源:DataInitializer.java

示例9: init

import org.springframework.context.event.EventListener; //導入依賴的package包/類
@EventListener(value = ContextRefreshedEvent.class)
public void init() {
    log.info("start data initialization  ...");
    this.posts
        .deleteAll()
        .thenMany(

            Flux
                .range(1, 100)
                .flatMap(
                    num -> this.posts.save(Post.builder().title("Title" + num).content("content of " + "Title" + num).build())
                )
        )
        .log()
        .subscribe(
            null,
            null,
            () -> log.info("done initialization...")
        );

}
 
開發者ID:hantsy,項目名稱:spring-reactive-sample,代碼行數:22,代碼來源:DataInitializer.java

示例10: init

import org.springframework.context.event.EventListener; //導入依賴的package包/類
@EventListener(value = ContextRefreshedEvent.class)
public void init() {
    log.info("start data initialization  ...");
    this.posts
        .deleteAll()
        .thenMany(
            Flux
                .just("Post one", "Post two")
                .flatMap(
                    title -> this.posts.save(Post.builder().id(UUID.randomUUID().toString()).title(title).content("content of " + title).build())
                )
        )
        .log()
        .subscribe(
            null,
            null,
            () -> log.info("done initialization...")
        );

}
 
開發者ID:hantsy,項目名稱:spring-reactive-sample,代碼行數:21,代碼來源:DataInitializer.java

示例11: onApplicationStop

import org.springframework.context.event.EventListener; //導入依賴的package包/類
@EventListener
public void onApplicationStop(ApplicationStopEvent applicationStopEvent) {
	Application application = (Application) applicationStopEvent.getSource();
	try {
		int counter = 0;
		boolean started = false;
		do {
			started = applicationService.isStopped(application.getName());
			Thread.sleep(1000);
		} while (counter++ < 30 && !started);
		if (counter <= 30) {
			application.setStatus(Status.STOP);
		} else {
			application.setStatus(Status.FAIL);
		}
		logger.info("Application status : " + application.getStatus());
		applicationService.saveInDB(application);
	} catch (Exception e) {
		e.printStackTrace();
	}
}
 
開發者ID:oncecloud,項目名稱:devops-cstack,代碼行數:22,代碼來源:ApplicationListener.java

示例12: onModuleStop

import org.springframework.context.event.EventListener; //導入依賴的package包/類
@EventListener
@Async
public void onModuleStop(ModuleStopEvent moduleStopEvent) {
	Module module = (Module) moduleStopEvent.getSource();
	try {
		int counter = 0;
		boolean isStopped = false;
		do {
			isStopped = dockerService.isStoppedGracefully(module.getName());
			Thread.sleep(1000);
		} while (counter++ < 30 && !isStopped);
		if (counter <= 30) {
			module.setStatus(Status.STOP);
		} else {
			module.setStatus(Status.FAIL);
		}
		logger.info("Server status : " + module.getStatus());
		moduleService.update(module);
	} catch (Exception e) {
		logger.error(module.getName(), e);
		e.printStackTrace();
	}
}
 
開發者ID:oncecloud,項目名稱:devops-cstack,代碼行數:24,代碼來源:ModuleListener.java

示例13: contextRefreshedEvent

import org.springframework.context.event.EventListener; //導入依賴的package包/類
/**
 * Run setup when application starts.
 */
@EventListener(ContextRefreshedEvent.class)
public void contextRefreshedEvent() {
    logger.info("Running setup");

    if (userRepository.count() == 0) {
        logger.info("No users have been configured, creating default user");
        User user = new User(defaultUsername,
            defaultPassword,
            Collections.singleton("ROLE_" + WebSecurityConfig.Roles.ADMIN));
        userRepository.save(user);
        logger.info("Created user \"{}\" with password \"{}\". Change this password for security reasons!",
            defaultUsername,
            defaultPassword);
    }

    logger.info("Setup completed");
}
 
開發者ID:BakkerTom,項目名稱:happy-news,代碼行數:21,代碼來源:Setup.java

示例14: onBeforeTokenGrantedEvent

import org.springframework.context.event.EventListener; //導入依賴的package包/類
@EventListener
public void onBeforeTokenGrantedEvent(BeforeTokenGrantedEvent event) {
    Person person = (Person) event.getAuthentication().getPrincipal();
    String firstName = capitalizeFully(person.getFirstName());
    String lastName = capitalizeFully(person.getLastName());

    log.info("Updating user name: timestamp: {}, name: {} {}",
            event.getTimestamp(),
            firstName,
            lastName
    );

    userService.findByPersonalCode(person.getPersonalCode()).ifPresent(user -> {
        user.setFirstName(firstName);
        user.setLastName(lastName);
        userService.save(user);
    });
}
 
開發者ID:TulevaEE,項目名稱:onboarding-service,代碼行數:19,代碼來源:UserNameUpdater.java

示例15: conversationUpdated

import org.springframework.context.event.EventListener; //導入依賴的package包/類
/**
 * Processes update events as e.g. sent by the {@link StoreService}
 * @param storeEvent
 */
@EventListener
protected void conversationUpdated(StoreServiceEvent storeEvent){
    log.debug("StoreServiceEvent for {}", storeEvent.getConversationId());
    if(storeEvent.getOperation() == Operation.SAVE){
        if(storeEvent.getConversationStatus() == Status.Complete){
            log.debug("  - SAVE operation of a COMPLETED conversation");
            indexConversation(storeService.get(storeEvent.getConversationId()), true);
        } //else we do not index uncompleted conversations
    } else if(storeEvent.getOperation() == Operation.DELETE){
        log.debug("  - DELETE operation");
        removeConversation(storeEvent.getConversationId(), true);
    } else {
        log.debug("  - {} ignored", storeEvent);
    }
}
 
開發者ID:redlink-gmbh,項目名稱:smarti,代碼行數:20,代碼來源:ConversationIndexer.java


注:本文中的org.springframework.context.event.EventListener類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。