private void saveParser(SelectionKey key, ProtocolParser parser) { WorkerThread workerThread = (WorkerThread) Thread.currentThread(); // Detach the current Thread data. ThreadAttachment threadAttachment = workerThread.getAttachment(); threadAttachment.setAttribute(ProtocolParser.PARSER, parser); // Attach it to the SelectionKey so the it can be resumed latter. key.attach(threadAttachment); }
public static void attach(SelectionKey selectionKey, Response.ResponseAttachment suspendedResponse) { Object attachment = selectionKey.attachment(); if (attachment == null || !(attachment instanceof ThreadAttachment)) { attachment = obtainThreadAttachment(); selectionKey.attach(attachment); } final ThreadAttachment threadAttachment = (ThreadAttachment) attachment; suspendedResponse.setThreadAttachment(threadAttachment); suspendedResponse.resetTimeout(); threadAttachment.setIdleTimeoutDelay(suspendedResponse.getIdleTimeoutDelay()); threadAttachment.setTimeoutListener(suspendedResponse); threadAttachment.setKeySelectionListener(suspendedResponse); threadAttachment.setAttribute(SUSPENDED_RESPONSE_ATTR, suspendedResponse); }