Abstract base class for protocol handlers. @param the type of the socket
| 58 | * @param <S> the type of the socket |
| 59 | */ |
| 60 | public abstract class AbstractProtocol<S> implements ProtocolHandler, MBeanRegistration { |
| 61 | |
| 62 | /** |
| 63 | * The string manager for this package. |
| 64 | */ |
| 65 | private static final StringManager sm = StringManager.getManager(AbstractProtocol.class); |
| 66 | |
| 67 | /** |
| 68 | * Counter used to generate unique JMX names for connectors using automatic port binding. |
| 69 | */ |
| 70 | private static final AtomicInteger nameCounter = new AtomicInteger(0); |
| 71 | |
| 72 | /** |
| 73 | * Unique ID for this connector. Only used if the connector is configured to use a random port as the port will |
| 74 | * change if stop(), start() is called. |
| 75 | */ |
| 76 | private int nameIndex = 0; |
| 77 | |
| 78 | |
| 79 | /** |
| 80 | * Endpoint that provides low-level network I/O - must be matched to the ProtocolHandler implementation |
| 81 | * (ProtocolHandler using NIO, requires NIO Endpoint etc.). |
| 82 | */ |
| 83 | private final AbstractEndpoint<S,?> endpoint; |
| 84 | |
| 85 | |
| 86 | /** The handler. */ |
| 87 | private Handler<S> handler; |
| 88 | |
| 89 | |
| 90 | /** Set of processors currently waiting for async processing. */ |
| 91 | private final Set<Processor> waitingProcessors = ConcurrentHashMap.newKeySet(); |
| 92 | |
| 93 | /** |
| 94 | * Controller for the timeout scheduling. |
| 95 | */ |
| 96 | private ScheduledFuture<?> timeoutFuture = null; |
| 97 | /** Scheduled future for the periodic monitor task. */ |
| 98 | private ScheduledFuture<?> monitorFuture; |
| 99 | |
| 100 | /** |
| 101 | * Creates a new protocol handler. |
| 102 | * |
| 103 | * @param endpoint The endpoint for low-level network I/O |
| 104 | */ |
| 105 | public AbstractProtocol(AbstractEndpoint<S,?> endpoint) { |
| 106 | this.endpoint = endpoint; |
| 107 | ConnectionHandler<S> cHandler = new ConnectionHandler<>(this); |
| 108 | getEndpoint().setHandler(cHandler); |
| 109 | setHandler(cHandler); |
| 110 | setConnectionLinger(Constants.DEFAULT_CONNECTION_LINGER); |
| 111 | setTcpNoDelay(Constants.DEFAULT_TCP_NO_DELAY); |
| 112 | } |
| 113 | |
| 114 | |
| 115 | // ----------------------------------------------- Generic property handling |
| 116 | |
| 117 | /** |
nothing calls this directly
no test coverage detected