热更新应该不会成功

back_recharge
zhangshanxue 2020-06-13 16:59:39 +08:00
parent 5264ddcb83
commit 45521fdee5
1 changed files with 16 additions and 13 deletions

View File

@ -10,13 +10,14 @@ import org.slf4j.LoggerFactory;
import java.io.File;
import java.io.IOException;
import java.util.concurrent.atomic.AtomicInteger;
public class CheckFight {
private static final Logger LOGGER = LoggerFactory.getLogger(CheckFight.class);
private ThreadLocal<LuaValue> localTransCoderObj = new ThreadLocal<LuaValue>();
private ThreadLocal<Integer> localVersion = new ThreadLocal<>();
// private String luaFileName = null;
private CheckFight(){}
@ -29,7 +30,7 @@ public class CheckFight {
return CheckFight.Instance.instance;
}
private int hotFixVersion = 0;
private AtomicInteger hotFixVersion = new AtomicInteger();
static class LuaHotFixBean{
private int version;
@ -42,21 +43,22 @@ public class CheckFight {
public void luaHotFix(){
LuaHotFixBean luaHotFixBean = STableManager.getJsonFilePathInJsonConf("lua-hotfix.json", LuaHotFixBean.class);
if(luaHotFixBean!=null && hotFixVersion < luaHotFixBean.getVersion()){
LOGGER.info("the curhotFixVersion={},the new hotFixVersion={} will hotfix ",hotFixVersion,luaHotFixBean.getVersion());
init();
if(luaHotFixBean!=null && hotFixVersion.get() < luaHotFixBean.getVersion()){
LOGGER.info("the curhotFixVersion={},the new hotFixVersion={} will hotfix ",hotFixVersion.get(),luaHotFixBean.getVersion());
//init();
LOGGER.info("the luahotfix done");
hotFixVersion = luaHotFixBean.getVersion();
hotFixVersion.set(luaHotFixBean.getVersion());
//tofix 不是原子操作
this.localTransCoderObj = new ThreadLocal<LuaValue>();
}
}
public void init(){
LuaHotFixBean luaHotFixBean = STableManager.getJsonFilePathInJsonConf("lua-hotfix.json", LuaHotFixBean.class);
if(luaHotFixBean!=null) {
hotFixVersion = luaHotFixBean.getVersion();
}
}
// public void init(){
// LuaHotFixBean luaHotFixBean = STableManager.getJsonFilePathInJsonConf("lua-hotfix.json", LuaHotFixBean.class);
// if(luaHotFixBean!=null) {
// hotFixVersion = luaHotFixBean.getVersion();
// }
// }
public static String getPath(String prefixDir, String... filePath) throws IOException {
@ -117,13 +119,14 @@ public class CheckFight {
public LuaValue getTransCoderObj(){
LuaValue transCoderObj = localTransCoderObj.get();
if(transCoderObj == null){
if(transCoderObj == null||localVersion.get()!=hotFixVersion.get()){
String luaFileName = null;
try {
luaFileName = getPath("luafight/BattleMain.lua");
} catch (IOException e) {
e.printStackTrace();
}
localVersion.set( hotFixVersion.get());
Globals globals = JsePlatform.debugGlobals();
transCoderObj = globals.loadfile(luaFileName).call();
localTransCoderObj.set(transCoderObj);