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();
}
}
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));
}
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");
}
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");
}
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("拉闸,定时任务异常..............");
}
}
Aggregations