Search in sources :

Example 36 with Scheduled

use of org.springframework.scheduling.annotation.Scheduled in project anki-battle-showcase by adessoAG.

the class GameEngine method gameLoop.

@Scheduled(fixedRate = 50)
public void gameLoop() {
    VehicleStateProvider vehicleStateProvider = new VehicleStateProvider();
    if (running) {
        // Step 0: Calculate elapsed nanoseconds since last loop
        long step = System.nanoTime();
        long deltaNanos = step - lastStep;
        lastStep = step;
        // TODO: Synchronize with Anki vehicles
        if (stepCount == 0) {
            for (DynamicBody body : world.getDynamicBodies()) {
                if (body instanceof Vehicle)
                    anki.synchronizeState((Vehicle) body);
            }
        }
        // Step 2: Simulate movement
        updateSimulation(deltaNanos);
        // Step 3: Process input
        // TODO: Process input from frontend
        // Step 4: Evaluate behavior
        stepCount++;
        if (stepCount > 3) {
            List<DynamicBody> dynBodies = world.getDynamicBodies();
            for (DynamicBody body : dynBodies) {
                log.debug(body.toString());
                if (!(body instanceof Vehicle)) {
                    continue;
                }
                List<GameState> factsRoad = vehicleStateProvider.getRoadFacts((Vehicle) body);
                List<GameState> factsInventory = vehicleStateProvider.getInventoryFacts((Vehicle) body);
                List<GameState> factsObstacles = vehicleStateProvider.getObstacleFacts((Vehicle) body);
                body.setFacts(factsRoad, factsInventory, factsObstacles);
            }
            evaluateBehavior();
            stepCount = 0;
        }
        // Remove while iterating, leads to exception
        // java.util.ConcurrentModificationException: in renderer?
        // collisionHandling();
        collectOrphanedWeapons();
        // Step 5: Render world
        renderWorld();
        calculateLaptime();
    }
}
Also used : Vehicle(de.adesso.anki.battle.world.bodies.Vehicle) VehicleStateProvider(de.adesso.anki.battle.providers.VehicleStateProvider) DynamicBody(de.adesso.anki.battle.world.DynamicBody) GameState(com.states.GameState) Scheduled(org.springframework.scheduling.annotation.Scheduled)

Example 37 with Scheduled

use of org.springframework.scheduling.annotation.Scheduled in project mica2 by obiba.

the class TempFileService method cleanupTempFiles.

@Scheduled(fixedDelay = TEMP_FILE_CLEANUP_INTERVAL)
public void cleanupTempFiles() {
    log.debug("Cleaning up tempfiles");
    List<TempFile> tempFiles = tempFileRepository.findByCreatedDateLessThan(DateTime.now().minusHours(TEMP_FILE_EXPIRE_TIMEOUT), new PageRequest(0, 100));
    tempFiles.forEach(f -> tempFileRepository.delete(f));
}
Also used : PageRequest(org.springframework.data.domain.PageRequest) TempFile(org.obiba.mica.file.TempFile) Scheduled(org.springframework.scheduling.annotation.Scheduled)

Example 38 with Scheduled

use of org.springframework.scheduling.annotation.Scheduled in project webapp by elimu-ai.

the class MailChimpScheduler method executeImport.

// 10 past every hour
@Scheduled(cron = "00 10 * * * *")
public synchronized void executeImport() {
    logger.info("executeImport");
    if (EnvironmentContextLoaderListener.env != Environment.PROD) {
        return;
    }
    List<Contributor> contributors = contributorDao.readAll();
    logger.info("contributors.size(): " + contributors.size());
    for (Contributor contributor : contributors) {
        try {
            // Check if contributor is already subscribed to the mailing list
            String memberInfo = MailChimpApiHelper.getMemberInfo(contributor.getEmail());
            if (StringUtils.isBlank(memberInfo)) {
                MailChimpApiHelper.subscribeMember(contributor);
            }
        } catch (IOException ex) {
            logger.error(null, ex);
            break;
        }
    }
    logger.info("executeImport complete");
}
Also used : Contributor(ai.elimu.model.Contributor) IOException(java.io.IOException) Scheduled(org.springframework.scheduling.annotation.Scheduled)

Example 39 with Scheduled

use of org.springframework.scheduling.annotation.Scheduled in project webapp by elimu-ai.

the class SyllableUsageCountScheduler method execute.

