/* @author j.n.magee 14/08/98 */ package concurrency.primes; import concurrency.connector.*; class Filter extends Thread { private PrimesCanvas display; private Pipe in,out; private int index; Filter(Pipe i, Pipe o, int id, PrimesCanvas d) {in = i; out=o;display = d; index = id;} public void run() { int i,p; Integer v; try { v = (Integer)in.get(); p=v.intValue(); display.prime(index,p); if (p==Primes.EOS && out!=null) { out.put(v); return; } while(true) { v = (Integer)in.get(); i=v.intValue(); display.print(index,i); sleep(1000); if (i==Primes.EOS) { if (out!=null) out.put(v); break; } else if (i%p!=0 && out!=null) out.put(v); } } catch (InterruptedException e){} } }