| 17 | import org.jetbrains.annotations.Nullable; |
| 18 | |
| 19 | public abstract class Protocol<TArgument extends Serializable> implements Serializable { |
| 20 | public static final int HEADER_SIZE = 12; // moduleId[4] + protocolId[4] + size[4] |
| 21 | private static final @NotNull Logger logger = LogManager.getLogger(Protocol.class); |
| 22 | private static final LongConcurrentHashMap<Class<? extends Protocol<?>>> protocolClasses = new LongConcurrentHashMap<>(); |
| 23 | private static final @NotNull VarHandle userStateHandle; |
| 24 | protected static final IOException noHandlerException = new IOException("noHandler"); |
| 25 | |
| 26 | public static final int eCriticalPlus = 0; |
| 27 | public static final int eCritical = 1; |
| 28 | public static final int eNormal = 2; |
| 29 | public static final int eSheddable = 3; |
| 30 | |
| 31 | private transient AsyncSocket sender; // AsyncSocket |
| 32 | @SuppressWarnings("unused") |
| 33 | private transient @Nullable Object userState; |
| 34 | public TArgument Argument; |
| 35 | protected long resultCode; |
| 36 | |
| 37 | static { |
| 38 | try { |
| 39 | userStateHandle = MethodHandles.lookup().findVarHandle(Protocol.class, "userState", Object.class); |
| 40 | } catch (ReflectiveOperationException e) { |
| 41 | throw new ExceptionInInitializerError(e); |
| 42 | } |
| 43 | } |
| 44 | |
| 45 | public int getCriticalLevel() { |
| 46 | return eCriticalPlus; |
| 47 | } |
| 48 | |
| 49 | private static final class UserStateWithEncoded { |
| 50 | private transient @Nullable Object userState; |
| 51 | private transient final @NotNull ByteBuffer encodeShared; |
| 52 | |
| 53 | private UserStateWithEncoded(@Nullable Object userState, @NotNull ByteBuffer encodeShared) { |
| 54 | this.userState = userState; |
| 55 | this.encodeShared = encodeShared; |
| 56 | } |
| 57 | } |
| 58 | |
| 59 | public int getFamilyClass() { |
| 60 | return FamilyClass.Protocol; |
| 61 | } |
| 62 | |
| 63 | public AsyncSocket getSender() { |
| 64 | return sender; |
| 65 | } |
| 66 | |
| 67 | public void setSender(AsyncSocket sender) { |
| 68 | this.sender = sender; |
| 69 | } |
| 70 | |
| 71 | public @Nullable Service getService() { |
| 72 | return sender.getService(); |
| 73 | } |
| 74 | |
| 75 | public @Nullable Object getUserState() { |
| 76 | var us = userState; |
nothing calls this directly
no outgoing calls
no test coverage detected