// At 07:30 every morning
@Scheduled(cron = "00 30 07 * * *")
public synchronized void execute() {
    logger.info("execute");
    for (Locale locale : Locale.values()) {
        logger.info("Calculating usage count for Syllables with locale " + locale);
        Map<String, Integer> syllableFrequencyMap = new HashMap<>();
        List<StoryBook> storyBooks = storyBookDao.readAllOrdered(locale);
        logger.info("storyBooks.size(): " + storyBooks.size());
        for (StoryBook storyBook : storyBooks) {
            logger.info("storyBook.getTitle(): " + storyBook.getTitle());
            Map<String, Integer> syllableFrequencyMapForBook = SyllableFrequencyHelper.getSyllableFrequency(storyBook);
            for (String key : syllableFrequencyMapForBook.keySet()) {
                String syllableText = key;
                int syllableFrequency = syllableFrequencyMapForBook.get(key);
                if (!syllableFrequencyMap.containsKey(syllableText)) {
                    syllableFrequencyMap.put(syllableText, syllableFrequency);
                } else {
                    syllableFrequencyMap.put(syllableText, syllableFrequencyMap.get(syllableText) + syllableFrequency);
                }
            }
        }
        logger.info("syllableFrequencyMap: " + syllableFrequencyMap);
        for (String key : syllableFrequencyMap.keySet()) {
            String syllableText = key;
            // Skip syllables that are actual words
            // TODO: add logic to Word editing
            Word word = wordDao.readByText(locale, syllableText);
            if (word != null) {
                continue;
            }
            // TODO: add support for trigrams
            if (syllableText.length() != 2) {
                continue;
            }
            Syllable existingSyllable = syllableDao.readByText(locale, syllableText);
            if (existingSyllable == null) {
                Syllable syllable = new Syllable();
                syllable.setLocale(locale);
                syllable.setTimeLastUpdate(Calendar.getInstance());
                syllable.setText(syllableText);
                syllable.setUsageCount(syllableFrequencyMap.get(syllableText));
                syllableDao.create(syllable);
            } else {
                existingSyllable.setUsageCount(syllableFrequencyMap.get(syllableText));
                syllableDao.update(existingSyllable);
            }
        }
    }
    logger.info("execute complete");
}
Also used : Locale(ai.elimu.model.enums.Locale) StoryBook(ai.elimu.model.content.StoryBook) Word(ai.elimu.model.content.Word) HashMap(java.util.HashMap) Syllable(ai.elimu.model.content.Syllable) Scheduled(org.springframework.scheduling.annotation.Scheduled)

Example 40 with Scheduled

use of org.springframework.scheduling.annotation.Scheduled in project haha by hahafreeasair666.

the class CreditComponent method timedTaskOfZan.

/*@Scheduled(fixedRate = 5000*1)
    public void testTimedTask(){
        System.out.println("哈哈自在如风");
    }*/
/**
 * 对反馈公告的赞进行每日赞数量检测进行发布者信用积分的修改
 */
@Scheduled(cron = "0 0 0 * * ?")
public void timedTaskOfZan() {
    try {
        // 对收养反馈公告的赞数量进行发布者信用积分改变
        Wrapper<AdoptionFeedBack> wrapper = new EntityWrapper<>();
        adoptionFeedBackService.selectList(wrapper).forEach(li -> {
            News news = newsService.selectById(li.getNewsId());
            if (news.getZan() > li.getLastTimeZan()) {
                updateUserCredit(news.getCreateUserId(), getNumber(news.getZan() - li.getLastTimeZan()), true);
                li.setLastTimeZan(news.getZan());
                adoptionFeedBackService.updateById(li);
            }
        });
        // 对成功收养的反馈公告进行检查对信用积分改变
        Wrapper<Adoption> wrapper1 = new EntityWrapper<>();
        wrapper1.eq("isadoption", 1);
        adoptionService.selectList(wrapper1).forEach(li -> {
            AdoptionSuccessNewsVO adoptionSuccessNewsVO = adoptionMapper.checkUserIsSendNews(li.getId());
            // 第一次
            if (!li.getFirstHandle()) {
                newsHandle(li, adoptionSuccessNewsVO, 1);
            // 第二次
            } else if (!li.getSecondHandle()) {
                newsHandle(li, adoptionSuccessNewsVO, 2);
            // 第三次
            } else if (!li.getThirdHandle()) {
                newsHandle(li, adoptionSuccessNewsVO, 3);
            }
            adoptionService.updateById(li);
        });
        log.info("定时任务处理完毕 " + new Date());
    } catch (Exception e) {
        log.error("拉闸,定时任务异常..............");
    }
}
Also used : AdoptionSuccessNewsVO(com.ch999.haha.admin.vo.mappervo.AdoptionSuccessNewsVO) AdoptionFeedBack(com.ch999.haha.admin.entity.AdoptionFeedBack) News(com.ch999.haha.admin.entity.News) EntityWrapper(com.baomidou.mybatisplus.mapper.EntityWrapper) Adoption(com.ch999.haha.admin.entity.Adoption) Date(java.util.Date) Scheduled(org.springframework.scheduling.annotation.Scheduled)

Aggregations

Scheduled (org.springframework.scheduling.annotation.Scheduled)40 Date (java.util.Date)9 IOException (java.io.IOException)6 HashMap (java.util.HashMap)5 Contributor (ai.elimu.model.Contributor)4 Locale (ai.elimu.model.enums.Locale)4 Nabaztag (com.nabalive.data.core.model.Nabaztag)4 StoryBook (ai.elimu.model.content.StoryBook)3 Word (ai.elimu.model.content.Word)3 Application (com.nabalive.application.core.Application)3 Status (com.nabalive.server.jabber.Status)3 File (java.io.File)3 SimpleDateFormat (java.text.SimpleDateFormat)3 ArrayList (java.util.ArrayList)3 DisruptorBindEvent (com.lmax.disruptor.spring.boot.event.DisruptorBindEvent)2 BigDecimal (java.math.BigDecimal)2 DateFormat (java.text.DateFormat)2 LocalDate (java.time.LocalDate)2 Map (java.util.Map)2 ExecutionException (java.util.concurrent.ExecutionException)2