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.
44 lines
1.1 KiB
44 lines
1.1 KiB
|
3 years ago
|
package com.bx.imserver.netty;
|
||
|
|
|
||
|
|
import com.bx.imcommon.contant.RedisKey;
|
||
|
|
import lombok.extern.slf4j.Slf4j;
|
||
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
||
|
|
import org.springframework.boot.CommandLineRunner;
|
||
|
|
import org.springframework.data.redis.core.RedisTemplate;
|
||
|
|
import org.springframework.stereotype.Component;
|
||
|
|
|
||
|
|
import javax.annotation.PreDestroy;
|
||
|
|
import java.util.List;
|
||
|
|
|
||
|
|
@Slf4j
|
||
|
|
@Component
|
||
|
3 years ago
|
public class IMServerGroup implements CommandLineRunner {
|
||
|
3 years ago
|
|
||
|
|
public static volatile long serverId = 0;
|
||
|
|
|
||
|
|
@Autowired
|
||
|
|
RedisTemplate<String,Object> redisTemplate;
|
||
|
|
|
||
|
|
@Autowired
|
||
|
|
private List<IMServer> imServers;
|
||
|
|
|
||
|
|
@Override
|
||
|
|
public void run(String... args) throws Exception {
|
||
|
|
// 初始化SERVER_ID
|
||
|
|
String key = RedisKey.IM_MAX_SERVER_ID;
|
||
|
|
serverId = redisTemplate.opsForValue().increment(key,1);
|
||
|
|
// 启动服务
|
||
|
|
for(IMServer imServer:imServers){
|
||
|
|
imServer.start();
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
@PreDestroy
|
||
|
|
public void destroy(){
|
||
|
|
// 停止服务
|
||
|
|
for(IMServer imServer:imServers){
|
||
|
|
imServer.stop();
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|