1 4 package com.tcsimulator.listener; 5 6 import EDU.oswego.cs.dl.util.concurrent.LinkedQueue; 7 8 import java.io.PrintStream ; 9 import java.util.ArrayList ; 10 import java.util.Collection ; 11 import java.util.Iterator ; 12 13 public class QueuePrinter implements Runnable { 14 15 private final LinkedQueue queue; 16 private final Collection outputStreams; 17 18 public QueuePrinter(LinkedQueue queue, PrintStream out) { 19 this.queue = queue; 20 this.outputStreams = new ArrayList (); 21 this.outputStreams.add(out); 22 } 23 24 public void setAdditionalOutput(PrintStream out) { 25 this.outputStreams.add(out); 26 } 27 28 public void run() { 29 while (true) { 30 try { 31 Object obj = this.queue.take(); 32 for (Iterator i = outputStreams.iterator(); i.hasNext();) { 33 ((PrintStream ) i.next()).println(obj); 34 } 35 } catch (InterruptedException e) { 36 throw new RuntimeException (e); 37 } 38 } 39 } 40 41 } 42 | Popular Tags |