下发任务
parent
50c8321678
commit
490d8bbbc1
@ -0,0 +1,50 @@
|
|||||||
|
package com.docus.server;
|
||||||
|
|
||||||
|
import com.docus.core.util.DateUtil;
|
||||||
|
import com.docus.core.util.json.JSON;
|
||||||
|
import com.docus.server.common.netty.CommMsg;
|
||||||
|
import com.docus.server.common.netty.server.ChannelRepository;
|
||||||
|
import com.docus.server.convert.CommMsgConvert;
|
||||||
|
import com.docus.server.dto.scheduling.management.schterminator.CommMsgDTO;
|
||||||
|
import io.netty.buffer.Unpooled;
|
||||||
|
import io.netty.channel.Channel;
|
||||||
|
import io.netty.util.CharsetUtil;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.scheduling.annotation.Async;
|
||||||
|
import org.springframework.scheduling.annotation.EnableAsync;
|
||||||
|
import org.springframework.scheduling.annotation.EnableScheduling;
|
||||||
|
import org.springframework.scheduling.annotation.Scheduled;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
@EnableScheduling
|
||||||
|
@EnableAsync
|
||||||
|
public class JobConfig {
|
||||||
|
@Resource
|
||||||
|
private ChannelRepository channelRepository;
|
||||||
|
|
||||||
|
@Async
|
||||||
|
@Scheduled(cron = "0/1 * * * * ?")
|
||||||
|
public void runTask() throws InterruptedException {
|
||||||
|
|
||||||
|
Map<String, Channel> channelMap = channelRepository.getIpToChannelCacheMap();
|
||||||
|
Set<String> keySet = channelMap.keySet();
|
||||||
|
|
||||||
|
for (String clientIp : keySet) {
|
||||||
|
Channel channel = channelMap.get(clientIp);
|
||||||
|
|
||||||
|
CommMsg commMsg = CommMsgConvert.INSTANCE.convertDO(new CommMsgDTO());
|
||||||
|
commMsg.setMessageTime(DateUtil.formatDateTime(new Date()));
|
||||||
|
|
||||||
|
if (channel != null) {
|
||||||
|
channel.writeAndFlush(Unpooled.copiedBuffer(JSON.toJSON(commMsg), CharsetUtil.UTF_8));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue