use of org.springframework.scheduling.annotation.Scheduled in project SpringStepByStep by JavaProgrammerLB.
the class MyBean method printMessage.
@Scheduled(fixedRate = 1000)
public void printMessage() {
System.out.println("I am called by Spring scheduler");
Date date = new Date();
SimpleDateFormat fmt = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String now = fmt.format(date);
System.out.println(now);
}
use of org.springframework.scheduling.annotation.Scheduled in project anton-pavlovich-bot by wyvie.
the class MessageReader method readMessages.
@Scheduled(fixedDelay = 200)
public void readMessages() {
GetUpdates getUpdates = new GetUpdates().limit(telegramProperties.getUpdateLimit()).offset(lastOffset).timeout(0);
GetUpdatesResponse response = telegramBot.execute(getUpdates);
List<Update> updates = response.updates();
updates.forEach(update -> {
lastOffset = update.updateId() + 1;
Message message = update.message();
if (message != null && message.text() != null) {
logger.debug("Got message '" + message.text() + "' from chat_id " + message.chat().id());
persistUser(message.from());
if (validateCommmand(message))
commandProcessor.processCommand(message);
else {
String messageText = message.text().trim();
if (messageText.equals("+") || messageText.equals("-") || emojiHelper.isThumbsUp(messageText) || emojiHelper.isThumbsDown(messageText))
commandProcessor.processKarma(message);
}
lastOffset = update.updateId() + 1;
}
});
}
use of org.springframework.scheduling.annotation.Scheduled in project rocketmq-externals by apache.
the class DashboardCollectTask method collectBroker.
@Scheduled(cron = "0 0/1 * * * ?")
public void collectBroker() {
if (!rmqConfigure.isEnableDashBoardCollect()) {
return;
}
try {
Date date = new Date();
ClusterInfo clusterInfo = mqAdminExt.examineBrokerClusterInfo();
Set<Map.Entry<String, BrokerData>> clusterEntries = clusterInfo.getBrokerAddrTable().entrySet();
Map<String, String> addresses = Maps.newHashMap();
for (Map.Entry<String, BrokerData> clusterEntry : clusterEntries) {
HashMap<Long, String> addrs = clusterEntry.getValue().getBrokerAddrs();
Set<Map.Entry<Long, String>> addrsEntries = addrs.entrySet();
for (Map.Entry<Long, String> addrEntry : addrsEntries) {
addresses.put(addrEntry.getValue(), clusterEntry.getKey() + ":" + addrEntry.getKey());
}
}
Set<Map.Entry<String, String>> entries = addresses.entrySet();
for (Map.Entry<String, String> entry : entries) {
List<String> list = dashboardCollectService.getBrokerMap().get(entry.getValue());
if (null == list) {
list = Lists.newArrayList();
}
KVTable kvTable = fetchBrokerRuntimeStats(entry.getKey(), 3);
if (kvTable == null) {
continue;
}
String[] tpsArray = kvTable.getTable().get("getTotalTps").split(" ");
BigDecimal totalTps = new BigDecimal(0);
for (String tps : tpsArray) {
totalTps = totalTps.add(new BigDecimal(tps));
}
BigDecimal averageTps = totalTps.divide(new BigDecimal(tpsArray.length), 5, BigDecimal.ROUND_HALF_UP);
list.add(date.getTime() + "," + averageTps.toString());
dashboardCollectService.getBrokerMap().put(entry.getValue(), list);
}
log.debug("Broker Collected Data in memory = {}" + JsonUtil.obj2String(dashboardCollectService.getBrokerMap().asMap()));
} catch (Exception e) {
throw Throwables.propagate(e);
}
}
use of org.springframework.scheduling.annotation.Scheduled in project rocketmq-externals by apache.
the class DashboardCollectTask method saveData.
@Scheduled(cron = "0/5 * * * * ?")
public void saveData() {
if (!rmqConfigure.isEnableDashBoardCollect()) {
return;
}
// one day refresh cache one time
String dataLocationPath = rmqConfigure.getConsoleCollectData();
DateFormat format = new SimpleDateFormat("yyyy-MM-dd");
String nowDateStr = format.format(new Date());
String currentDateStr = format.format(currentDate);
if (!currentDateStr.equals(nowDateStr)) {
dashboardCollectService.getBrokerMap().invalidateAll();
dashboardCollectService.getTopicMap().invalidateAll();
currentDate = new Date();
}
File brokerFile = new File(dataLocationPath + nowDateStr + ".json");
File topicFile = new File(dataLocationPath + nowDateStr + "_topic" + ".json");
try {
Map<String, List<String>> brokerFileMap;
Map<String, List<String>> topicFileMap;
if (brokerFile.exists()) {
brokerFileMap = dashboardCollectService.jsonDataFile2map(brokerFile);
} else {
brokerFileMap = Maps.newHashMap();
Files.createParentDirs(brokerFile);
}
if (topicFile.exists()) {
topicFileMap = dashboardCollectService.jsonDataFile2map(topicFile);
} else {
topicFileMap = Maps.newHashMap();
Files.createParentDirs(topicFile);
}
brokerFile.createNewFile();
topicFile.createNewFile();
writeFile(dashboardCollectService.getBrokerMap(), brokerFileMap, brokerFile);
writeFile(dashboardCollectService.getTopicMap(), topicFileMap, topicFile);
log.debug("Broker Collected Data in memory = {}" + JsonUtil.obj2String(dashboardCollectService.getBrokerMap().asMap()));
log.debug("Topic Collected Data in memory = {}" + JsonUtil.obj2String(dashboardCollectService.getTopicMap().asMap()));
} catch (IOException e) {
throw Throwables.propagate(e);
}
}
use of org.springframework.scheduling.annotation.Scheduled in project spring-boot-starter-samples by vindell.
the class DisruptorConfig method send.
// 每1s执行1次
@Scheduled(fixedDelay = 1000)
public void send() throws Exception {
DisruptorBindEvent event = new DisruptorBindEvent(this, "message " + Math.random());
event.setEvent("Event-Output");
event.setTag("TagA-Output");
event.setKey("id-" + Math.random());
disruptorTemplate.publishEvent(event);
}
Aggregations