WebSocket frame handler for client connections.
| 32 | * WebSocket frame handler for client connections. |
| 33 | */ |
| 34 | public class WsFrameClient extends WsFrameBase { |
| 35 | |
| 36 | private final Log log = LogFactory.getLog(WsFrameClient.class); // must not be static |
| 37 | private static final StringManager sm = StringManager.getManager(WsFrameClient.class); |
| 38 | |
| 39 | private final AsyncChannelWrapper channel; |
| 40 | private final CompletionHandler<Integer,Void> handler; |
| 41 | // Not final as it may need to be re-sized |
| 42 | private volatile ByteBuffer response; |
| 43 | |
| 44 | /** |
| 45 | * Constructs a new WsFrameClient. |
| 46 | * |
| 47 | * @param response The response buffer |
| 48 | * @param channel The async channel wrapper |
| 49 | * @param wsSession The WebSocket session |
| 50 | * @param transformation The transformation to apply |
| 51 | */ |
| 52 | public WsFrameClient(ByteBuffer response, AsyncChannelWrapper channel, WsSession wsSession, |
| 53 | Transformation transformation) { |
| 54 | super(wsSession, transformation); |
| 55 | this.response = response; |
| 56 | this.channel = channel; |
| 57 | this.handler = new WsFrameClientCompletionHandler(); |
| 58 | } |
| 59 | |
| 60 | |
| 61 | void startInputProcessing() { |
| 62 | try { |
| 63 | processSocketRead(); |
| 64 | } catch (IOException ioe) { |
| 65 | close(ioe); |
| 66 | } |
| 67 | } |
| 68 | |
| 69 | |
| 70 | private void processSocketRead() throws IOException { |
| 71 | while (true) { |
| 72 | switch (getReadState()) { |
| 73 | case WAITING: |
| 74 | if (!changeReadState(ReadState.WAITING, ReadState.PROCESSING)) { |
| 75 | continue; |
| 76 | } |
| 77 | while (response.hasRemaining()) { |
| 78 | if (isSuspended()) { |
| 79 | if (!changeReadState(ReadState.SUSPENDING_PROCESS, ReadState.SUSPENDED)) { |
| 80 | continue; |
| 81 | } |
| 82 | // There is still data available in the response buffer |
| 83 | // Return here so that the response buffer will not be |
| 84 | // cleared and there will be no data read from the |
| 85 | // socket. Thus, when the read operation is resumed first |
| 86 | // the data left in the response buffer will be consumed |
| 87 | // and then a new socket read will be performed |
| 88 | return; |
| 89 | } |
| 90 | inputBuffer.mark(); |
| 91 | inputBuffer.position(inputBuffer.limit()).limit(inputBuffer.capacity()); |
nothing calls this directly
no test coverage detected