class KWICIndexEntry static KWICIndexEntry [] entries(String description) private KWICIndexEntry(String words[], int index_word) boolean less(KWICIndexEntry kie) public String toString()
See the complete code.
public void run() while true Object o = input_object() if (o == null) break if !isValidObject(o) throw new Error() o = process_input(o) output_object(o) end_loop()
abstract class FilterRunnableTemplate implements Runnable abstract protected boolean isValidObject(Object o) abstract protected void process_input(Object o) protected buffer inb, outb protected void end_loop() try outb.put(null) catch (InterruptedException ie) { } FilterRunnable(buffer ib, buffer ob) inb = ib outb = ob protected Object input_object() try return inb.get() catch (InterruptedException ie) throw new Error() protected void output_object(Object o) try outb.put(o) catch (InterruptedException ie) throw new Error() public void run() // As before.
See the complete code.
protected void process_input(Object o) KWICIndexEntry entries[] = KWICIndexEntry.entries((String) o) if entries != null try outb.put(o) catch (InterruptedException ie) return
See the complete code.
protected void end_loop() try KWICIndexEntry db[] = new KWICIndexEntry[descriptions.size()] descriptions.toArray(db) outb.put(db) outb.put(null) catch (Exception ie) throw new RuntimeException()
See the complete code.
protected void output_object(Object o) KWICIndexEntry [] ieg = (KWICIndexEntry []) o for (int i = 0; i < ieg.length; i++) System.out.println(ieg[i])
See the complete code.
interface TerminationInterface void normal(int id) void abnormal(int id)
class PAFTermination implements TerminationInterface final static int unterminated = 0 normal = 1 abnormal = 2 final private int status[];
int check() int i = 0 while (i < status.length) && (status[i] == normal) i++ if i == status.length return normal while (i < status.length) && (status[i] == unterminated) i++ return i == status.length ? unterminated : abnormal
synchronized int disposition() // Wait until all threads have terminated normally, // or a thread terminates abnormally. while true try wait() catch (InterruptedException ie) return abnormal final int i = check() if (i != unterminated) return i synchronized void abnormal(int id) // Process id terminates abnormally. status[id] = abnormal notify() synchronized void normal(int id) // Process id terminates normally. status[id] = normal notify()
See the complete code.
ti
.
ti
.
ti.normal()
or ti.abnormal()
.
ti.disposition()
.
class StoppingThread extends Thread private final TerminationInterface halter; private final int id; StoppingThread (int id, TerminationInterface halter, Runnable r) super(r) this.halter = halter this.id = id public void run() boolean normal = true try super.run() catch (Exception e) normal = false if normal halter.normal(id); else halter.abnormal(id);
class kwic { public static void main(String[] args) buffer b1, b2, b3 StoppingThread threads[] = new StoppingThread[4] PAFTermination halter = new PAFTermination(4) InputFilter if = new InputFilter("input", b1) RotateFilter rf = new RotateFilter("rotate", b1, b2) SortFilter sf = new SortFilter("sort", b2, b3) OutputFilter of = new OutputFilter("output", b3) threads[0] = new StoppingThread(0, halter, if) threads[1] = new StoppingThread(1, halter, rf) threads[2] = new StoppingThread(2, halter, sf) threads[3] = new StoppingThread(3, halter, of) for (int i = 0; i < threads.length; i++) threads[i].start() if halter.disposition() != PAFTermination.normal System.out.println("Abnormal termination.") for (int i = 0; i < threads.length; i++) if threads[i].isAlive() threads[i].interrupt()
This page last modified on 9 August 2002.