@@ -0,0 +1,1629 @@
+/**%0A * %0A */%0Apackage mathsquared.resultswizard2;%0A%0Aimport java.util.Queue;%0A%0A/**%0A * Feeds data from a queue to another object, and from the object to another queue. Currently, the only supported object is a %7B@link ProtocolSelector%7D.%0A * %0A * @author MathSquared%0A * %0A */%0Apublic class QueueCommunicator implements Runnable %7B%0A    private Queue rx; // receiving%0A    private Queue tx; // sending%0A    private ProtocolSelector comm;%0A%0A    public QueueCommunicator (Queue rx, Queue tx, ProtocolSelector comm) %7B%0A        this.rx = rx;%0A        this.tx = tx;%0A        this.comm = comm;%0A    %7D%0A%0A    public void run () %7B%0A        boolean aborted = false;%0A        while (!aborted) %7B%0A            // Wait until we have data%0A            while (rx.size() == 0) %7B%0A                try %7B%0A                    Thread.sleep(100);%0A                %7D catch (InterruptedException e) %7B%0A                    // ignore%0A                %7D%0A            %7D%0A%0A            // Process the data%0A%0A            Object pop = rx.poll();%0A%0A            // This is an object stream, so we must check and cast (and ensure that we're not about to NPE, just to be safe)%0A            if (pop != null && pop instanceof Command) %7B%0A                Command cmd = (Command) pop;%0A                Command send = comm.processMessage(cmd); // Get the command to send back%0A                tx.add(send);%0A%0A                // Ensure that we're not aborting (POISON or XMIT_ERROR_RESTART invalidate the streams)%0A                if (cmd.getType().equals(Message.POISON) %7C%7C cmd.getType().equals(Message.XMIT_ERROR_RESTART)) %7B%0A                    aborted = true;%0A                %7D%0A            %7D%0A        %7D%0A    %7D%0A%7D%0A

Add QueueCommunicator