优化离线清理玩家逻辑
parent
0b67387c77
commit
29518695a9
|
@ -45,7 +45,7 @@ public class UserManager {
|
|||
private static Map<Integer,Long> userMapPutTime = new ConcurrentHashMap<>(); //离线读入
|
||||
private static AtomicInteger login_f_num = new AtomicInteger(0);//登陆计数
|
||||
private static final int LOGIN_F_LIMIT = 100;//报警界限
|
||||
private static final long LIVE_TIME = 60 * 60 * 1000L;
|
||||
private static final long LIVE_TIME = 12 * 60 * 60 * 1000L;
|
||||
|
||||
public static void addUser(User user) {
|
||||
userMap.put(user.getId(), user);
|
||||
|
@ -62,43 +62,37 @@ public class UserManager {
|
|||
|
||||
//离线清除逻辑
|
||||
public static void checkOffline(){
|
||||
// try {
|
||||
// Set<User> collect = userMap.entrySet().stream().filter(integerUserEntry -> !OnlineUserManager.checkUidOnline(integerUserEntry.getKey())).map(Map.Entry::getValue).collect(Collectors.toSet());
|
||||
// if (OnlineUserManager.sessionMap.entrySet().isEmpty() && ChampionshipLogic.getProgress() == -1) {
|
||||
// userMap.clear();
|
||||
// userMapPutTime.clear();
|
||||
// LOGGER.info("checkOffline no online clear all {}", userMap.keySet().size());
|
||||
// return;
|
||||
// }
|
||||
// long now = System.currentTimeMillis();
|
||||
// for (User integerUserEntry : collect) {
|
||||
// Long addTime = userMapPutTime.getOrDefault(integerUserEntry.getId(), LIVE_TIME);
|
||||
// if (now - addTime >= LIVE_TIME) {
|
||||
// userMap.remove(integerUserEntry.getId());
|
||||
// userMapPutTime.remove(integerUserEntry.getId());
|
||||
// }
|
||||
// }
|
||||
// LOGGER.info("checkOffline left count={}", userMap.keySet().size());
|
||||
// }catch (Exception e){
|
||||
// LOGGER.error("Exception离线清除逻辑err={}",e.toString());
|
||||
// }
|
||||
try {
|
||||
Set<User> collect = userMap.entrySet().stream().filter(integerUserEntry -> !OnlineUserManager.checkUidOnline(integerUserEntry.getKey())).map(Map.Entry::getValue).collect(Collectors.toSet());
|
||||
long l = System.currentTimeMillis();
|
||||
collect.forEach(integerUserEntry -> {
|
||||
long offLineTime = integerUserEntry.getPlayerInfoManager().getOffLineTime();
|
||||
if (offLineTime < integerUserEntry.getPlayerInfoManager().getOnlineTime()) {
|
||||
return;
|
||||
}
|
||||
if (l - offLineTime > 12 * 60 * 60 * 1000 && userMapPutTime.getOrDefault(integerUserEntry.getId(), 0L) > 12 * 60 * 60 * 1000) {
|
||||
long now = System.currentTimeMillis();
|
||||
for (User integerUserEntry : collect) {
|
||||
Long addTime = userMapPutTime.getOrDefault(integerUserEntry.getId(), LIVE_TIME);
|
||||
if (now - addTime >= LIVE_TIME) {
|
||||
userMap.remove(integerUserEntry.getId());
|
||||
userMapPutTime.remove(integerUserEntry.getId());
|
||||
}
|
||||
});
|
||||
}
|
||||
LOGGER.info("checkOffline left count={}", userMap.keySet().size());
|
||||
} catch (Exception e) {
|
||||
LOGGER.error("Exception离线清除逻辑err={}", e.toString());
|
||||
}catch (Exception e){
|
||||
LOGGER.error("Exception离线清除逻辑err={}",e.toString());
|
||||
}
|
||||
// try {
|
||||
// Set<User> collect = userMap.entrySet().stream().filter(integerUserEntry -> !OnlineUserManager.checkUidOnline(integerUserEntry.getKey())).map(Map.Entry::getValue).collect(Collectors.toSet());
|
||||
// long l = System.currentTimeMillis();
|
||||
// collect.forEach(integerUserEntry -> {
|
||||
// long offLineTime = integerUserEntry.getPlayerInfoManager().getOffLineTime();
|
||||
// if (offLineTime < integerUserEntry.getPlayerInfoManager().getOnlineTime()) {
|
||||
// return;
|
||||
// }
|
||||
// if (l - offLineTime > 12 * 60 * 60 * 1000 && userMapPutTime.getOrDefault(integerUserEntry.getId(), 0L) > 12 * 60 * 60 * 1000) {
|
||||
// userMap.remove(integerUserEntry.getId());
|
||||
// userMapPutTime.remove(integerUserEntry.getId());
|
||||
// }
|
||||
// });
|
||||
// LOGGER.info("checkOffline left count={}", userMap.keySet().size());
|
||||
// } catch (Exception e) {
|
||||
// LOGGER.error("Exception离线清除逻辑err={}", e.toString());
|
||||
// }
|
||||
}
|
||||
|
||||
|
||||
|
@ -209,6 +203,7 @@ public class UserManager {
|
|||
public static User getUser(int uid,boolean canNull) throws Exception {
|
||||
User user = userMap.get(uid);
|
||||
if (user != null) {
|
||||
userMapPutTime.put(uid, TimeUtils.now());
|
||||
return user;
|
||||
}
|
||||
user = MongoUtil.getInstence().getMyMongoTemplate().findById(User.getCollectionName(), uid, User.class);
|
||||
|
|
Loading…
Reference in New Issue