MCPcopy Create free account
hub / github.com/e2wugui/zeze / Log

Class Log

ZezeJava/ZezeJava/src/main/java/Zeze/Transaction/Log.java:25–173  ·  view source on GitHub ↗

操作日志。 主要用于 bean.variable 的修改。 用于其他非 bean 的日志时,也需要构造一个 bean,用来包装日志。

Source from the content-addressed store, hash-verified

23 * 用于其他非 bean 的日志时,也需要构造一个 bean,用来包装日志。
24 */
25public abstract class Log implements Serializable {
26 private static final @NotNull Logger logger = LogManager.getLogger(Log.class);
27
28 public enum Category {
29 eHistory, // 只有这个类被会被收集到增量日志里面
30 eUser, // 用户自定义
31 eSpecial, // zeze内部特殊定义的log,也可能是用户自定义的。
32 }
33
34 private static final LongConcurrentHashMap<IntFunction<Log>> factorys = new LongConcurrentHashMap<>();
35
36 public static void register(@NotNull IntFunction<Log> s) {
37 var ins = s.apply(0);
38 var old = factorys.putIfAbsent(ins.getTypeId(), s);
39 if (old == null)
40 logger.debug("register log typeId({}): {}", ins.getTypeId(), ins.getTypeName());
41 else {
42 var oldIns = old.apply(0);
43 if (!oldIns.getTypeName().equals(ins.getTypeName())) {
44 logger.error("register duplicated log typeId({}): {} & {}",
45 ins.getTypeId(), oldIns.getTypeName(), ins.getTypeName());
46 }
47 }
48 }
49
50 public static @NotNull Log create(int typeId, int varId) {
51 var factory = factorys.get(typeId);
52 if (factory != null)
53 return factory.apply(varId);
54 throw new UnsupportedOperationException("unknown log typeId=" + typeId);
55 }
56
57 private final Bean belong;
58 private final int varId;
59
60 protected Log(Bean belong, int varId) {
61 this.belong = belong;
62 this.varId = varId;
63 }
64
65 public final Bean getBelong() {
66 return belong;
67 }
68
69 public final int getVariableId() {
70 return varId;
71 }
72
73 public abstract @NotNull Category category();
74
75 public abstract int getTypeId();
76
77 public @NotNull String getTypeName() {
78 return getClass().getSimpleName();
79 }
80
81 public long getLogKey() {
82 return belong.objectId() + getVariableId();

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected