back_recharge
zhangshanxue 2020-08-13 19:26:18 +08:00
parent 6895ec3444
commit cbde195205
36 changed files with 1099 additions and 378 deletions

View File

@ -1,111 +0,0 @@
package com.ljsd.common.mogodb;
import com.mongodb.*;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Query;
import java.lang.ref.WeakReference;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
public class LjsdMongoTemplate {
private MongoTemplate mongoTemplate;
public LjsdMongoTemplate( MongoTemplate mongoTemplate ){
this.mongoTemplate = mongoTemplate;
}
public DBCollection getCollection(String collectionName){
return mongoTemplate.getCollection(collectionName);
}
public <T> void save(T obj) throws Exception {
// MongoRoot root = (MongoRoot)obj;
// mongoTemplate.save(obj,root.getCollection());
// root.setBsave(true);
mongoTemplate.save(obj);
}
public <T> void saveWithoutMongoRoot(T obj) throws Exception {
mongoTemplate.save(obj);
}
public <T> List<T> findAll(String collectionName, Class<T> clazz) throws Exception {
return mongoTemplate.findAll(clazz,collectionName);
}
public <T> List<T> findAllByCondition(Query query, Class<T> entityClass) throws Exception {
return mongoTemplate.find(query, entityClass);
}
public <T> T findById(String collectionName, String id, Class<T> clazz) throws Exception {
return mongoTemplate.findById(id,clazz,collectionName);
}
public <T> T findById(String collectionName, int id, Class<T> clazz) throws Exception {
return mongoTemplate.findById(id,clazz,collectionName);
}
public <T> T findById(int id, Class<T> clazz) throws Exception {
return mongoTemplate.findById(id,clazz);
}
public void chnage(Object obj){
Class<?> clazz = obj.getClass();
}
public boolean remove(Query query, String collection) throws Exception {
mongoTemplate.remove(query,collection);
return true;
}
public void updateValue(String collectionName, BasicDBObject searchQuery, BasicDBObject dbObject){
DBCollection coll = mongoTemplate.getCollection(collectionName);
coll.update(searchQuery, dbObject);
}
//非用户线程记得更新玩家数据
public void lastUpdate() throws Exception {
MongoUpdateCacheThreadLocal.update(this);
}
public void concurrentDataUpdate(Map<String, Map<String, MongoUpdateCache.UpdateRequest>> updateRequestMap) throws Exception {
MongoUpdateCacheThreadLocal.concurrentDataUpdate(this,updateRequestMap);
}
public int inc(String collectionName, String id, String key){
DBCollection collection = mongoTemplate.getCollection(collectionName);
BasicDBObject searchQuery = new BasicDBObject();
searchQuery.put("_id", id);
// 使用collection的find方法查找document
DBCursor cursor = collection.find(searchQuery);
// 循环输出结果
if (cursor.hasNext()) {
BasicDBObject update= new BasicDBObject().append("$inc",new BasicDBObject().append(key, 1));
DBObject query = cursor.next();
DBObject result = collection.findAndModify(query, update);
return Integer.parseInt(result.get(key).toString())+1;
} else {
searchQuery.put(key, 1);
collection.insert(searchQuery);
return 1;
}
}
public int inc(String key){
return inc("inc_c", "inc_k", key);
}
public Object convertToMongoType(Object obj){
return this.mongoTemplate.getConverter().convertToMongoType(obj);
}
public MongoTemplate getMongoTemplate() {
return mongoTemplate;
}
}

View File

