Search in sources :

Example 11 with Scheduled

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);
}
Also used : SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date) Scheduled(org.springframework.scheduling.annotation.Scheduled)

Example 12 with Scheduled

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;
        }
    });
}
Also used : GetUpdates(com.pengrad.telegrambot.request.GetUpdates) Message(com.pengrad.telegrambot.model.Message) GetUpdatesResponse(com.pengrad.telegrambot.response.GetUpdatesResponse) Update(com.pengrad.telegrambot.model.Update) Scheduled(org.springframework.scheduling.annotation.Scheduled)

Example 13 with Scheduled

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);
    }
}
Also used : KVTable(org.apache.rocketmq.common.protocol.body.KVTable) BrokerData(org.apache.rocketmq.common.protocol.route.BrokerData) Date(java.util.Date) BigDecimal(java.math.BigDecimal) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) ClusterInfo(org.apache.rocketmq.common.protocol.body.ClusterInfo) HashMap(java.util.HashMap) Map(java.util.Map) Scheduled(org.springframework.scheduling.annotation.Scheduled)

Example 14 with Scheduled

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);
    }
}
Also used : SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) TopicList(org.apache.rocketmq.common.protocol.body.TopicList) GroupList(org.apache.rocketmq.common.protocol.body.GroupList) List(java.util.List) IOException(java.io.IOException) SimpleDateFormat(java.text.SimpleDateFormat) File(java.io.File) Date(java.util.Date) Scheduled(org.springframework.scheduling.annotation.Scheduled)

Example 15 with Scheduled

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);
}
Also used : DisruptorBindEvent(com.lmax.disruptor.spring.boot.event.DisruptorBindEvent) 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