| 52 | import org.jetbrains.annotations.Nullable; |
| 53 | |
| 54 | public class Timer extends AbstractTimer implements HotBeanFactory { |
| 55 | static final Logger logger = LogManager.getLogger(Timer.class); |
| 56 | private static int CountPerNode = Reflect.inDebugMode ? 1 : 3; // 调试状态下减少timer之间的影响,以免频繁redo |
| 57 | private static final BeanFactory beanFactory = new BeanFactory(); |
| 58 | private static final LongConcurrentHashMap<AtomicLong> exceptCounter = new LongConcurrentHashMap<>(); |
| 59 | |
| 60 | public static void setCountPerNode(int countPerNode) { |
| 61 | CountPerNode = Math.max(countPerNode, 1); |
| 62 | } |
| 63 | |
| 64 | public static long getSpecialTypeIdFromBean(@NotNull Serializable bean) { |
| 65 | return BeanFactory.getSpecialTypeIdFromBean(bean); |
| 66 | } |
| 67 | |
| 68 | public static @NotNull Bean createBeanFromSpecialTypeId(long typeId) { |
| 69 | try { |
| 70 | return beanFactory.createBeanFromSpecialTypeId(typeId); |
| 71 | } catch (Exception e) { |
| 72 | if (exceptCounter.computeIfAbsent(typeId, __ -> new AtomicLong()).getAndIncrement() < 10) |
| 73 | logger.error("createBeanFromSpecialTypeId({}) exception:", typeId, e); |
| 74 | return new RawBean(typeId); |
| 75 | } |
| 76 | } |
| 77 | |
| 78 | public static long getOnlineSpecialTypeIdFromBean(@NotNull Serializable bean) { |
| 79 | return bean.typeId(); |
| 80 | } |
| 81 | |
| 82 | public static @NotNull Bean createOnlineBeanFromSpecialTypeId(long typeId) { |
| 83 | try { |
| 84 | return beanFactory.createBeanFromSpecialTypeId(typeId); |
| 85 | } catch (Exception e) { |
| 86 | if (exceptCounter.computeIfAbsent(typeId, __ -> new AtomicLong()).getAndIncrement() < 10) |
| 87 | logger.error("createOnlineBeanFromSpecialTypeId({}) exception:", typeId, e); |
| 88 | return new RawBean(typeId); |
| 89 | } |
| 90 | } |
| 91 | |
| 92 | public final Application zeze; |
| 93 | private AutoKey nodeIdAutoKey; |
| 94 | AutoKey timerIdAutoKey; |
| 95 | AutoKey timerSerialId; |
| 96 | |
| 97 | // 在这台服务器进程内调度的所有Timer。key是timerId,value是ThreadPool.schedule的返回值。 |
| 98 | final ConcurrentHashMap<String, Future<?>> timerFutures = new ConcurrentHashMap<>(); |
| 99 | private final HotHandle<TimerHandle> hotHandle = new HotHandle<>(); |
| 100 | private boolean started; |
| 101 | |
| 102 | private TimerAccount timerAccount; |
| 103 | private Online defaultOnline; |
| 104 | |
| 105 | private final ConcurrentHashSet<HotModule> hotModulesHaveDynamic = new ConcurrentHashSet<>(); |
| 106 | private boolean freshStopModuleDynamic; |
| 107 | |
| 108 | public static @NotNull Timer create(@NotNull AppBase app) { |
| 109 | return GenModule.createRedirectModule(Timer.class, app); |
| 110 | } |
| 111 |
nothing calls this directly
no outgoing calls
no test coverage detected