|
@@ -20,8 +20,10 @@ import org.slf4j.Logger;
|
|
|
|
|
|
import java.io.File;
|
|
|
import java.io.FileInputStream;
|
|
|
-import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.Objects;
|
|
|
+import java.util.concurrent.ConcurrentHashMap;
|
|
|
import java.util.concurrent.ScheduledThreadPoolExecutor;
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
|
@@ -48,7 +50,8 @@ public class GCenter extends AbstractService {
|
|
|
/** 绑定的http 端口 **/
|
|
|
public static int BIND_HTTP_PORT = 4001;
|
|
|
|
|
|
- public static HashMap<Integer, NetHandler> handlers = new HashMap<>();
|
|
|
+ /** ws消息事件 **/
|
|
|
+ public static Map<Integer, NetHandler> handlers = new ConcurrentHashMap<>();
|
|
|
|
|
|
private static volatile GCenter instance;
|
|
|
|
|
@@ -86,7 +89,7 @@ public class GCenter extends AbstractService {
|
|
|
// 初始化网络服务
|
|
|
this.initNetService();
|
|
|
// 播网关更新游戏服链接 10秒调用
|
|
|
- this.scheduleExec.scheduleWithFixedDelay(new UpdateServerInfos(), 0, 10, TimeUnit.SECONDS);
|
|
|
+ scheduleExec.scheduleWithFixedDelay(new UpdateServerInfos(), 0, 10, TimeUnit.SECONDS);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -97,13 +100,13 @@ public class GCenter extends AbstractService {
|
|
|
private void initProperties() throws Exception {
|
|
|
logger.info("初始化 Properties ...");
|
|
|
SERVER_SETTINGS = new PropertiesUtil(env.getConfDir() + "/" + CONFIGURATION_FILE);
|
|
|
- SERVER_ID = Integer.parseInt(SERVER_SETTINGS.getProperty("SERVER_ID"));
|
|
|
+ SERVER_ID = Integer.parseInt(Objects.requireNonNull(SERVER_SETTINGS.getProperty("SERVER_ID")));
|
|
|
|
|
|
BIND_HOST = SERVER_SETTINGS.getProperty("BIND_HOST");
|
|
|
- BIND_PORT = Integer.parseInt(SERVER_SETTINGS.getProperty("BIND_PORT"));
|
|
|
+ BIND_PORT = Integer.parseInt(Objects.requireNonNull(SERVER_SETTINGS.getProperty("BIND_PORT")));
|
|
|
|
|
|
BIND_HTTP_HOST = SERVER_SETTINGS.getProperty("BIND_HTTP_HOST");
|
|
|
- BIND_HTTP_PORT = Integer.parseInt(SERVER_SETTINGS.getProperty("BIND_HTTP_PORT"));
|
|
|
+ BIND_HTTP_PORT = Integer.parseInt(Objects.requireNonNull(SERVER_SETTINGS.getProperty("BIND_HTTP_PORT")));
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -111,7 +114,7 @@ public class GCenter extends AbstractService {
|
|
|
*/
|
|
|
private void initHandler() {
|
|
|
logger.info("初始化消息事件...");
|
|
|
- if (handlers != null && handlers.size() > 0) {
|
|
|
+ if (handlers != null && !handlers.isEmpty()) {
|
|
|
handlers.clear();
|
|
|
}
|
|
|
File f = new File(env.getConfDir() + "/" + EVENT_FILE);
|
|
@@ -129,7 +132,6 @@ public class GCenter extends AbstractService {
|
|
|
registerHandler(id, (NetHandler) Class.forName(clazz).newInstance());
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
|
- e.printStackTrace();
|
|
|
logger.error(e.getMessage(), e);
|
|
|
}
|
|
|
}
|