You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
57 lines
1.3 KiB
57 lines
1.3 KiB
|
9 months ago
|
package com.ruoyi.imserver.netty;
|
||
|
|
|
||
|
|
|
||
|
|
import com.ruoyi.common.im.constant.IMRedisKey;
|
||
|
|
import com.ruoyi.common.im.mq.RedisMQTemplate;
|
||
|
|
import lombok.AllArgsConstructor;
|
||
|
|
import lombok.extern.slf4j.Slf4j;
|
||
|
|
import org.springframework.boot.CommandLineRunner;
|
||
|
|
import org.springframework.stereotype.Component;
|
||
|
|
|
||
|
|
import javax.annotation.PreDestroy;
|
||
|
|
import java.util.List;
|
||
|
|
|
||
|
|
@Slf4j
|
||
|
|
@Component
|
||
|
|
@AllArgsConstructor
|
||
|
|
public class IMServerGroup implements CommandLineRunner {
|
||
|
|
|
||
|
|
public static volatile long serverId = 0;
|
||
|
|
|
||
|
|
private final RedisMQTemplate redisMQTemplate;
|
||
|
|
|
||
|
|
private final List<IMServer> imServers;
|
||
|
|
|
||
|
|
/***
|
||
|
|
* 判断服务器是否就绪
|
||
|
|
*
|
||
|
|
**/
|
||
|
|
public boolean isReady() {
|
||
|
|
for (IMServer imServer : imServers) {
|
||
|
|
if (!imServer.isReady()) {
|
||
|
|
return false;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
return true;
|
||
|
|
}
|
||
|
|
|
||
|
|
@Override
|
||
|
|
public void run(String... args) {
|
||
|
|
// 初始化SERVER_ID
|
||
|
|
String key = IMRedisKey.IM_MAX_SERVER_ID;
|
||
|
|
serverId = redisMQTemplate.opsForValue().increment(key, 1);
|
||
|
|
// 启动服务
|
||
|
|
for (IMServer imServer : imServers) {
|
||
|
|
imServer.start();
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
@PreDestroy
|
||
|
|
public void destroy() {
|
||
|
|
// 停止服务
|
||
|
|
for (IMServer imServer : imServers) {
|
||
|
|
imServer.stop();
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|