@@ -0,0 +1,1772 @@
+package pw.koj.jetstreem.core;%0A%0Aimport java.nio.channels.Selector;%0Aimport java.nio.channels.SelectionKey;%0Aimport java.nio.channels.ClosedChannelException;%0Aimport java.io.IOException;%0Aimport java.util.*;%0A%0Apublic class StrmIOLoop extends Thread %7B%0A    private Selector selector;%0A    private StrmQueue taskQueue;%0A%0A    private StrmIOLoop () %7B%0A        super();%0A        try %7B%0A            this.selector = Selector.open();%0A        %7D catch (IOException ex) %7B%0A            System.err.println(%22I/O error: %22 + ex.getMessage());%0A        %7D%0A        this.taskQueue = StrmQueue.getInstance();%0A    %7D%0A%0A    public static StrmIOLoop initIOLoop() %7B%0A        StrmIOLoop loop = new StrmIOLoop();%0A        loop.start();%0A        return loop;%0A    %7D%0A%0A    public void closeIOLoop() %7B%0A        this.interrupt();%0A    %7D%0A%0A    public void run() %7B%0A        try %7B%0A            while (this.selector.select() %3E 0) %7B%0A                Set keys = this.selector.selectedKeys();%0A                for (Iterator%3CSelectionKey%3E it = keys.iterator(); it.hasNext(); ) %7B%0A                    SelectionKey key = it.next();%0A                    it.remove();%0A                    StrmIOTask task = (StrmIOTask)key.attachment();%0A                    taskQueue.push(task.strm(), task.func(), null);%0A                %7D%0A            %7D%0A        %7D catch (ClosedChannelException ex) %7B%0A            System.err.println(%22I/O channel is closed!%22);%0A        %7D catch (IOException ex) %7B%0A            System.err.println(%22I/O error: %22 + ex.getMessage());%0A        %7D finally %7B%0A            try %7B%0A                for (SelectionKey key: this.selector.keys()) %7B%0A                    key.channel().close();%0A                %7D%0A            %7D catch (IOException ex) %7B%0A                System.err.println(%22I/O error: %22 + ex.getMessage());%0A            %7D%0A        %7D%0A    %7D%0A%7D%0A%0A%0A%0A

implement run() in class StrmIOLoop