pbwest 2002/10/24 07:22:15
Modified: src/org/apache/fop/datastructs Tag: FOP_0-20-0_Alt-Design
SyncedCircularBuffer.java
Log:
Added producerExhausted() and support.
Revision Changes Path
No revision
No revision
1.1.2.4 +30 -2
xml-fop/src/org/apache/fop/datastructs/Attic/SyncedCircularBuffer.java
Index: SyncedCircularBuffer.java
===================================================================
RCS file:
/home/cvs/xml-fop/src/org/apache/fop/datastructs/Attic/SyncedCircularBuffer.java,v
retrieving revision 1.1.2.3
retrieving revision 1.1.2.4
diff -u -r1.1.2.3 -r1.1.2.4
--- SyncedCircularBuffer.java 19 Oct 2002 03:09:04 -0000 1.1.2.3
+++ SyncedCircularBuffer.java 24 Oct 2002 14:22:15 -0000 1.1.2.4
@@ -35,6 +35,7 @@
private int getptr = 0;
private int putptr = 0;
private boolean flush = false;
+ private boolean producerFinished = false;
private Object pushBackBuf = null;
/**
@@ -101,6 +102,9 @@
if (Thread.interrupted()) {
throw new InterruptedException("Consumer interrupted");
}
+ if (producerFinished && isEmpty()) {
+ throw new NoSuchElementException("Producer is finished.");
+ }
if (pushBackBuf != null) {
obj = pushBackBuf;
pushBackBuf = null;
@@ -109,6 +113,11 @@
while (isEmpty()) {
// wait for the producer
+ // N.B. InterruptedException is propagated
+ // N.B. Because of synchronisation, producerFinished cannot
+ // become true while isEmpty() remains true, so just check for
+ // isEmpty(). In other circumstances, the
+ // InterruptedException will be propagated
this.wait();
}
@@ -141,6 +150,10 @@
throw new NoSuchElementException(
"SyncedCircularBuffer is full.");
}
+ if (producerFinished) {
+ throw new RuntimeException(
+ "SyncedCircularBuffer is finished.");
+ }
if (Thread.interrupted()) {
throw new InterruptedException("Producer interrupted");
}
@@ -153,6 +166,7 @@
notifyAll();
while (! isEmpty()) {
// Wait for the consumer
+ // N.B. InterruptedException is propagated
this.wait();
}
flush = false;
@@ -168,6 +182,20 @@
synchronized (this) {
if (! isEmpty()) {
flush = true;
+ notifyAll();
+ }
+ }
+ }
+
+ /**
+ * Notifies the consumer that the producer has terminated.
+ * The <tt>notifyAll()</tt> call allows for processing of the buffer before it
fills.
+ */
+ public void producerExhausted() {
+ synchronized (this) {
+ if (! isEmpty()) {
+ flush = true;
+ producerFinished = true;
notifyAll();
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]