Skip to content

Commit 0490d09

Browse files
committed
update
1 parent 9f0579d commit 0490d09

File tree

172 files changed

+184774
-5
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

172 files changed

+184774
-5
lines changed

cache/src/main/java/com/zfoo/tank/cache/controller/BattleController.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@
2121
import com.zfoo.net.router.attachment.GatewayAttachment;
2222
import com.zfoo.net.anno.PacketReceiver;
2323
import com.zfoo.net.session.Session;
24-
import com.zfoo.net.util.SingleCache;
2524
import com.zfoo.orm.OrmContext;
2625
import com.zfoo.orm.util.MongoIdUtils;
2726
import com.zfoo.protocol.collection.CollectionUtils;
27+
import com.zfoo.scheduler.util.SingleCache;
2828
import com.zfoo.scheduler.util.TimeUtils;
2929
import com.zfoo.tank.common.entity.PlayerEntity;
3030
import com.zfoo.tank.common.entity.ScoreRankEntity;

single-boot/src/main/java/com/zfoo/tank/single/boot/controller/BattleController.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@
1717
import com.zfoo.net.NetContext;
1818
import com.zfoo.net.anno.PacketReceiver;
1919
import com.zfoo.net.session.Session;
20-
import com.zfoo.net.util.SingleCache;
2120
import com.zfoo.orm.OrmContext;
2221
import com.zfoo.orm.anno.EntityCacheAutowired;
2322
import com.zfoo.orm.cache.IEntityCache;
2423
import com.zfoo.orm.util.MongoIdUtils;
2524
import com.zfoo.protocol.collection.CollectionUtils;
25+
import com.zfoo.scheduler.util.SingleCache;
2626
import com.zfoo.scheduler.util.TimeUtils;
2727
import com.zfoo.storage.anno.StorageAutowired;
2828
import com.zfoo.storage.model.IStorage;

