| 68 | import org.jetbrains.annotations.Nullable; |
| 69 | |
| 70 | public class Online extends AbstractOnline implements HotUpgrade { |
| 71 | protected static final @NotNull Logger logger = LogManager.getLogger(Online.class); |
| 72 | |
| 73 | public final @NotNull ProviderApp providerApp; |
| 74 | private final AtomicLong loginTimes = new AtomicLong(); |
| 75 | |
| 76 | private final @NotNull EventDispatcher loginEvents; |
| 77 | private final @NotNull EventDispatcher reloginEvents; |
| 78 | private final @NotNull EventDispatcher logoutEvents; |
| 79 | private final @NotNull EventDispatcher localRemoveEvents; |
| 80 | |
| 81 | // 缓存拥有Local数据的HotModule,用来优化。 |
| 82 | private final ConcurrentHashSet<HotModule> hotModulesHaveLocal = new ConcurrentHashSet<>(); |
| 83 | private boolean freshStopModule = false; |
| 84 | |
| 85 | private void onHotModuleStop(@NotNull HotModule hot) { |
| 86 | freshStopModule |= hotModulesHaveLocal.remove(hot) != null; |
| 87 | } |
| 88 | |
| 89 | @Override |
| 90 | public boolean hasFreshStopModuleLocalOnce() { |
| 91 | var tmp = freshStopModule; |
| 92 | freshStopModule = false; |
| 93 | return tmp; |
| 94 | } |
| 95 | |
| 96 | static class Retreat { |
| 97 | final @NotNull String account; |
| 98 | final @NotNull String clientId; |
| 99 | final @NotNull String key; |
| 100 | final @NotNull Bean bean; |
| 101 | |
| 102 | Retreat(@NotNull String account, @NotNull String clientId, @NotNull String key, @NotNull Bean bean) { |
| 103 | this.account = account; |
| 104 | this.clientId = clientId; |
| 105 | this.key = key; |
| 106 | this.bean = bean; |
| 107 | } |
| 108 | } |
| 109 | |
| 110 | @Override |
| 111 | public void upgrade(@NotNull Function<Bean, Bean> retreatFunc) throws Exception { |
| 112 | // 如果需要,重建_tlocal内存表的用户设置的bean。 |
| 113 | var retreats = new ArrayList<Retreat>(); |
| 114 | _tlocal.walkMemory((account, locals) -> { |
| 115 | for (var login : locals.getLogins()) { |
| 116 | var clientId = login.getKey(); |
| 117 | for (var e : login.getValue().getDatas()) { |
| 118 | var retreatBean = retreatFunc.apply(e.getValue().getAny().getBean()); |
| 119 | if (retreatBean != null) { |
| 120 | beanFactory.register(retreatBean); // 覆盖beanFactory. |
| 121 | retreats.add(new Retreat(account, clientId, e.getKey(), retreatBean)); |
| 122 | if (retreats.size() > 50) { |
| 123 | saveRetreats(retreats); |
| 124 | retreats.clear(); |
| 125 | } |
| 126 | } |
| 127 | } |
nothing calls this directly
no outgoing calls
no test coverage detected