增加启动等待采集器连接事件
parent
4d06e75487
commit
1e8edd88ef
@ -0,0 +1,27 @@
|
|||||||
|
package com.docus.server.common.netty.event;
|
||||||
|
|
||||||
|
import com.docus.server.common.CommMsg;
|
||||||
|
import lombok.Getter;
|
||||||
|
import org.springframework.context.ApplicationEvent;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
public class StartUpEvent extends ApplicationEvent {
|
||||||
|
/**
|
||||||
|
* 下载对应任务id ,接收处理
|
||||||
|
*/
|
||||||
|
private final String message;
|
||||||
|
|
||||||
|
private final CommMsg commMsg;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param source 触发该事件的对象
|
||||||
|
* @param message 该事件携带的信息
|
||||||
|
*/
|
||||||
|
public StartUpEvent(Object source, String message, CommMsg commMsg) {
|
||||||
|
super(source);
|
||||||
|
this.message = message;
|
||||||
|
this.commMsg = commMsg;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,41 @@
|
|||||||
|
package com.docus.server.common.netty.event;
|
||||||
|
|
||||||
|
import com.docus.server.common.netty.server.CollectorChannelCacheMap;
|
||||||
|
import io.netty.channel.Channel;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.context.event.EventListener;
|
||||||
|
import org.springframework.scheduling.annotation.Async;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
@Slf4j
|
||||||
|
public class StartUpEventListener {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private CollectorChannelCacheMap collectorChannelCacheMap;
|
||||||
|
|
||||||
|
|
||||||
|
@EventListener
|
||||||
|
@Async("threadPoolExecutor")
|
||||||
|
public void startUp(StartUpEvent startUpEvent) {
|
||||||
|
while (true) {
|
||||||
|
String collectorId = startUpEvent.getMessage();
|
||||||
|
Channel channel = collectorChannelCacheMap.get(collectorId);
|
||||||
|
log.info("等待采集器={}启动中", collectorId);
|
||||||
|
if (null != channel && channel.isOpen()) {
|
||||||
|
log.info("等待采集器={}启动成功并注册到终端", collectorId);
|
||||||
|
collectorChannelCacheMap.writeAndFlush(collectorId, startUpEvent.getCommMsg());
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
Thread.sleep(5000);
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue