| 19 | import org.jetbrains.annotations.Nullable; |
| 20 | |
| 21 | public abstract class AsyncSocket implements Closeable { |
| 22 | private static final @NotNull Logger logger = LogManager.getLogger(AsyncSocket.class); |
| 23 | public static final @NotNull Level PROTOCOL_LOG_LEVEL = Level.toLevel(System.getProperty("protocolLog"), Level.OFF); |
| 24 | public static final boolean ENABLE_PROTOCOL_LOG = PROTOCOL_LOG_LEVEL != Level.OFF && logger.isEnabled(PROTOCOL_LOG_LEVEL); |
| 25 | public static final boolean ENABLE_DEBUG_LOG = logger.isDebugEnabled(); |
| 26 | public static final boolean ENABLE_PROTOCOL_LOG_OLD = "true".equalsIgnoreCase(System.getProperty("protocolLogOld")); |
| 27 | private static final LongHashSet protocolLogExcept = new LongHashSet(); |
| 28 | |
| 29 | protected Object userState; |
| 30 | |
| 31 | private static final AtomicLong sessionIdGen = new AtomicLong(1); |
| 32 | private static @NotNull LongSupplier sessionIdGenFunc = sessionIdGen::getAndIncrement; |
| 33 | |
| 34 | static { |
| 35 | var str = System.getProperty("protocolLogExcept"); |
| 36 | if (str != null) { |
| 37 | //noinspection DynamicRegexReplaceableByCompiledPattern |
| 38 | for (var numStr : str.split("[^\\d\\-]")) { |
| 39 | if (!numStr.isBlank()) |
| 40 | protocolLogExcept.add(Long.parseLong(numStr)); |
| 41 | } |
| 42 | } |
| 43 | |
| 44 | ShutdownHook.init(); |
| 45 | } |
| 46 | |
| 47 | private final @NotNull Service service; |
| 48 | |
| 49 | protected AsyncSocket(@NotNull Service service) { |
| 50 | this.service = service; |
| 51 | } |
| 52 | |
| 53 | public @NotNull Service getService() { |
| 54 | return service; |
| 55 | } |
| 56 | |
| 57 | public static boolean canLogProtocol(long protocolTypeId) { |
| 58 | return !protocolLogExcept.contains(protocolTypeId); |
| 59 | } |
| 60 | |
| 61 | public Object getUserState() { |
| 62 | return userState; |
| 63 | } |
| 64 | |
| 65 | public void setUserState(Object value) { |
| 66 | userState = value; |
| 67 | } |
| 68 | |
| 69 | public static void setSessionIdGenFunc(@Nullable LongSupplier seed) { |
| 70 | sessionIdGenFunc = seed != null ? seed : sessionIdGen::getAndIncrement; |
| 71 | } |
| 72 | |
| 73 | public enum Type { |
| 74 | eServer, |
| 75 | eClient, |
| 76 | eServerSocket, |
| 77 | } |
| 78 |
nothing calls this directly
no test coverage detected