@ -1,21 +1,19 @@
package com.ljsd.common.mogodb;
import com.ljsd.common.mogodb.util.BlockingUniqueQueue;
import com.ljsd.common.mogodb.util.ConcurrentDataMessage;
import com.ljsd.common.mogodb.util.MongoKeys;
import com.mongodb.BasicDBObject;
import org.springframework.data.mongodb.core.MongoTemplate;
import java.util.*;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.ConcurrentHashMap;
public class MongoUpdateCache {
public static class UpdateRequest {
MongoBase mongoBase;
String fullKey;
Object value;
int opCode;
public MongoBase mongoBase;
public String fullKey;
public Object value;
public int opCode;
UpdateRequest(String fullKey, Object value, int opCode, MongoBase mongoBase) {
this.fullKey = fullKey;
@ -75,8 +73,8 @@ public class MongoUpdateCache {
}
protected void update(LjsdMongoTemplate ljsdMongoTemplate) {
updateMongoData(ljsdMongoTemplate, requestMap);
protected void update( MongoUpdateImp mongoUpdateImp){
mongoUpdateImp.updateMongoData( requestMap);
requestMap.clear();
if (updateDataMap.size() !=0){
ConcurrentDataMessage.addLogQueue(new HashMap<>(updateDataMap));
@ -84,42 +82,52 @@ public class MongoUpdateCache {
}
}
public void concurrentDataUpdate(LjsdMongoTemplate ljsdMongoTemplate, Map<String, Map<String, UpdateRequest>> updateRequestMap) {
updateMongoData(ljsdMongoTemplate, updateRequestMap);
}
// public void concurrentDataUpdate(LjsdMongoTemplate ljsdMongoTemplate, Map<String, Map<String, UpdateRequest>> updateRequestMap) {
// updateMongoData(ljsdMongoTemplate, updateRequestMap);
// }
private void updateMongoData(LjsdMongoTemplate ljsdMongoTemplate, Map<String, Map<String, UpdateRequest>> updateRequestMap) {
BasicDBObject searchQuery = new BasicDBObject();
for (Map.Entry<String, Map<String, UpdateRequest>> entry : updateRequestMap.entrySet()) {
String[] strs = entry.getKey().split(":");
String collection = strs[0];
String id = strs[1];
searchQuery.put("_id", Integer.parseInt(id));
BasicDBObject valueDBObj = new BasicDBObject();
BasicDBObject dbobj = new BasicDBObject();
BasicDBObject removedbobj = new BasicDBObject();
for (UpdateRequest request : entry.getValue().values()) {
if (request.opCode == 2) {
removedbobj.append(request.fullKey, request.value);
continue;
}
valueDBObj.append(request.fullKey, ljsdMongoTemplate.convertToMongoType(request.value));
}
boolean flag = false;
if (!valueDBObj.isEmpty()) {
dbobj.append("$set", valueDBObj);
flag = true;
}
if (!removedbobj.isEmpty()) {
dbobj.append("$unset", removedbobj);
flag = true;
}
if (flag) {
ljsdMongoTemplate.updateValue(collection, searchQuery, dbobj);
}
}
}
// private void updateMongoData( Map<String, Map<String, UpdateRequest>> updateRequestMap) {
// BasicDBObject searchQuery = new BasicDBObject();
// for (Map.Entry<String, Map<String, UpdateRequest>> entry : updateRequestMap.entrySet()) {
// String[] strs = entry.getKey().split(":");
// String collection = strs[0];
// String id = strs[1];
// searchQuery.put("_id", Integer.parseInt(id));
// BasicDBObject valueDBObj = new BasicDBObject();
// BasicDBObject dbobj = new BasicDBObject();
// BasicDBObject removedbobj = new BasicDBObject();
//
// MongoTemplate otherMonogTemplate==null;
// if(collection.equals("guildInfo")){
// Integer guilderverId = MongoUtil.getInstence().findGuilderverId(id);
// otherMonogTemplate = MongoUtil.getInstence().getMonogTemplate(guilderverId);
// }else {
// int serverIdByUid = AreaManager.getInstance().getServerIdByUid(id, GameApplication.serverId);
// otherMonogTemplate = MongoUtil.getInstence().getMonogTemplate(guilderverId);
// }
//
// for (UpdateRequest request : entry.getValue().values()) {
// if (request.opCode == 2) {
// removedbobj.append(request.fullKey, request.value);
// continue;
// }
// valueDBObj.append(request.fullKey, ljsdMongoTemplate.convertToMongoType(request.value));
// }
//
// boolean flag = false;
// if (!valueDBObj.isEmpty()) {
// dbobj.append("$set", valueDBObj);
// flag = true;
// }
//
// if (!removedbobj.isEmpty()) {
// dbobj.append("$unset", removedbobj);
// flag = true;
// }
// if (flag&&null!=otherMonogTemplate) {
// otherMonogTemplate.updateValue(collection, searchQuery, dbobj);
// }
// }
// }
}

View File

@ -24,13 +24,13 @@ public class MongoUpdateCacheThreadLocal {
mongoUpdateCache.addUpdateRequest(mongoBase, fullKey, "", 2);
}
protected static void update(LjsdMongoTemplate ljsdMongoTemplate) throws IllegalAccessException {
public static void update(MongoUpdateImp mongoUpdateImp) throws IllegalAccessException {
MongoUpdateCache mongoUpdateCache = getMongoUpdateCache();
mongoUpdateCache.update(ljsdMongoTemplate);
mongoUpdateCache.update(mongoUpdateImp);
}
public static void concurrentDataUpdate(LjsdMongoTemplate ljsdMongoTemplate,Map<String, Map<String, MongoUpdateCache.UpdateRequest>> updateRequestMap) {
MongoUpdateCache mongoUpdateCache = getMongoUpdateCache();
mongoUpdateCache.concurrentDataUpdate(ljsdMongoTemplate, updateRequestMap);
}
// public static void concurrentDataUpdate(LjsdMongoTemplate ljsdMongoTemplate,Map<String, Map<String, MongoUpdateCache.UpdateRequest>> updateRequestMap) {
// MongoUpdateCache mongoUpdateCache = getMongoUpdateCache();
// mongoUpdateCache.concurrentDataUpdate(ljsdMongoTemplate, updateRequestMap);
// }
}

View File

@ -0,0 +1,13 @@
package com.ljsd.common.mogodb;
import java.util.Map;
/**
* Description: des
* Author: zsx
* CreateDate: 2020/8/11 19:31
*/
public interface MongoUpdateImp {
void updateMongoData( Map<String, Map<String, MongoUpdateCache.UpdateRequest>> updateRequestMap) ;
}

View File

@ -1,79 +0,0 @@
package com.ljsd.common.mogodb.test;
import com.ljsd.common.mogodb.LjsdMongoTemplate;
import com.ljsd.common.mogodb.MongoRootConverter;
import com.ljsd.common.mogodb.test.pojo.BaseInfoForTest;
import com.ljsd.common.mogodb.test.pojo.CardTestInfo;
import com.ljsd.common.mogodb.test.pojo.PlayerForTest;
import com.mongodb.MongoClientURI;
import org.springframework.core.convert.converter.Converter;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.SimpleMongoDbFactory;
import org.springframework.data.mongodb.core.convert.CustomConversions;
import org.springframework.data.mongodb.core.convert.DefaultDbRefResolver;
import org.springframework.data.mongodb.core.convert.DefaultMongoTypeMapper;
import org.springframework.data.mongodb.core.convert.MappingMongoConverter;
import org.springframework.data.mongodb.core.mapping.MongoMappingContext;
import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.List;
public class TestMongo {
private static LjsdMongoTemplate ljsdMongoTemplate;
public static void main(String[] args) {
try {
ljsdMongoTemplate = getLjsdMongoTemplate();
save();
PlayerForTest one = findOne();
System.out.println(one);
} catch (UnknownHostException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
}
public static void update(PlayerForTest playerForTest) throws Exception {
BaseInfoForTest baseInfoForTest = playerForTest.getBaseInfoForTest();
baseInfoForTest.setName("222222522");
ljsdMongoTemplate.lastUpdate();
}
public static PlayerForTest findOne() throws Exception {
return ljsdMongoTemplate.findById(PlayerForTest.getCollectionName(),"1",PlayerForTest.class);
}
public static void save() throws Exception {
CardTestInfo cardTestInfo = new CardTestInfo();
cardTestInfo.setId("33");
cardTestInfo.setLevel("555");
BaseInfoForTest baseInfoForTest = new BaseInfoForTest();
baseInfoForTest.setAge(10);
baseInfoForTest.setName("test");
PlayerForTest playerForTest = new PlayerForTest(1,baseInfoForTest);
baseInfoForTest.addCard(2,cardTestInfo);
ljsdMongoTemplate.save(playerForTest);
System.out.println(ljsdMongoTemplate);
}
public static LjsdMongoTemplate getLjsdMongoTemplate() throws UnknownHostException {
SimpleMongoDbFactory simpleMongoDbFactory = new SimpleMongoDbFactory(new MongoClientURI("mongodb://60.1.1.14:27017/test_10215"));
DefaultDbRefResolver dbRefResolver = new DefaultDbRefResolver(simpleMongoDbFactory);
MappingMongoConverter converter = new MappingMongoConverter(dbRefResolver, new MongoMappingContext());
converter.setTypeMapper(new DefaultMongoTypeMapper(null));
// converter.setCustomConversions(customConversions());
converter.afterPropertiesSet();
MongoTemplate mongoTemplate = new MongoTemplate(simpleMongoDbFactory, converter);
return new LjsdMongoTemplate(mongoTemplate);
}
private static CustomConversions customConversions() {
List<Converter<?, ?>> converterList = new ArrayList<Converter<?, ?>>();
converterList.add(new MongoRootConverter());
return new CustomConversions(converterList);
}
}

View File

@ -1,10 +1,7 @@
package com.ljsd.common.mogodb.test.pojo;
import com.ljsd.common.mogodb.LjsdMongoTemplate;
import com.ljsd.common.mogodb.MongoRoot;
import java.util.Map;
public class PlayerForTest extends MongoRoot {
public final static String _COLLECTION_NAME = "playerForTest";
private BaseInfoForTest baseInfoForTest;

View File

@ -1,6 +1,5 @@
package com.ljsd.common.mogodb.util;
import com.ljsd.common.mogodb.LjsdMongoTemplate;
import com.ljsd.common.mogodb.MongoUpdateCache;
import java.util.HashMap;
@ -15,10 +14,10 @@ public class ConcurrentDataMessage {
dataQueue.offer(info);
}
public static void manageData(LjsdMongoTemplate myMongoTemplate) throws Exception {
Map<String, Map<String, MongoUpdateCache.UpdateRequest>> take = ConcurrentDataMessage.dataQueue.take();
myMongoTemplate.concurrentDataUpdate(take);
}
// public static void manageData(LjsdMongoTemplate myMongoTemplate) throws Exception {
//// Map<String, Map<String, MongoUpdateCache.UpdateRequest>> take = ConcurrentDataMessage.dataQueue.take();
//// myMongoTemplate.concurrentDataUpdate(take);
//// }
public static void main(String[] args) throws InterruptedException {
BlockingQueue<Map<String, String>> dataQueueTest = new BlockingUniqueQueue<>();

View File

@ -553,6 +553,15 @@ public class TimeUtils {
}
}
public static long stringToTimeLong2(String dateStr) {
try {
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
return dateFormat.parse(dateStr).getTime();
} catch (ParseException e) {
LOGGER.error("", e);
}
return now();
}
/**
* specTime is in [st,now] or not?
*

View File

@ -2,14 +2,23 @@ package com.ljsd;
import com.ljsd.jieling.core.GlobalsDef;
import com.ljsd.jieling.db.mongo.AreaManager;
import com.ljsd.jieling.db.redis.RedisKey;
import com.ljsd.jieling.db.redis.RedisUtil;
import com.mongodb.MongoClient;
import com.mongodb.MongoClientURI;
import org.springframework.data.redis.connection.jedis.JedisConnectionFactory;
import org.springframework.data.redis.core.Cursor;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.data.redis.core.ZSetOperations;
import java.io.*;
import java.net.URL;
import java.util.HashSet;
import java.util.List;
import java.util.Properties;
import java.util.Set;
public class DbClear {
public static void main(String[] args) throws IOException {
@ -20,11 +29,67 @@ public class DbClear {
System.out.println(file.getAbsolutePath());
properties.load(new FileReader(file));
String property = properties.getProperty("spring.data.mongodb.uri");
MongoClientURI mongoClientURI = new MongoClientURI(property);
MongoClient mongoClient = new MongoClient(mongoClientURI);
mongoClient.dropDatabase(mongoClientURI.getDatabase());
// MongoClientURI mongoClientURI = new MongoClientURI(property);
// MongoClient mongoClient = new MongoClient(mongoClientURI);
// mongoClient.dropDatabase(mongoClientURI.getDatabase());
StringRedisTemplate redisTemplate = getRedisTemplate();
redisTemplate.delete(redisTemplate.keys(properties.get("server.id")+"*"));
RedisUtil.getInstence().testTemp(redisTemplate);
// Set<String> keys = redisTemplate.keys(properties.get("server.id") + "*" + "RANK*");
// Set<String> keys = redisTemplate.scan(10161+ "*" + "RANK*");
Set<String> keys =new HashSet<>();
Cursor<String> cursor =RedisUtil.getInstence().scan( 10161+ "*" + "RANK*", 200);
while (cursor.hasNext()){
//找到一次就添加一次
keys.add(cursor.next());
}
cursor.close();
// redisTemplate.delete(redisTemplate.keys(properties.get("server.id")+"*"));
keys.forEach(k->{
// List<String> keyList = RedisUtil.getInstence().get(k, "", String.class, GlobalsDef.REDIS_OVER_FOREVER);
// List<String> keyListTarget = RedisUtil.getInstence().getListForNewArea(k, "", String.class, GlobalsDef.REDIS_OVER_FOREVER);
// if (!keyList.isEmpty()) {
// for (String heroTidInfo : keyList) {
// String useNum = RedisUtil.getInstence().redisGetValue(heroTidInfo);
// String heroTid = heroTidInfo.split(RedisKey.Delimiter_colon)[2];
// String key = newAreaId + RedisKey.Delimiter_colon + k + RedisKey.Delimiter_colon + heroTid;
// RedisUtil.getInstence().incrValue(key, Long.parseLong(useNum));
// if (!keyListTarget.contains(key)) {
// RedisUtil.getInstence().putListEntryForNewArea(k, "", key, 0, GlobalsDef.REDIS_OVER_FOREVER);
// }
// }
// }
// Long fightTimes = RedisUtil.getInstence().getObject(k,
// RedisKey.Fight_Times_Flag, Long.class, GlobalsDef.REDIS_OVER_FOREVER);
// String fightTimesKey = RedisUtil.getInstence().getKeyForArea(k, RedisKey.Fight_Times_Flag);
// if (fightTimes == null) {
// return;
// }
// RedisUtil.getInstence().incrValue(fightTimesKey, fightTimes);
Set<ZSetOperations.TypedTuple<String>> set= RedisUtil.getInstence().getAllZsetRange(k);
// if(k.startsWith("10161")){
// int length =k.length();
// k = "20161"+k.substring(String.valueOf("10161").length(),length);
// }
// if(null != set){
// for(ZSetOperations.TypedTuple<String> item : set){
// String id = item.getValue();
// Double score = item.getScore();
// RedisUtil.getInstence().zsetAddOne(k,id,score);
// }
// }
System.out.println("\r\nk = " + k+":"+set.size());
});
System.out.println("the mongo url=" + property);

View File

@ -4,6 +4,7 @@ import com.google.gson.Gson;
import com.ljsd.common.mogodb.util.MongoKeys;
import com.ljsd.jieling.config.json.CoreSettings;
import com.ljsd.jieling.core.CoreLogic;
import com.ljsd.jieling.db.mongo.AreaManager;
import com.ljsd.jieling.db.mongo.MongoUtil;
import com.ljsd.jieling.db.redis.RedisKey;
import com.ljsd.jieling.db.redis.RedisUtil;
@ -46,9 +47,10 @@ public class GameLogicService implements IService {
@Override
public void init() throws Exception {
RedisUtil.getInstence().init();
MongoUtil.getInstence().init();
MongoUtil.getLjsdMongoTemplate().getMongoTemplate().getCollection(User.getCollectionName()).createIndex("playerManager.level");
AreaManager.getInstance().init();
RedisUtil.getInstence().init();
MongoUtil.getLjsdMongoTemplate().getMongoTemplate(GameApplication.serverId).getCollection(User.getCollectionName()).createIndex("playerManager.level");
registerServerInfoToRedis();
}
@ -85,7 +87,7 @@ public class GameLogicService implements IService {
STableManager.initialize("config");
//mongo异步数据处理线程
MongoDataHandlerTask.init();
//MongoDataHandlerTask.init();
//初始化邮件
MailingSystemManager.init();

View File

@ -131,7 +131,7 @@ public class GmService implements RPCRequestGMIFace.Iface {
InnerMessageUtil.broadcastWithRandom( user->{
((GmRoleAbstract) obj).setUser(user);
obj.exec(parameters2);
}, sendIds, Math.min(randomTime, 120));
}, sendIds, Math.min(randomTime, 10));
} else {
LOGGER.info("gm________________________start"+cmd);
obj.exec(parameters);

View File

@ -1,9 +1,11 @@
package com.ljsd.jieling.core;
import com.ljsd.jieling.db.mongo.MongoUtil;
import com.ljsd.jieling.db.mongo.core.ServerAreaInfoManager;
import com.ljsd.jieling.logic.dao.SCdkInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.data.mongodb.core.MongoTemplate;
import java.util.HashMap;
import java.util.List;
@ -26,6 +28,12 @@ public class CoreLogic {
}
public ServerAreaInfoManager findServerArenaInfoManager() throws Exception{
MongoTemplate coreMongoTemplate =MongoUtil.getCoreMongoTemplate();
return coreMongoTemplate.findById(1,ServerAreaInfoManager.class);
}
public void checkCoreCdk() throws Exception{
try {
List<SCdkInfo> all = MongoUtil.getCoreMongoTemplate().findAll(SCdkInfo.class);
@ -49,4 +57,7 @@ public class CoreLogic {
public void setsCdkInfosCacheMap(Map<Integer, SCdkInfo> sCdkInfosCacheMap) {
this.sCdkInfosCacheMap = sCdkInfosCacheMap;
}
}

View File

@ -1,5 +1,6 @@
package com.ljsd.jieling.core.function;
import com.ljsd.GameApplication;
import com.ljsd.jieling.config.clazzStaticCfg.MapStaticConfig;
import com.ljsd.jieling.core.FunctionManager;
import com.ljsd.jieling.db.mongo.MongoUtil;
@ -15,6 +16,7 @@ import com.ljsd.jieling.protocols.MessageTypeProto;
import com.ljsd.jieling.util.MessageUtil;
import manager.STableManager;
import org.springframework.data.domain.Sort;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Query;
import java.util.List;
@ -38,7 +40,9 @@ public class EndlessFunction implements FunctionManager {
int level = calWorldLevel();
MapLogic.getInstance().updateEndlessSeason(timeControllerOfFunction.getTimes());
serverConfigTmp.setWorldLevel(level);
MongoUtil.getLjsdMongoTemplate().save(serverConfigTmp);
MongoTemplate otherMonogTemplate = MongoUtil.getInstence().getMonogTemplate(GameApplication.serverId);
otherMonogTemplate.save(serverConfigTmp);
MapLogic.getInstance().setEndlessMapId(GlobalDataManaager.getEndleeMapIdByLevel());
Map<Integer, ISession> onlineUserMap = OnlineUserManager.sessionMap;
MapInfoProto.EndlessMapChange info = MapInfoProto.EndlessMapChange.newBuilder().setMapId(MapLogic.getEndlessMapId()).setWorldLevel(level).build();

View File

@ -0,0 +1,277 @@
package com.ljsd.jieling.db.mongo;
import com.ljsd.GameApplication;
import com.ljsd.jieling.config.json.ServerProperties;
import com.ljsd.jieling.core.CoreLogic;
import com.ljsd.jieling.core.GlobalsDef;
import com.ljsd.jieling.db.mongo.core.ServerAreaInfo;
import com.ljsd.jieling.db.mongo.core.ServerAreaInfoManager;
import com.ljsd.jieling.db.redis.RedisKey;
import com.ljsd.jieling.db.redis.RedisUtil;
import com.ljsd.jieling.logic.dao.PlayerInfoCache;
import com.ljsd.jieling.util.ConfigurableApplicationContextManager;
import io.netty.util.internal.ConcurrentSet;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.data.redis.core.Cursor;
import org.springframework.data.redis.core.ZSetOperations;
import util.TimeUtils;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
/**
* Description: des
* Author: zsx
* CreateDate: 2020/8/14 22:55
*/
public class AreaManager {
private static final Logger LOGGER = LoggerFactory.getLogger(AreaManager.class);
//本服所属的区域 大区id位数一定要比serverid长若本服未进行划分那么serverid = arenaid
public static int areaId;
public static int newAreaId;
public static int masterServerId;
private static Set<Integer> serverIds = new ConcurrentSet<>();
public static ServerAreaInfoManager serverArenaInfoManagerCache;
public void init() {
initParm();
}
private static class Instance {
private final static AreaManager instance = new AreaManager();
}
public static AreaManager getInstance() {
return Instance.instance;
}
private void initParm() {
try {
int myServerId = GameApplication.serverProperties.getId();
areaId = myServerId;
masterServerId = myServerId;
serverIds.add(myServerId);
ServerAreaInfoManager serverArenaInfoManager = CoreLogic.getInstance().findServerArenaInfoManager();
if (serverArenaInfoManager != null) {
Integer areaIdTmp = serverArenaInfoManager.getAreaIdByServerIdMap().get(myServerId);
if (areaIdTmp != null) {
ServerAreaInfo serverAreaInfo = serverArenaInfoManager.getServerAreaInfoMap().get(areaIdTmp);
long execDate = TimeUtils.stringToTimeLong2(serverAreaInfo.getExecDate());
//防止动态加机器
if (System.currentTimeMillis() > execDate) {
masterServerId = serverAreaInfo.getMasterServerId();
areaId = areaIdTmp;
serverIds.clear();
serverIds.add(masterServerId);
serverIds.addAll(serverAreaInfo.getSlaveAreaIds());
}
}
serverArenaInfoManagerCache = serverArenaInfoManager;
}
} catch (Exception e) {
LOGGER.error("the exception {}", e);
}
}
public boolean processAddServerAreaIsChange() {
try {
ServerAreaInfoManager serverArenaInfoManager = CoreLogic.getInstance().findServerArenaInfoManager();
if (serverArenaInfoManager == null) {
return false;
}
if (serverArenaInfoManagerCache != null && serverArenaInfoManager.getVersion() == serverArenaInfoManagerCache.getVersion()) {
return false;
}
Map<Integer, ServerAreaInfo> serverAreaInfoMapFromDBCache = new HashMap<>();
if (serverArenaInfoManagerCache != null) {
serverAreaInfoMapFromDBCache = serverArenaInfoManagerCache.getServerAreaInfoMap();
}
boolean needAddRobotInRank = false;
ServerAreaInfo mineServerAreaInfo = null;
Map<Integer, ServerAreaInfo> serverAreaInfoMapFromDB = serverArenaInfoManager.getServerAreaInfoMap();
for (ServerAreaInfo serverAreaInfoDb : serverAreaInfoMapFromDB.values()) {
int version = serverAreaInfoDb.getVersion();
ServerAreaInfo serverAreaInfoCache = serverAreaInfoMapFromDBCache.get(serverAreaInfoDb.getAreaId());
if (serverAreaInfoCache != null && serverAreaInfoCache.getVersion() == version) {
continue;
}
Map<Integer, Integer> addServerOrAreaIds = serverAreaInfoDb.getAddServerOrAreaIds();
//大区吞并
if (serverAreaInfoCache != null) {
Set<Map.Entry<Integer, Integer>> entries = addServerOrAreaIds.entrySet();
for (Map.Entry<Integer, Integer> addServerOrAreaItem : entries) {
Integer serverOrArea = addServerOrAreaItem.getKey();
Integer type = addServerOrAreaItem.getValue();
//大区进行融合
if (type == 2) {
ServerAreaInfo serverAreaInfo = serverAreaInfoMapFromDB.get(serverOrArea);
if (serverAreaInfoCache.getVersion() >= serverAreaInfo.getVersion()) {
continue;
}
if (serverAreaInfo.getMasterServerId() == GameApplication.serverId) {
mineServerAreaInfo = serverAreaInfoDb;
}
}
}
} else {
//大区新建
int masterServerId = serverAreaInfoDb.getMasterServerId();
if (masterServerId == GameApplication.serverId) {
needAddRobotInRank = true;//主服
}
if (addServerOrAreaIds.keySet().contains(GameApplication.serverId)) {
mineServerAreaInfo = serverAreaInfoDb;//从服
}
}
}
// serverArenaInfoManagerCache = serverArenaInfoManager;
if (mineServerAreaInfo == null) {
serverArenaInfoManagerCache = serverArenaInfoManager;
return false;
}
newAreaId = mineServerAreaInfo.getAreaId();
long execDate = TimeUtils.stringToTimeLong2(mineServerAreaInfo.getExecDate());
if (System.currentTimeMillis() > execDate) {
serverArenaInfoManagerCache = serverArenaInfoManager;
int tmpAreaId = areaId;
//处理天才站结算
boolean isSuccess = RedisUtil.getInstence().tryGetDistributedLock(RedisKey.ServerArenaJob, Integer.toString(tmpAreaId), Integer.toString(tmpAreaId), 500);
if (isSuccess) {
LOGGER.info(" serverArenaInfoManager get redis lock,the serverid={},the oldArea={},the newArea={}", GameApplication.serverId, areaId, newAreaId);
try {
new Thread("sever_area_change") {
@Override
public void run() {
try {
}catch (Exception e) {
LOGGER.error(" serverArenaInfoManager get exception", e);
}
task();
}
}.start();
} catch (Exception e) {
LOGGER.error(" serverArenaInfoManager get exception", e);
} finally {
RedisUtil.getInstence().releaseDistributedLock(RedisKey.ServerArenaJob, Integer.toString(tmpAreaId), Integer.toString(tmpAreaId));
}
return true;
}
LOGGER.info(" serverArenaInfoManager not get redis lock,the serverid={},the oldArea={},the newArea={}", GameApplication.serverId, areaId, newAreaId);
serverStateReset();
return true;
}
} catch (Exception e) {
}
return false;
}
/**
*
*
*/
public void task() throws Exception {
LOGGER.info("the server={} exec task server work,start", GameApplication.serverId);
//合并排行榜
Set<String> keys =new HashSet<>();
Cursor<String> cursor =RedisUtil.getInstence().scan( GameApplication.serverId+ "*" + "RANK*", 200);
while (cursor.hasNext()){
//找到一次就添加一次
keys.add(cursor.next());
}
cursor.close();
keys.forEach(k->{
Set<ZSetOperations.TypedTuple<String>> set= RedisUtil.getInstence().getAllZsetRange(k);
String newKey = k;
if(k.startsWith(String.valueOf(GameApplication.serverId))){
int length =k.length();
newKey = newAreaId+k.substring(String.valueOf(GameApplication.serverId).length(),length);
}
if(null != set){
for(ZSetOperations.TypedTuple<String> item : set){
String id = item.getValue();
Double score = item.getScore();
RedisUtil.getInstence().zsetAddOne(newKey,id,score);
}
}
LOGGER.info("合并排行榜"+k+" --> "newKey);
});
//合并集合缓存、
Map<Integer, PlayerInfoCache> players = RedisUtil.getInstence().getMapValues(RedisKey.PLAYER_INFO_CACHE, "", Integer.class, PlayerInfoCache.class);
LOGGER.info("the server={} exec task server work,done", GameApplication.serverId);
}
private void serverStateReset() {
areaId = newAreaId;
resetMaster();
resetServerId(serverArenaInfoManagerCache.getServerAreaInfoMap().get(areaId));
LOGGER.info("the server={} exec task server work,done", GameApplication.serverId);
}
private void resetMaster() {
ServerAreaInfo serverAreaInfo = serverArenaInfoManagerCache.getServerAreaInfoMap().get(areaId);
masterServerId = serverAreaInfo.getMasterServerId();
}
private void resetServerId(ServerAreaInfo serverAreaInfo) {
serverIds.clear();
serverIds.add(masterServerId);
serverIds.addAll(serverAreaInfo.getSlaveAreaIds());
}
public boolean checkServerIdAllowPermit(int targetServerId) {
if (serverIds.contains(targetServerId)) {
return true;
}
LOGGER.error("the serverid={} can not allow permit,the current areaId={}", targetServerId, areaId);
return false;
}
public int getServerIdByUid(int uid, int defaultServerId) {
int serverId = defaultServerId;
Integer serverIdByUid = RedisUtil.getInstence().getMapEntry(RedisKey.CUser_ServerId_Key, "", Integer.toString(uid),
Integer.class);
if (serverIdByUid != null) {
return serverIdByUid;
}
serverIdByUid = MongoUtil.getInstence().findCUserServerId(uid);
if (serverIdByUid != null) {
serverId = serverIdByUid;
RedisUtil.getInstence().putMapEntry(RedisKey.CUser_ServerId_Key, "", Integer.toString(uid),
serverId);
} else {
return GameApplication.serverId;
}
return serverId;
}
}

View File

@ -0,0 +1,207 @@
package com.ljsd.jieling.db.mongo;
import com.ljsd.GameApplication;
import com.ljsd.common.mogodb.MongoUpdateCache;
import com.ljsd.common.mogodb.MongoUpdateCacheThreadLocal;
import com.ljsd.common.mogodb.MongoUpdateImp;
import com.ljsd.jieling.db.mongo.core.ServerAreaInfoManager;
import com.mongodb.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Query;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
public class LjsdMongoTemplate implements MongoUpdateImp {
private static final Logger LOGGER = LoggerFactory.getLogger(LjsdMongoTemplate.class);
// private MongoTemplate mongoTemplate;
public LjsdMongoTemplate( ){
// this.mongoTemplate = mongoTemplate;
}
// public DBCollection getCollection(String collectionName){
// return mongoTemplate.getCollection(collectionName);
// }
//注释
public <T> void save(int uid,T obj) throws Exception {
// MongoRoot root = (MongoRoot)obj;
// mongoTemplate.save(obj,root.getCollection());
// root.setBsave(true);
int serverIdByUid = AreaManager.getInstance().getServerIdByUid(Integer.valueOf(uid), GameApplication.serverId);
MongoTemplate otherMonogTemplate = getMongoTemplate(serverIdByUid);
otherMonogTemplate.save(obj);
}
public <T> void saveWithoutMongoRoot(T obj) throws Exception {
MongoTemplate monogTemplate = MongoUtil.getInstence().getMonogTemplate(GameApplication.serverId);
monogTemplate.save(obj);
}
public <T> List<T> findAll(String collectionName, Class<T> clazz) throws Exception {
List<T> list = new ArrayList<>();
ServerAreaInfoManager serverArenaInfoManagerCache = AreaManager.serverArenaInfoManagerCache;
if (serverArenaInfoManagerCache != null) {
Map<Integer, Integer> areaIdByServerIdMap = serverArenaInfoManagerCache.getAreaIdByServerIdMap();
for (Map.Entry<Integer, Integer> entry : areaIdByServerIdMap.entrySet()) {
if (entry.getValue() == AreaManager.areaId) {
MongoTemplate mongoTemplate = MongoUtil.mongoTemplateMap.get(entry.getKey());
if (mongoTemplate == null) {
LOGGER.info("findAll exception mongoTemplate == null serverId=>{}", entry.getKey());
continue;
}
List<T> all = mongoTemplate.findAll(clazz,collectionName);
list.addAll(all);
}
}
} else {
for (MongoTemplate mongoTemplate : MongoUtil.mongoTemplateMap.values()) {
List<T> all = mongoTemplate.findAll(clazz);
list.addAll(all);
}
}
return list;
//return mongoTemplate.findAll(clazz,collectionName);
}
public <T> List<T> findAllByCondition(Query query, Class<T> entityClass) throws Exception {
List<T> list = new ArrayList<>();
ServerAreaInfoManager serverArenaInfoManagerCache = AreaManager.serverArenaInfoManagerCache;
if (serverArenaInfoManagerCache != null) {
Map<Integer, Integer> areaIdByServerIdMap = serverArenaInfoManagerCache.getAreaIdByServerIdMap();
for (Map.Entry<Integer, Integer> entry : areaIdByServerIdMap.entrySet()) {
if (entry.getValue() == AreaManager.areaId) {
MongoTemplate mongoTemplate = MongoUtil.mongoTemplateMap.get(entry.getKey());
if (mongoTemplate == null) {
LOGGER.info("findAll exception mongoTemplate == null serverId=>{}", entry.getKey());
continue;
}
List<T> all = mongoTemplate.find(query, entityClass);
list.addAll(all);
}
}
} else {
for (MongoTemplate mongoTemplate : MongoUtil.mongoTemplateMap.values()) {
List<T> all = mongoTemplate.find(query, entityClass);
list.addAll(all);
}
}
return list;
// return mongoTemplate.find(query, entityClass);
}
public <T> T findById(String collectionName, String id, Class<T> clazz) throws Exception {
int serverIdByUid = AreaManager.getInstance().getServerIdByUid(Integer.valueOf(id), GameApplication.serverId);
MongoTemplate otherMonogTemplate = getMongoTemplate(serverIdByUid);
return otherMonogTemplate.findById(id,clazz,collectionName);
}
public <T> T findById(String collectionName, int id, Class<T> clazz) throws Exception {
int serverIdByUid = AreaManager.getInstance().getServerIdByUid(id, GameApplication.serverId);
MongoTemplate otherMonogTemplate = getMongoTemplate(serverIdByUid);
return otherMonogTemplate.findById(id,clazz,collectionName);
}
public <T> T findById(int id, Class<T> clazz) throws Exception {
int serverIdByUid = AreaManager.getInstance().getServerIdByUid(id, GameApplication.serverId);
MongoTemplate otherMonogTemplate = getMongoTemplate(serverIdByUid);
return otherMonogTemplate.findById(id,clazz);
}
// public void chnage(Object obj){
// Class<?> clazz = obj.getClass();
// }
//
// public boolean remove(Query query, String collection) throws Exception {
// getMongoTemplate(GameApplication.serverId).remove(query,collection);
// return true;
// }
// public void updateValue(String collectionName, BasicDBObject searchQuery, BasicDBObject dbObject){
// DBCollection coll = mongoTemplate.getCollection(collectionName);
// coll.update(searchQuery, dbObject);
// }
//非用户线程记得更新玩家数据
public void lastUpdate() throws Exception {
MongoUpdateCacheThreadLocal.update(this);
}
// public void concurrentDataUpdate(Map<String, Map<String, MongoUpdateCache.UpdateRequest>> updateRequestMap) throws Exception {
// MongoUpdateCacheThreadLocal.concurrentDataUpdate(this,updateRequestMap);
// }
//
//
// public Object convertToMongoType(Object obj){
// return this.mongoTemplate.getConverter().convertToMongoType(obj);
// }
//
public MongoTemplate getMongoTemplate(int serverId) {
MongoTemplate otherMonogTemplate = MongoUtil.getInstence().getMonogTemplate(serverId);
if (otherMonogTemplate == null) {
return null;
}
return otherMonogTemplate;
}
public void updateMongoData( Map<String, Map<String, MongoUpdateCache.UpdateRequest>> updateRequestMap) {
BasicDBObject searchQuery = new BasicDBObject();
for (Map.Entry<String, Map<String, MongoUpdateCache.UpdateRequest>> entry : updateRequestMap.entrySet()) {
String[] strs = entry.getKey().split(":");
String collection = strs[0];
String id = strs[1];
searchQuery.put("_id", Integer.parseInt(id));
BasicDBObject valueDBObj = new BasicDBObject();
BasicDBObject dbobj = new BasicDBObject();
BasicDBObject removedbobj = new BasicDBObject();
MongoTemplate otherMonogTemplate=null;
if(collection.equals("guildInfo")){
Integer guilderverId = MongoUtil.getInstence().findGuilderverId(Integer.valueOf(id));
otherMonogTemplate = MongoUtil.getInstence().getMonogTemplate(guilderverId);
}else {
int serverIdByUid = AreaManager.getInstance().getServerIdByUid(Integer.valueOf(id), GameApplication.serverId);
otherMonogTemplate = MongoUtil.getInstence().getMonogTemplate(serverIdByUid);
}
for (MongoUpdateCache.UpdateRequest request : entry.getValue().values()) {
if (request.opCode == 2) {
removedbobj.append(request.fullKey, request.value);
continue;
}
valueDBObj.append(request.fullKey, otherMonogTemplate.getConverter().convertToMongoType(request.value));
}
boolean flag = false;
if (!valueDBObj.isEmpty()) {
dbobj.append("$set", valueDBObj);
flag = true;
}
if (!removedbobj.isEmpty()) {
dbobj.append("$unset", removedbobj);
flag = true;
}
if (flag&&null!=otherMonogTemplate) {
DBCollection coll = otherMonogTemplate.getCollection(collection);
coll.update(searchQuery, dbobj);
}
}
}
}

View File

@ -1,8 +1,7 @@
package com.ljsd.jieling.db.mongo;
import com.ljsd.common.mogodb.LjsdMongoTemplate;
import com.ljsd.common.mogodb.MongoRootConverter;
import com.ljsd.common.mogodb.MongoSettingsProperties;
import com.mongodb.MongoClient;
import com.mongodb.MongoClientOptions;
import com.mongodb.MongoClientURI;
import org.springframework.beans.factory.annotation.Value;
@ -95,7 +94,7 @@ public class MongoConfig {
@Bean(name = "LjsdMongoTemplate")
public LjsdMongoTemplate ljsdMongoTemplate() throws Exception {
return new LjsdMongoTemplate(this.mongoTemplate());
return new LjsdMongoTemplate();
}
/**
@ -108,8 +107,14 @@ public class MongoConfig {
return new SimpleMongoDbFactory(new MongoClientURI(MONGO_CORE_URI));
}
@Bean(name = "coreMongoTemplate")
@Bean(value = "coreMongoTemplate")
public MongoTemplate coreMongoTemplate() throws Exception {
return new MongoTemplate(dbFactory2());
}
@Bean(value = "mongoClient")
public MongoClient mongoClient() throws Exception {
return new MongoClient(new MongoClientURI(MONGO_URI));
}
}

View File

@ -1,17 +1,22 @@
package com.ljsd.jieling.db.mongo;
import com.alibaba.fastjson.JSON;
import com.fasterxml.jackson.core.type.TypeReference;
import com.google.gson.*;
import com.google.gson.reflect.TypeToken;
import com.ljsd.common.mogodb.LjsdMongoTemplate;
import com.ljsd.GameApplication;
import com.ljsd.jieling.db.mongo.core.CServerInfo;
import com.ljsd.jieling.logic.OnlineUserManager;
import com.ljsd.jieling.logic.dao.root.GuildInfo;
import com.ljsd.jieling.logic.dao.root.User;
import com.ljsd.jieling.util.ConfigurableApplicationContextManager;
import com.ljsd.jieling.util.InnerMessageUtil;
import com.ljsd.jieling.util.SysUtil;
import io.netty.util.internal.MathUtil;
import com.mongodb.BasicDBObject;
import com.mongodb.DBObject;
import com.mongodb.MongoClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.data.annotation.Transient;
import org.springframework.data.mongodb.core.query.BasicQuery;
import util.MathUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -19,6 +24,7 @@ import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import javax.annotation.Resource;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
@ -26,7 +32,6 @@ import java.io.PrintWriter;
import java.lang.reflect.Type;
import java.net.UnknownHostException;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
public class MongoUtil {
@ -37,6 +42,7 @@ public class MongoUtil {
private static int MAX_TRY_TIMES = 3; //最大尝试次数,保障获取/存储成功
private static int FAILED_SLEEP = 2; //每次失败最大停顿时间
private MongoUtil() {
}
@ -48,14 +54,26 @@ public class MongoUtil {
private static final MongoUtil instance = new MongoUtil();
}
private LjsdMongoTemplate myMongoTemplate;
public static Map<Integer,MongoTemplate> mongoTemplateMap = new HashMap<>();
public static Map<Integer,Integer> guild2serverid= new HashMap<>();
private MongoClient mongoClient;
private LjsdMongoTemplate myMongoTemplate;
private MongoTemplate coreMongoTemplate;
public void init() {
myMongoTemplate = ConfigurableApplicationContextManager.getBean(LjsdMongoTemplate.class);
coreMongoTemplate = (MongoTemplate) ConfigurableApplicationContextManager.getBean("coreMongoTemplate");
mongoClient = (MongoClient) ConfigurableApplicationContextManager.getBean("mongoClient");
List<CServerInfo> cServerInfos = coreMongoTemplate.findAll(CServerInfo.class);
for (CServerInfo cServerInfo : cServerInfos) {
getMonogTemplate(cServerInfo.getServerId());
}
}
public LjsdMongoTemplate getMyMongoTemplate() {
@ -90,7 +108,6 @@ public class MongoUtil {
}
public static MongoTemplate getCoreMongoTemplate() throws UnknownHostException {
return MongoUtil.getInstence().coreMongoTemplate;
}
@ -246,4 +263,54 @@ public class MongoUtil {
}
public Integer findCUserServerId(int uid){
BasicQuery basicQuery = new BasicQuery(new BasicDBObject("userId", uid),new BasicDBObject("serverid", 1));
DBObject c_user_info = coreMongoTemplate.findOne(basicQuery, DBObject.class, "c_user_info");
if(c_user_info == null){
LOGGER.error("the user={} not exists",uid);
return null;
}
Long serverid = (Long)c_user_info.get("serverid");
if(serverid == null){
return null;
}
return serverid.intValue();
}
public Integer findGuilderverId(int guildId){
if(guild2serverid.containsKey(guildId)){
return guild2serverid.get(guildId);
}else {
guild2serverid.put(guildId, GameApplication.serverId);
return GameApplication.serverId;
}
}
//初始化 数据库映射 公会server映射
public MongoTemplate getMonogTemplate(int serverId){
if(!AreaManager.getInstance().checkServerIdAllowPermit(serverId)){
return null;
}
MongoTemplate mongoTemplate = mongoTemplateMap.get(serverId);
if(mongoTemplate == null){
String dbName = "jl_"+serverId;
mongoTemplate = new MongoTemplate(mongoClient, dbName);
mongoTemplateMap.put(serverId,mongoTemplate);
List<GuildInfo> all = mongoTemplate.findAll(GuildInfo.class, GuildInfo._COLLECTION_NAME);
for (GuildInfo guildInfo:all) {
guild2serverid.put(guildInfo.getId(),serverId);
}
}
return mongoTemplate;
}
}

View File

@ -1,28 +1,11 @@
package com.ljsd.jieling.db.mongo;
import com.alibaba.fastjson.JSON;
import com.google.gson.*;
import com.ljsd.common.mogodb.LjsdMongoTemplate;
import com.ljsd.jieling.logic.OnlineUserManager;
import com.ljsd.jieling.logic.dao.root.User;
import com.ljsd.jieling.util.ConfigurableApplicationContextManager;
import com.ljsd.jieling.util.InnerMessageUtil;
import com.ljsd.jieling.util.SysUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.data.annotation.Transient;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import util.MathUtils;
import java.io.*;
import java.lang.reflect.Type;
import java.net.UnknownHostException;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.*;
public class MongoUtiltest {

View File

@ -0,0 +1,31 @@
package com.ljsd.jieling.db.mongo.core;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.Document;
import org.springframework.data.mongodb.core.mapping.Field;
@Document(collection = "server_info")
public class CServerInfo {
@Id
private int id;
@Field(value = "server_id")
private int serverId;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public int getServerId() {
return serverId;
}
public void setServerId(int serverId) {
this.serverId = serverId;
}
}

View File

@ -0,0 +1,107 @@
package com.ljsd.jieling.db.mongo.core;
import org.springframework.data.mongodb.core.mapping.Field;
import java.util.List;
import java.util.Map;
public class ServerAreaInfo {
@Field(value = "version")
private int version;
@Field(value = "area_id")
private int areaId;
@Field(value = "mater_serverId")
private int masterServerId;
@Field(value = "slave_ids")
private List<Integer> slaveServerIds ;
@Field(value = "slave_area_ids")
private List<Integer> slaveAreaIds; //不入库 只做解析用
@Field(value = "add_serverOrArea_ids")
private Map<Integer,Integer> addServerOrAreaIds; //key: serverid or areaid value: type : 类型 1 serverid 2 areaid
@Field(value = "pre_date")
private String preDate;
@Field(value = "exec_date")
private String execDate;
@Field(value = "flag")
private boolean flag ;
public int getVersion() {
return version;
}
public void setVersion(int version) {
this.version = version;
}
public int getAreaId() {
return areaId;
}
public void setAreaId(int areaId) {
this.areaId = areaId;
}
public int getMasterServerId() {
return masterServerId;
}
public void setMasterServerId(int masterServerId) {
this.masterServerId = masterServerId;
}
public List<Integer> getSlaveServerIds() {
return slaveServerIds;
}
public void setSlaveServerIds(List<Integer> slaveServerIds) {
this.slaveServerIds = slaveServerIds;
}
public List<Integer> getSlaveAreaIds() {
return slaveAreaIds;
}
public void setSlaveAreaIds(List<Integer> slaveAreaIds) {
this.slaveAreaIds = slaveAreaIds;
}
public Map<Integer, Integer> getAddServerOrAreaIds() {
return addServerOrAreaIds;
}
public void setAddServerOrAreaIds(Map<Integer, Integer> addServerOrAreaIds) {
this.addServerOrAreaIds = addServerOrAreaIds;
}
public String getPreDate() {
return preDate;
}
public void setPreDate(String preDate) {
this.preDate = preDate;
}
public String getExecDate() {
return execDate;
}
public void setExecDate(String execDate) {
this.execDate = execDate;
}
public boolean isFlag() {
return flag;
}
public void setFlag(boolean flag) {
this.flag = flag;
}
}

View File

@ -0,0 +1,59 @@
package com.ljsd.jieling.db.mongo.core;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.Document;
import org.springframework.data.mongodb.core.mapping.Field;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
/**
*
*/
@Document(collection = "server_area_manager")
public class ServerAreaInfoManager {
@Id
private int id;
@Field(value = "version")
private int version;
@Field(value = "server_area_map")
private Map<Integer, ServerAreaInfo> serverAreaInfoMap = new ConcurrentHashMap<>();
@Field(value = "server_area_id")
private Map<Integer,Integer> areaIdByServerIdMap = new ConcurrentHashMap<>();
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public int getVersion() {
return version;
}
public void setVersion(int version) {
this.version = version;
}
public Map<Integer, ServerAreaInfo> getServerAreaInfoMap() {
return serverAreaInfoMap;
}
public void setServerAreaInfoMap(Map<Integer, ServerAreaInfo> serverAreaInfoMap) {
this.serverAreaInfoMap = serverAreaInfoMap;
}
public Map<Integer, Integer> getAreaIdByServerIdMap() {
return areaIdByServerIdMap;
}
public void setAreaIdByServerIdMap(Map<Integer, Integer> areaIdByServerIdMap) {
this.areaIdByServerIdMap = areaIdByServerIdMap;
}
}

View File

@ -8,10 +8,16 @@ import java.util.Set;
public class RedisKey {
public final static String Delimiter_colon = ":";
private final static String areaId = "0";
//合服
public final static String ServerArenaJob = "ServerArenaJob_key";
public static final String TOKEN = "JL_TOKEN";
/**
@ -21,16 +27,14 @@ public class RedisKey {
public static final String UNDERLINE_LINE = "_";
/**
*
*/
public static final String MAP_RANK = "JL_MAP_RANK";
/**
*
*/
public static final String USER_SERVER_INFO = "JL_USER_SERVER_INFO";
public final static String CUser_ServerId_Key = "CUser_ServerId"; //服务器缓存
/**
*
*/
@ -99,13 +103,11 @@ public class RedisKey {
public static final String ARENA_RRECORD = "ARENA_RRECORD";
public static final String ARENA_RANK = "ARENA_RANK";
public static final String ADVENTRUEN_BOSS_OWN = "ADVENTRUEN_BOSS_OWN";
public static final String ADVENTRUEN_BOSS_INFO = "ADVENTRUEN_BOSS_INFO";
public static final String ADVENTRUEN_BOSS_RANK = "ADVENTRUEN_BOSS_RANK";
public static final String ADVENTRUEN_BOSS_HURT_DETAIL = "ADVENTRUEN_BOSS_HURT_DETAIL";
@ -123,27 +125,8 @@ public class RedisKey {
public static final String USER_LOGIN_URL = "USER_LOGIN_URL:";
public static final String TOWER_RANK = "TOWER_RANK";
public static final String FORCE_RANK = "FORCE_RANK";
public static final String AREDEF_TEAM_FORCE_RANK = "AREDEF_TEAM_FORCE_RANK";
public static final String EXPERT_RANK = "EXPERT_RANK";
public static final String FORCE_CURR_RANK = "FORCE_CURR_RANK";
public static final String MAIN_LEVEL_RANK = "MAIN_LEVEL_RANK";
public static final String RANDOM_CARD_RANK="RANDOM_CARD_RANK";
public static final String RANDOM_CARD_PERFECT_RANK = "RANDOM_CARD_PERFECT_RANK";
public static final String GUILD_FORCE_RANK = "GUILD_FORCE_RANK";
public static final String GUILD_BOSS_RANK = "GUILD_BOSS_RANK";
public static final String GUILD_RED_PACKAGE_RANK = "GUILD_RED_PACKAGE_RANK";
public static final String CAR_DEALY_RANK = "CAR_DEALY_RANK";
public static final String CAR_DEALY_PLAY = "CAR_DEALY_PLAY";
public static final String CAR_DEALY_GUILD_RANK = "CAR_DEALY_GUILD_RANK";
public static final String FAMILY_ID = "FAMILY_ID";
@ -155,8 +138,6 @@ public class RedisKey {
public static final String FAMILY_ATTACK_BLOOD = "FAMILY_ATTACK_BLOOD";
public static final String FAMILY_FIGHT_RANK = "FAMILY_FIGHT_RANK";
public static final String FAMILY_FIGHT_MATCHING_RANK ="FAMILY_FIGHT_MATCHING_RANK";
//公会战进攻获得星数排行榜
public static final String FAMILY_FIGHT_STAR_RANK = "FAMILY_FIGHT_STAR_RANK";
//公会战击破建筑星数
public static final String FAMILY_FIGHT_EXTRA_STAR = "FAMILY_FIGHT_EXTRA_STAR";
//公会战公会统计
@ -185,7 +166,6 @@ public class RedisKey {
public static final String OPERATE_FAMILY_APPLY = "OPERATE_FAMILY_APPLY";
public static final String OPERATE_FAMILY_APPLY_JOIN = "OPERATE_FAMILY_APPLY_JOIN";
public static final String MONSTER_ATTACK_RANK = "MONSTER_ATTACK_RANK";
//掉线缓存indication
public static final String INDICATION_OFFLINE = "INDICATION_OFFLINE";
@ -197,7 +177,7 @@ public class RedisKey {
public static final String SESSION_OFFLINE = "SESSION_OFFLINE";
public static final String PLAYER_INFO_CACHE = "PLAYER_INFO_CACHE";
//问卷调查
public static final String QUESTION_FROMBACK = "QUESTION_FROMBACK";
@ -209,7 +189,7 @@ public class RedisKey {
public static final String MATCH_SERVER_INFO = "MATCH_SERVER_INFO";
public static final String LOGIC_SERVER_INFO = "LOGIC_SERVER_INFO";
public static final String BLOODY_SERVER_INFO = "BLOODY_SERVER_INFO";
public static final String SYSMSG = "SYSMSG";
public static final String AUTOOPENTIME = "AUTOOPENTIME";
public final static String CDKEY = "CDKEY";
@ -251,16 +231,8 @@ public class RedisKey {
public final static String ACTIVITY_GIFT_LIMIT = "ACTIVITY_GIFT_LIMIT"; //活动礼包个数限制
public static final String DEATH_PATH_EVERY_PERSON_RANK = "DEATH_PATH_EVERY_PERSON_RANK";
public static final String DEATH_PATH_EVERY_GUILD_RANK = "DEATH_PATH_EVERY_GUILD_RANK";
public static final String DEATH_PATH_CHALLENGE_COUNT = "DEATH_PATH_CHALLENGE_COUNT";
public static final String DEATH_PATH_TOTAL_PERSON_RANK = "DEATH_PATH_TOTAL_PERSON_RANK";
public static final String DEATH_PATH_TOTAL_GUILD_RANK = "DEATH_PATH_TOTAL_GUILD_RANK";
public static final String DEATH_PAHT_TOTAL_CHALLENGE_COUNT = "DEATH_PAHT_TOTAL_CHALLENGE_COUNT";
@ -274,7 +246,56 @@ public class RedisKey {
public static final String MAIL_RED_POINT = "MAIL_RED_POINT";//全服红点加入
//排行榜
public static final String SYSMSG = "SYSMSG";//????
public static final String MAP_RANK = "JL_MAP_RANK";
public static final String ARENA_RANK = "ARENA_RANK";
public static final String ADVENTRUEN_BOSS_RANK = "ADVENTRUEN_BOSS_RANK";
public static final String TOWER_RANK = "TOWER_RANK";
public static final String FORCE_RANK = "FORCE_RANK";
public static final String AREDEF_TEAM_FORCE_RANK = "AREDEF_TEAM_FORCE_RANK";
public static final String EXPERT_RANK = "EXPERT_RANK";
public static final String FORCE_CURR_RANK = "FORCE_CURR_RANK";
public static final String MAIN_LEVEL_RANK = "MAIN_LEVEL_RANK";
public static final String RANDOM_CARD_RANK="RANDOM_CARD_RANK";
public static final String RANDOM_CARD_PERFECT_RANK = "RANDOM_CARD_PERFECT_RANK";
public static final String GUILD_FORCE_RANK = "GUILD_FORCE_RANK";
public static final String GUILD_BOSS_RANK = "GUILD_BOSS_RANK";
public static final String GUILD_RED_PACKAGE_RANK = "GUILD_RED_PACKAGE_RANK";
public static final String CAR_DEALY_RANK = "CAR_DEALY_RANK";
public static final String CAR_DEALY_GUILD_RANK = "CAR_DEALY_GUILD_RANK";
//公会战进攻获得星数排行榜
public static final String FAMILY_FIGHT_STAR_RANK = "FAMILY_FIGHT_STAR_RANK";
public static final String MONSTER_ATTACK_RANK = "MONSTER_ATTACK_RANK";//兽潮
public static final String DEATH_PATH_EVERY_PERSON_RANK = "DEATH_PATH_EVERY_PERSON_RANK";
public static final String DEATH_PATH_EVERY_GUILD_RANK = "DEATH_PATH_EVERY_GUILD_RANK";
public static final String DEATH_PATH_TOTAL_PERSON_RANK = "DEATH_PATH_TOTAL_PERSON_RANK";
public static final String DEATH_PATH_TOTAL_GUILD_RANK = "DEATH_PATH_TOTAL_GUILD_RANK";
public static final String SITUATION_RANK = "SITUATION_RANK";
public static Set<String> familyKey = new HashSet<>();
static {
familyKey.add(ADVENTRUEN_BOSS_CHALLENGE_LOCK_KEY);
familyKey.add(OPERATE_FAMILY);

View File

@ -4,16 +4,17 @@ import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.ljsd.GameApplication;
import com.ljsd.common.mogodb.util.GlobalData;
import com.ljsd.jieling.db.mongo.AreaManager;
import com.ljsd.jieling.util.ConfigurableApplicationContextManager;
import org.springframework.data.redis.RedisConnectionFailureException;
import org.springframework.data.redis.core.*;
import org.springframework.data.redis.serializer.RedisSerializer;
import util.StringUtil;
import util.TimeUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.data.redis.connection.RedisConnection;
import org.springframework.data.redis.connection.ReturnType;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.data.redis.core.ZSetOperations;
import org.springframework.util.CollectionUtils;
import redis.clients.jedis.Protocol;
@ -54,7 +55,17 @@ public class RedisUtil {
putMapEntry(RedisKey.FAMILY_FIGHT_FINISH_MATCHING,"",String.valueOf(GameApplication.serverId),states);
}
public void testTemp(StringRedisTemplate redisTemplat){
redisTemplate = redisTemplat;
}
public Cursor<String> scan(String match, int count){
ScanOptions scanOptions = ScanOptions.scanOptions().match(match).count(count).build();
RedisSerializer<String> redisSerializer = (RedisSerializer<String>) redisTemplate.getKeySerializer();
return (Cursor) redisTemplate.executeWithStickyConnection((RedisCallback) redisConnection ->
new ConvertingCursor<>(redisConnection.scan(scanOptions), redisSerializer::deserialize));
}
/**
*
*
@ -866,6 +877,16 @@ public class RedisUtil {
return null;
}
public Set<ZSetOperations.TypedTuple<String>> getAllZsetRange(String key){
for (int i = 0; i < MAX_TRY_TIMES; i++) {
try {
return redisTemplate.opsForZSet().rangeWithScores(key, 0, -1);
} catch (Exception e) {
TimeUtils.sleep(FAILED_SLEEP);
}
}
return null;
}
public Set<ZSetOperations.TypedTuple<String>> rangeByScoreWithScores(String type,String key, double start, double end){
String rkey = getKey(type, key);
@ -1186,14 +1207,14 @@ public class RedisUtil {
||RedisKey.FAMILY_INFO.equals(type)||RedisKey.PIDGIDTEMP.equals(type)) {
return type + RedisKey.Delimiter_colon + key;
}
if(RedisKey.familyKey.contains(type)){
return GameApplication.serverProperties.getAreaId()+ RedisKey.Delimiter_colon+type + RedisKey.Delimiter_colon+key;
}
// if(RedisKey.familyKey.contains(type)){
// return GameApplication.serverProperties.getAreaId()+ RedisKey.Delimiter_colon+type + RedisKey.Delimiter_colon+key;
// }
if(RedisKey.TOKEN.equals(type)||RedisKey.USER_SERVER_INFO.equals(type)||
RedisKey.CDKEY.equals(type)){
return type + RedisKey.Delimiter_colon + key;
}
return GameApplication.serverId + RedisKey.Delimiter_colon + type + RedisKey.Delimiter_colon + key;
return AreaManager.areaId+ RedisKey.Delimiter_colon + type + RedisKey.Delimiter_colon + key;
}

View File

@ -39,7 +39,7 @@ public class Cmd_changename extends GmRoleAbstract {
User user = getUser();
if("hotfix".equals(args[2])){
LOGGER.info("hotfix user={},thread={}",user.getId(),Thread.currentThread().getName());
MongoUtil.getLjsdMongoTemplate().save(user);
// MongoUtil.getLjsdMongoTemplate().save(user);
}
if("force".equals(args[2])){
int teamForce = HeroLogic.getInstance().calTeamTotalForce(user, 1, false);

View File

@ -20,7 +20,7 @@ public class Cmd_fixindb extends GmAbstract{
AyyncWorker ayyncWorker = new AyyncWorker(userInMem, true, new AyncWorkerRunnable() {
@Override
public void work(User user) throws Exception {
MongoUtil.getLjsdMongoTemplate().save(user);
MongoUtil.getLjsdMongoTemplate().save(user.getId(),user);
}
});
ProtocolsManager.getInstance().updateAyncWorker(ayyncWorker);

View File

@ -1,20 +1,14 @@
package com.ljsd.jieling.kefu;
import com.google.gson.Gson;
import com.ljsd.common.mogodb.LjsdMongoTemplate;
import com.ljsd.jieling.db.mongo.LjsdMongoTemplate;
import com.ljsd.jieling.db.mongo.MongoUtil;
import com.ljsd.jieling.logic.dao.root.User;
import com.ljsd.jieling.logic.item.ItemLog;
import config.SMainLevelConfig;
import manager.STableManager;
import org.springframework.data.domain.Sort;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import java.io.FileWriter;
import java.io.IOException;
import java.util.*;
import java.util.concurrent.atomic.AtomicInteger;
public class Cmd_out_cfg extends GmAbstract {
@Override

View File

@ -52,6 +52,7 @@ import config.SRechargeCommodityConfig;
import manager.STableManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.data.mongodb.core.MongoTemplate;
import util.TimeUtils;
import java.util.*;
@ -177,7 +178,8 @@ public class GlobalDataManaager implements IManager {
}
if(needUpdate){
MongoUtil.getInstence().getMyMongoTemplate().save(globalSystemControl);
MongoTemplate otherMonogTemplate = MongoUtil.getInstence().getMonogTemplate(GameApplication.serverId);
otherMonogTemplate.save(globalSystemControl);
openAction(reallyOpenList);
}
closeAction(closeList);

View File

@ -1,5 +1,6 @@
package com.ljsd.jieling.logic.dao;
import com.ljsd.GameApplication;
import com.ljsd.jieling.db.mongo.MongoUtil;
import com.ljsd.jieling.db.redis.RedisKey;
import com.ljsd.jieling.db.redis.RedisUtil;
@ -10,6 +11,7 @@ import com.ljsd.jieling.logic.dao.root.User;
import com.ljsd.jieling.logic.family.GuildLogic;
import com.mongodb.BasicDBObject;
import config.SGuildSetting;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.BasicQuery;
import org.springframework.data.redis.core.ZSetOperations;
@ -22,7 +24,11 @@ public class GuilidManager {
public static Map<Integer,List<GuildLog>> guildLogInfoMap = new HashMap<>();
public static void addGuildInfo(GuildInfo guildInfo) throws Exception {
MongoUtil.getInstence().getMyMongoTemplate().save(guildInfo);
Integer guilderverId = MongoUtil.getInstence().findGuilderverId(guildInfo.getId());
MongoTemplate otherMonogTemplate = MongoUtil.getInstence().getMonogTemplate(guilderverId);
otherMonogTemplate.save(guildInfo);
// MongoUtil.getInstence().getMyMongoTemplate().save(guildInfo);
guildInfoMap.put(guildInfo.getId(),guildInfo);
guildNameInfoMap.put(guildInfo.getName(),guildInfo);
}
@ -32,8 +38,11 @@ public class GuilidManager {
guildInfoMap.remove(guildId);
guildNameInfoMap.remove(guildInfo.getName());
guildLogInfoMap.remove(guildId);
MongoUtil.getInstence().getMyMongoTemplate().remove(new BasicQuery(new BasicDBObject("_id",guildId)),"guildInfo");
MongoUtil.getInstence().getMyMongoTemplate().remove(new BasicQuery(new BasicDBObject("guildId",guildId)),"guildLog");
Integer guilderverId = MongoUtil.getInstence().findGuilderverId(guildId);
MongoTemplate otherMonogTemplate = MongoUtil.getInstence().getMonogTemplate(guilderverId);
otherMonogTemplate.remove(new BasicQuery(new BasicDBObject("_id",guildId)),"guildInfo");
otherMonogTemplate.remove(new BasicQuery(new BasicDBObject("guildId",guildId)),"guildLog");
}
public static void addApplyGuildInfo(GuildApply guildApply){
@ -60,7 +69,10 @@ public class GuilidManager {
}
public static void addGuildLog(GuildLog guildLog) throws Exception {
MongoUtil.getInstence().getMyMongoTemplate().save(guildLog);
Integer guilderverId = MongoUtil.getInstence().findGuilderverId(guildLog.getGuildId());
MongoTemplate otherMonogTemplate = MongoUtil.getInstence().getMonogTemplate(guilderverId);
otherMonogTemplate.save(guildLog);
// MongoUtil.getInstence().getMyMongoTemplate().save(guildLog);
if(!guildLogInfoMap.containsKey(guildLog.getGuildId())){
guildLogInfoMap.put(guildLog.getGuildId(),new ArrayList<>());
}

View File

@ -5,6 +5,7 @@ import com.ljsd.GameApplication;
import com.ljsd.jieling.db.mongo.MongoUtil;
import com.ljsd.jieling.logic.dao.root.MailingSystem;
import com.ljsd.jieling.logic.mail.MailLogic;
import org.springframework.data.mongodb.core.MongoTemplate;
import util.TimeUtils;
import java.util.ArrayList;
@ -34,7 +35,10 @@ public class MailingSystemManager {
public static void addMailingSystem(MailingSystem mailingSystem) throws Exception {
mailingSystemMap.put(Integer.valueOf(mailingSystem.getId()), mailingSystem);
MongoUtil.getInstence().getMyMongoTemplate().save(mailingSystem);
MongoTemplate otherMonogTemplate = MongoUtil.getInstence().getMonogTemplate(GameApplication.serverId);
otherMonogTemplate.save(mailingSystem);
// MongoUtil.getInstence().getMyMongoTemplate().save(mailingSystem);
}
public static boolean isUserExist(int id) {

View File

@ -3,6 +3,7 @@ package com.ljsd.jieling.logic.dao;
import com.ljsd.jieling.config.clazzStaticCfg.CommonStaticConfig;
import com.ljsd.jieling.core.GlobalsDef;
import com.ljsd.jieling.db.mongo.AreaManager;
import com.ljsd.jieling.db.mongo.MongoUtil;
import com.ljsd.jieling.globals.BIReason;
import com.ljsd.jieling.ktbeans.KtEventUtils;
@ -92,7 +93,7 @@ public class UserManager {
User user = new User(uid);
UserManager.addUser(user);
initPlayer(user,openId,channel,pid,gid,platform,ip,channle_id,bundle_id);
MongoUtil.getInstence().getMyMongoTemplate().save(user);
MongoUtil.getInstence().getMyMongoTemplate().save(user.getId(),user);
PlayerLogic.getInstance().sendTestWelfareMail(user,1,1);
return user;
}
@ -149,6 +150,8 @@ public class UserManager {
int force = HeroLogic.getInstance().calTeamTotalForce(user, 1, true);
playerManager.setMaxForce(force);
user.getExpeditionManager().setExpeditionLeve(1);
// user.getExpeditionManager().setForceSnap(force);
// KtEventUtils.onKtEvent(user, ParamEventBean.UserRegister);
}

View File

@ -5,6 +5,7 @@ import com.ljsd.jieling.db.mongo.MongoUtil;
import com.ljsd.jieling.logic.dao.Question;
import com.ljsd.jieling.logic.dao.TimeControllerOfFunction;
import org.springframework.data.annotation.Transient;
import org.springframework.data.mongodb.core.MongoTemplate;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
@ -74,7 +75,9 @@ public class GlobalSystemControl {
public static void save(GlobalSystemControl globalSystemControl) throws Exception {
if (globalSystemControl.dirty) {
MongoUtil.getInstence().getMyMongoTemplate().save(globalSystemControl);
MongoTemplate otherMonogTemplate = MongoUtil.getInstence().getMonogTemplate(GameApplication.serverId);
otherMonogTemplate.save(globalSystemControl);
// MongoUtil.getInstence().getMyMongoTemplate().save(globalSystemControl);
}
}

View File

@ -1,8 +1,6 @@
package com.ljsd.jieling.logic.dao.root;
import com.ljsd.GameApplication;
import com.ljsd.common.mogodb.LjsdMongoTemplate;
import com.ljsd.common.mogodb.MongoRoot;
import com.ljsd.jieling.logic.dao.AutoIncrementManager;
import com.ljsd.jieling.logic.dao.SysMailManager;
import com.ljsd.jieling.logic.dao.SystemMailManager;

View File

@ -1,8 +1,10 @@
package com.ljsd.jieling.logic.item;
import com.ljsd.GameApplication;
import com.ljsd.GameLogicService;
import com.ljsd.common.mogodb.util.BlockingUniqueQueue;
import com.ljsd.jieling.db.mongo.MongoUtil;
import org.springframework.data.mongodb.core.MongoTemplate;
import java.util.ArrayList;
import java.util.List;
@ -22,7 +24,9 @@ public class ItemLogUtil {
if(sendDataList.size()>0){
for(ItemLog data:sendDataList){
try {
MongoUtil.getInstence().getMyMongoTemplate().save(data);
MongoTemplate otherMonogTemplate = MongoUtil.getInstence().getMonogTemplate(GameApplication.serverId);
otherMonogTemplate.save(data);
// MongoUtil.getInstence().getMyMongoTemplate().save(data);
} catch (Exception e) {
e.printStackTrace();
}

View File

@ -17,6 +17,7 @@ import com.ljsd.jieling.util.InnerMessageUtil;
import com.ljsd.jieling.util.MessageUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.data.mongodb.core.MongoTemplate;
import java.util.*;
@ -133,7 +134,9 @@ public class QuestionLogic {
}
if (isNeedUp) {
MongoUtil.getInstence().getMyMongoTemplate().save(globalSystemControl);
MongoTemplate otherMonogTemplate = MongoUtil.getInstence().getMonogTemplate(GameApplication.serverId);
otherMonogTemplate.save(globalSystemControl);
// MongoUtil.getInstence().getMyMongoTemplate().save(globalSystemControl);
}
//remove
for (Integer id : remove) {

View File

@ -7,6 +7,7 @@ import com.ljsd.jieling.core.CoreLogic;
import com.ljsd.jieling.core.GlobalsDef;
import com.ljsd.jieling.core.Lockeys;
import com.ljsd.jieling.core.SimpleTransaction;
import com.ljsd.jieling.db.mongo.AreaManager;
import com.ljsd.jieling.db.mongo.MongoUtil;
import com.ljsd.jieling.db.redis.RedisKey;
import com.ljsd.jieling.db.redis.RedisUtil;
@ -64,6 +65,7 @@ public class MinuteTask extends Thread {
HotfixUtil.getInstance();
Poster.getPoster().dispatchEvent(new MinuteTaskEvent());
AreaManager.getInstance().processAddServerAreaIsChange();
MessageUtil.checkAndSendMsg();
STableManager.updateTablesWithTableNames(true);
ActivityLogic.getInstance().checkSecretBoxSeason();

View File

@ -1,6 +1,6 @@
package com.ljsd.jieling.thread.task;
import com.ljsd.common.mogodb.LjsdMongoTemplate;
import com.ljsd.jieling.db.mongo.LjsdMongoTemplate;
import com.ljsd.common.mogodb.util.ConcurrentDataMessage;
import com.ljsd.jieling.util.ConfigurableApplicationContextManager;
import org.springframework.stereotype.Component;
@ -9,30 +9,30 @@ import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
@Component
public class MongoDataHandlerTask extends Thread {
private static LjsdMongoTemplate myMongoTemplate;
public MongoDataHandlerTask(){
setName("MongoDataHandlerTask");
}
@Override
public void run() {
while (true) {
try {
ConcurrentDataMessage.manageData(myMongoTemplate);
} catch (Exception e) {
e.printStackTrace();
}
}
}
public static void init(){
myMongoTemplate = ConfigurableApplicationContextManager.getBean(LjsdMongoTemplate.class);
// startTlogThread();
}
public static void startTlogThread(){
ExecutorService pool = Executors.newCachedThreadPool();
for (int i = 0; i < 1 ; i++){
MongoDataHandlerTask myThread = new MongoDataHandlerTask();
pool.execute(myThread);
}
}
// private static LjsdMongoTemplate myMongoTemplate;
// public MongoDataHandlerTask(){
// setName("MongoDataHandlerTask");
// }
// @Override
// public void run() {
// while (true) {
// try {
// ConcurrentDataMessage.manageData(myMongoTemplate);
// } catch (Exception e) {
// e.printStackTrace();
// }
// }
// }
// public static void init(){
// myMongoTemplate = ConfigurableApplicationContextManager.getBean(LjsdMongoTemplate.class);
//// startTlogThread();
// }
//
// public static void startTlogThread(){
// ExecutorService pool = Executors.newCachedThreadPool();
// for (int i = 0; i < 1 ; i++){
// MongoDataHandlerTask myThread = new MongoDataHandlerTask();
// pool.execute(myThread);
// }
// }
}