single-boot/src/main/java/com/zfoo/tank/single/boot/controller/LoginController.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ public void atLoginRequest(Session session, LoginRequest request) {
9292

9393
var sid = session.getSid();
9494

95-
EventBus.execute(HashUtils.fnvHash(account), new Runnable() {
95+
EventBus.asyncExecute(HashUtils.fnvHash(account), new Runnable() {
9696
@Override
9797
public void run() {
9898
var accountEntity = OrmContext.getAccessor().load(account, AccountEntity.class);

single/src/main/java/com/zfoo/tank/single/controller/BattleController.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@
1717
import com.zfoo.net.NetContext;
1818
import com.zfoo.net.anno.PacketReceiver;
1919
import com.zfoo.net.session.Session;
20-
import com.zfoo.net.util.SingleCache;
2120
import com.zfoo.orm.OrmContext;
2221
import com.zfoo.orm.anno.EntityCacheAutowired;
2322
import com.zfoo.orm.cache.IEntityCache;
2423
import com.zfoo.orm.util.MongoIdUtils;
2524
import com.zfoo.protocol.collection.CollectionUtils;
25+
import com.zfoo.scheduler.util.SingleCache;
2626
import com.zfoo.scheduler.util.TimeUtils;
2727
import com.zfoo.storage.anno.StorageAutowired;
2828
import com.zfoo.storage.model.IStorage;

single/src/main/java/com/zfoo/tank/single/controller/LoginController.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ public void atLoginRequest(Session session, LoginRequest request) {
8585
var sid = session.getSid();
8686

8787
// 由于uid还没确定下来,现在只能用account线程去处理
88-
EventBus.execute(HashUtils.fnvHash(account), new Runnable() {
88+
EventBus.asyncExecute(HashUtils.fnvHash(account), new Runnable() {
8989
@Override
9090
public void run() {
9191
var accountEntity = OrmContext.getAccessor().load(account, AccountEntity.class);
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
/*
2+
* Copyright (C) 2020 The zfoo Authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5+
* in compliance with the License. You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed
10+
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
* See the License for the specific language governing permissions and limitations under the License.
12+
*/
13+
14+
package com.zfoo.monitor.util;
15+
16+
import com.zfoo.monitor.*;
17+
import com.zfoo.net.util.NetUtils;
18+
import com.zfoo.protocol.exception.RunException;
19+
import com.zfoo.protocol.util.FileUtils;
20+
import com.zfoo.protocol.util.IOUtils;
21+
import com.zfoo.protocol.util.StringUtils;
22+
import com.zfoo.protocol.util.UuidUtils;
23+
import com.zfoo.scheduler.util.TimeUtils;
24+
import org.slf4j.Logger;
25+
import org.slf4j.LoggerFactory;
26+
import oshi.hardware.HWDiskStore;
27+
import oshi.hardware.HardwareAbstractionLayer;
28+
import oshi.hardware.NetworkIF;
29+
import oshi.software.os.OperatingSystem;
30+
31+
import java.io.File;
32+
import java.io.InputStream;
33+
import java.text.NumberFormat;
34+
import java.util.ArrayList;
35+
import java.util.HashMap;
36+
import java.util.List;
37+
import java.util.Map;
38+
import java.util.concurrent.ConcurrentHashMap;
39+
import java.util.stream.Collectors;
40+
41+
/**
42+
* 监控工具类
43+
*
44+
* @author godotg
45+
*/
46+
public abstract class MonitorUtils {
47+
48+
private static final Logger logger = LoggerFactory.getLogger(MonitorUtils.class);
49+
50+
private static Uptime maxUptime;
51+
private static Map<String, DiskFileSystem> maxDfMap;
52+
private static Memory maxFree;
53+
private static Map<String, Sar> maxSarMap;
54+
55+
static {
56+
initMonitor();
57+
}
58+
59+
public static void initMonitor() {
60+
maxUptime = OSUtils.uptime();
61+
maxDfMap = new ConcurrentHashMap<>(OSUtils.df().stream().collect(Collectors.toMap(key -> key.getName(), value -> value)));
62+
maxFree = OSUtils.free();
63+
maxSarMap = new ConcurrentHashMap<>(OSUtils.sar().stream().collect(Collectors.toMap(key -> key.getName(), value -> value)));
64+
}
65+
66+
public static Monitor maxMonitor() {
67+
var uuid = UuidUtils.getUUID();
68+
var monitor = Monitor.valueOf(uuid, maxUptime, new ArrayList<>(maxDfMap.values()), maxFree, new ArrayList<>(maxSarMap.values()));
69+
70+
initMonitor();
71+
return monitor;
72+
}
73+
74+
public static Monitor monitor() {
75+
var uuid = UuidUtils.getUUID();
76+
var uptime = OSUtils.uptime();
77+
var df = OSUtils.df();
78+
var free = OSUtils.free();
79+
var sar = OSUtils.sar();
80+
81+
if (uptime.compareTo(maxUptime) > 0) {
82+
maxUptime = uptime;
83+
}
84+
85+
for (var fileSystem : df) {
86+
var maxFileSystem = maxDfMap.get(fileSystem.getName());
87+
if (maxFileSystem != null && fileSystem.compareTo(maxFileSystem) > 0) {
88+
maxDfMap.put(fileSystem.getName(), fileSystem);
89+
}
90+
}
91+
92+
if (free.compareTo(maxFree) > 0) {
93+
maxFree = free;
94+
}
95+
96+
for (var networkIF : sar) {
97+
var maxNetworkIF = maxSarMap.get(networkIF.getName());
98+
if (maxNetworkIF != null && networkIF.compareTo(maxNetworkIF) > 0) {
99+
maxSarMap.put(maxNetworkIF.getName(), networkIF);
100+
}
101+
}
102+
103+
return Monitor.valueOf(uuid, uptime, df, free, sar);
104+
}
105+
106+
}
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
/*
2+
* Copyright (C) 2020 The zfoo Authors
3+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
4+
* in compliance with the License. You may obtain a copy of the License at
5+
*
6+
* http://www.apache.org/licenses/LICENSE-2.0
7+
*
8+
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed
9+
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10+
* See the License for the specific language governing permissions and limitations under the License.
11+
*/
12+
13+
package com.zfoo.protocol.model;
14+
15+
16+
import java.util.Objects;
17+
18+
/**
19+
* 键值对对象,只能在构造时传入键值
20+
*
21+
* @param <V> 值类型
22+
* @author godotg
23+
*/
24+
public class PairLong<V> {
25+
26+
private long key;
27+
private V value;
28+
29+
public PairLong() {
30+
31+
}
32+
33+
/**
34+
* 构造
35+
*
36+
* @param key 键
37+
* @param value 值
38+
*/
39+
public PairLong(long key, V value) {
40+
this.key = key;
41+
this.value = value;
42+
}
43+
44+
/**
45+
* 获取键
46+
*
47+
* @return 键
48+
*/
49+
public long getKey() {
50+
return this.key;
51+
}
52+
53+
/**
54+
* 获取值
55+
*
56+
* @return 值
57+
*/
58+
public V getValue() {
59+
return this.value;
60+
}
61+
62+
@Override
63+
public boolean equals(Object o) {
64+
if (this == o) return true;
65+
if (o == null || getClass() != o.getClass()) return false;
66+
PairLong<?> pairLong = (PairLong<?>) o;
67+
return key == pairLong.key && Objects.equals(value, pairLong.value);
68+
}
69+
70+
@Override
71+
public int hashCode() {
72+
return Long.hashCode(key);
73+
}
74+
75+
@Override
76+
public String toString() {
77+
return "Pair [key=" + key + ", value=" + value + "]";
78+
}
79+
}
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
/*
2+
* Copyright (C) 2020 The zfoo Authors
3+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
4+
* in compliance with the License. You may obtain a copy of the License at
5+
*
6+
* http://www.apache.org/licenses/LICENSE-2.0
7+
*
8+
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed
9+
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10+
* See the License for the specific language governing permissions and limitations under the License.
11+
*/
12+
13+
package com.zfoo.protocol.serializer;
14+
15+
import com.zfoo.protocol.util.FileUtils;
16+
import com.zfoo.protocol.util.StringUtils;
17+
18+
import java.util.ArrayList;
19+
import java.util.Arrays;
20+
import java.util.Map;
21+
22+
/**
23+
* @author godotg
24+
*/
25+
public enum CodeTemplatePlaceholder {
26+
27+
protocol_root_path("${protocol_root_path}"),
28+
protocol_imports("${protocol_imports}"),
29+
30+
protocol_class("${protocol_class}"),
31+
32+
protocol_registration("${protocol_registration}"),
33+
34+
protocol_manager_registrations("${protocol_manager_registrations}"),
35+
36+
protocol_note("${protocol_note}"),
37+
38+
protocol_name("${protocol_name}"),
39+
40+
protocol_id("${protocol_id}"),
41+
42+
protocol_field_definition("${protocol_field_definition}"),
43+
44+
protocol_write_serialization("${protocol_write_serialization}"),
45+
46+
protocol_read_deserialization("${protocol_read_deserialization}"),
47+
48+
;
49+
public final String placeholder;
50+
51+
private CodeTemplatePlaceholder(String placeholder) {
52+
this.placeholder = placeholder;
53+
}
54+
55+
56+
public static String formatTemplate(String template, Map<CodeTemplatePlaceholder, String> placeholderMap) {
57+
var lines = template.split(FileUtils.LS_REGEX);
58+
var formatLines = new ArrayList<String>();
59+
for (var line : lines) {
60+
var lineTrim = StringUtils.trim(line);
61+
var startPlaceholderOptional = Arrays.stream(CodeTemplatePlaceholder.values())
62+
.filter(it -> lineTrim.startsWith(it.placeholder))
63+
.findAny();
64+
var formatLine = line;
65+
if (startPlaceholderOptional.isPresent()) {
66+
var startPlaceholder = startPlaceholderOptional.get();
67+
// calculate the tab length
68+
var startSpace = StringUtils.substringBeforeFirst(line, startPlaceholder.placeholder);
69+
var startPlaceholderValue = placeholderMap.get(startPlaceholder);
70+
var startPlaceholderValueLines = Arrays.stream(startPlaceholderValue.split(FileUtils.LS_REGEX)).map(it -> startSpace + it).toList();
71+
72+
// add tab length to start placeholder
73+
var newStartPlaceholderValue = StringUtils.joinWith(FileUtils.LS, startPlaceholderValueLines.toArray());
74+
75+
formatLine = newStartPlaceholderValue + StringUtils.substringAfterFirst(line, startPlaceholder.placeholder);
76+
}
77+
78+
for (var codeTemplatePlaceholder : CodeTemplatePlaceholder.values()) {
79+
if (formatLine.contains(codeTemplatePlaceholder.placeholder)) {
80+
formatLine = formatLine.replace(codeTemplatePlaceholder.placeholder, placeholderMap.get(codeTemplatePlaceholder));
81+
}
82+
}
83+
84+
formatLines.add(formatLine);
85+
}
86+
return StringUtils.joinWith(FileUtils.LS, formatLines.toArray());
87+
}
88+
89+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package com.zfoo.protocol.serializer;
2+
3+
import com.zfoo.protocol.generate.GenerateOperation;
4+
import com.zfoo.protocol.registration.ProtocolRegistration;
5+
6+
import java.io.IOException;
7+
import java.util.List;
8+
9+
/**
10+
* 协议修改过后的测试流程:
11+
* 1.测试Java的老协议和新协议的兼容性,NormalObject/ObjectA/ObjectB有几个兼容字段
12+
* 2.测试Java在字节码增强,CutDown,反射三种情况下的代码下的协议解析的准确性
13+
* 3.测试resource/compatible中有5种协议兼容情况需要测试
14+
* 4.1/2/3总共有2*3*5=30种情况
15+
* <p>
16+
* 协议生成修改后的测试流程:
17+
* 1.测试老协议和新协议的兼容性,NormalObject/ObjectA/ObjectB有几个兼容字段
18+
* 2.测试普通生成,CutDown两种种情况下的代码下的协议解析的准确性
19+
* 3.测试merge,fold,default三种种生成方式
20+
* 4.测试resource/compatible中有5种协议兼容情况需要测试
21+
* 5.1/2/3/4总共2*2*3*5=60种情况
22+
* 6.简单的测试流程,NormalObject/ObjectA打开兼容字段,因为生成都是走的同一个方法直接测试非CutDown的fold
23+
*
24+
* @author godotg
25+
*/
26+
public interface ICodeGenerate {
27+
28+
void init(GenerateOperation generateOperation);
29+
30+
/**
31+
* 将一个包下的协议文件生成在一个协议文件里
32+
*/
33+
void mergerProtocol(List<ProtocolRegistration> registrations) throws IOException;
34+
35+
/**
36+
* 折叠协议,生成协议文件会和Java源文件保持相同的目录结构
37+
*/
38+
void foldProtocol(List<ProtocolRegistration> registrations) throws IOException;
39+
40+
/**
41+
* 默认把所有的协议文件放在同一个更目录下,不做任何操作
42+
*/
43+
void defaultProtocol(List<ProtocolRegistration> registrations) throws IOException;
44+
45+
}

0 commit comments

Comments
 (0)