修改分组
parent
8ed8485114
commit
3107bf3254
|
@ -2,11 +2,11 @@ package com.global;
|
|||
|
||||
import com.global.config.ConfigurableApplicationContextManager;
|
||||
import com.global.config.CoreSettings;
|
||||
import com.global.logic.GlobalLogic;
|
||||
import com.global.redis.RedisUtil;
|
||||
import com.global.thread.ThreadManager;
|
||||
import com.global.thrift.pool.GlobalRpcService;
|
||||
import com.global.thrift.pool.RPCServerTask;
|
||||
import com.world.logic.GlobalLogic;
|
||||
import manager.STableManager;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
package com.global.thread;
|
||||
|
||||
import com.global.redis.RedisKey;
|
||||
import com.global.redis.RedisUtil;
|
||||
import com.world.logic.GlobalLogic;
|
||||
import com.global.logic.GlobalLogic;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
|
|
@ -1,85 +0,0 @@
|
|||
package com.world.logic;
|
||||
|
||||
|
||||
import com.global.redis.RedisKey;
|
||||
import com.global.redis.RedisUtil;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.data.redis.core.ZSetOperations;
|
||||
import util.TimeUtils;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* @author lvxinran
|
||||
* @date 2020/12/1
|
||||
* @discribe
|
||||
*/
|
||||
|
||||
public class GlobalLogic {
|
||||
|
||||
|
||||
public static final Logger LOGGER = LoggerFactory.getLogger(GlobalLogic.class);
|
||||
|
||||
/**
|
||||
* 获取单例
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static GlobalLogic getInstance() {
|
||||
return Instance.instance;
|
||||
}
|
||||
|
||||
public static class Instance {
|
||||
public final static GlobalLogic instance = new GlobalLogic();
|
||||
}
|
||||
|
||||
private static Map<String,Integer> splitInfo;
|
||||
/**
|
||||
* 分组
|
||||
*/
|
||||
public void doSplit(){
|
||||
RedisUtil redisUtil = RedisUtil.getInstence();
|
||||
//这里为所有服务器的世界等级
|
||||
Map<String,Integer> worldLevelMap = redisUtil.getMapValues(RedisKey.SERVER_WORLDLEVE_INFO,String.class,Integer.class);
|
||||
Object matched = redisUtil.get(RedisKey.MATCHED_SPLIT_KEY);
|
||||
if(matched==null){
|
||||
return;
|
||||
}
|
||||
LOGGER.info("Global开始分组");
|
||||
long lastHour = TimeUtils.getLastOrUnderHour(TimeUtils.now(), 1, 0, 0, true);
|
||||
lastHour+=(2*TimeUtils.WEEK);
|
||||
int expireTime =(int)((lastHour-TimeUtils.now())/1000);
|
||||
redisUtil.set(RedisKey.MATCHED_SPLIT_KEY,String.valueOf(1),expireTime-60);
|
||||
worldLevelMap.forEach((k,v)->redisUtil.zsetAddOne(RedisKey.SERVER_LEVEL_RANK,k,v));
|
||||
Set<ZSetOperations.TypedTuple<String>> zsetRevRangeWithScore = redisUtil.getZsetRevRangeWithScore(RedisKey.SERVER_LEVEL_RANK, 10, 999);
|
||||
// int remain = zsetRevRangeWithScore.size() % 8;
|
||||
int index = 0;
|
||||
int areaId = 1;
|
||||
Map<String,Integer> split = new HashMap<>(zsetRevRangeWithScore.size());
|
||||
for(ZSetOperations.TypedTuple<String> data:zsetRevRangeWithScore){
|
||||
if(index>=8){
|
||||
if(zsetRevRangeWithScore.size()-areaId*8>4){
|
||||
areaId++;
|
||||
}
|
||||
index=0;
|
||||
}
|
||||
split.put(data.getValue(),areaId);
|
||||
|
||||
index++;
|
||||
}
|
||||
redisUtil.putMapEntrys(RedisKey.SERVER_SPLIT_INFO,split);
|
||||
LOGGER.info("Global分组结束");
|
||||
splitInfo = RedisUtil.getInstence().getMapValues(RedisKey.SERVER_SPLIT_INFO,String.class,Integer.class);
|
||||
}
|
||||
|
||||
public int getSplitInfo(int serverId){
|
||||
|
||||
if(splitInfo==null){
|
||||
splitInfo = RedisUtil.getInstence().getMapValues(RedisKey.SERVER_SPLIT_INFO,String.class,Integer.class);
|
||||
}
|
||||
return splitInfo.getOrDefault(String.valueOf(serverId),-1);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue