Re: BlockingSourceIF

Quartz <[email protected]> Tue, 23 Nov 2004 07:00:18 -0800 (PST)
Newsgroups gmane.comp.java.seda.user
Message-ID <[email protected]>
> For handling the backpressure, I will add a BlockingSinkIF interface 
> like we have already said.  But, to be consistent, I think that we must 
> create also a BlockingSourceIF.  Any objection?

For symetry, I guess so. But remember that non-blocking dequeue is only usefull if you have a
thread handling many stage (polling queues).

That is the case for TM that have less than 1 thread per stage. It checks all its stages queues
and if they are all empty, it goes to wait on a shared 'enqueue' monitor (one monitor per thread).
Any enqueue on any of the queues monitored by this thread will cause a notify() and the thread
pops out of wait to dequeue.

What I did, to be conserving the TM vs SM layer separation, is adding a
setSharedEnqueueSemaphore(Sem x) on the queue. It belongs to StageWrapperIF & QueueIF since it
concerns both enqueue and dequeue (source and sink). This semaphore is optionnal (may not be set)
as far as the queue implementation is concerned, but if set, the queue must notify the semaphore
to fulfill its contract with the TM.

(And here is where your head aches: it is totally possible to have let's say 5 threads over 20
stages. That means each thread may poll 20 queues. I call this a stagegroup. To be accurate, there
is one shared enqueue semaphore per stage group, not per thread, for simplicity, because it would
get ugly to notify an array of semaphores. Anyway the whole stage group is interrested in the
recent enqueue but only one thread needs to wake up (don't use notifyAll())).


package seda.sandStorm.core;
public final class Semaphore {
	private boolean raised = false;
	public final synchronized void wakeOne() {
		raised = true;
		notify();
	}
	public final synchronized void waitIfNotRaised() throws InterruptedException {
		if(!raised)
			wait();
		raised = false;
	}
}




		
__________________________________ 
Do you Yahoo!? 
The all-new My Yahoo! - Get yours free! 
http://my.yahoo.com 
 



-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users.
Discover which products truly live up to the hype. Start reading now. 
http://productguide.itmanagersjournal.com/