[concurrency-interest] Adding interfaces Sink and Source?

Doug Lea dl@cs.oswego.edu
Sat, 2 Oct 2004 10:31:54 -0400


> I think that it could be usefull, in a future java release, to add 2 
> interfaces, Sink and Source, such a way that a Queue extend these two 
> interfaces.
> 
> SEDA project at http://www.eecs.harvard.edu/~mdw/proj/seda/ is a good 
> exemple of what I mean.

We discussed this a lot in the expert group and interest list,
especially since the predecessor of J2SE5.0 Queue, dl.u.c versions of
"Channel", does have Puttable and Takable superinterfaces. Even though
several of you out there probably still think it was a mistake for us
to omit these, it still seems to be the most defensible decision:

Unlike dl.u.c.Channel, J2SE5.0 Queue and BlockingQueue are
Collections, that you can for example, iterate though. Lack of support
for Collection operations was a frequently-complained about limitation
of Channel. To support this and still allow the blander usages
envisioned for Channel, and additionally keep the useful new
distinction of blocking vs plain queues would have required us to
define four new mixin-style interfaces (Offerable, Pollable, Puttable,
Takable) plus give names to various combinations of those supporting
Collection operations or not.  This would add a lot of "surface area"
to the package. If there were a really good reason to do this, we
might have done it anyway. But most usages of Puttable (and similarly
for others) that don't involve Queues usually have different
semantics, so don't unify nicely. For example, in lot of cases, they
involve messaging or IO, so can throw different kinds of Exceptions or
return status indicators.

The way we left it, it is still possible for individual developers
to unify usages themselves by adding a bit of glue. For example:

interface Puttable<E> { void put(E x) throws Exception; }
class MyLinkedQueue<E> extends LinkedQueue<E> implements Puttable<E> {
  ...
}

This is annoying to do, but considering how few people will want 
or need to, it still seems like the best compromise.

-Doug