[concurrency-interest] draft Carrier API

Alex Otenko oleksandr.otenko at gmail.com
Sun Mar 8 12:36:50 EDT 2020


I am familiar with half closed states, but in the socket world. The use of
the same term is lost on me.

In networking, half closed socket is really a fully closed pipe in a
duplex. Here it is more of half closed singular pipe - closing one end of
the same pipe,  just from different ends. So some of the states that become
possible are really strange.

Calling it finish is better, but perhaps some confusion about possibly
interpreting it as an imperative instruction is still there. (Telling the
sender to "Finish!")

My understanding that the intention is to capture Carrier transitioning
like so:

sending and receiving -> sending complete, receiver can only drain buffered
items, reject future send attempts

Or

sending and receiving->receiving complete, no more items can be delivered,
discard all buffered items and reject future send attempts, reject future
attempts to receive

Is that right?

In the first case receiver needs some hint how many receives are sensible,
and if a receive is blocked on empty when sender transitions into the
sending done state, the receiver needs a nice way out. Throwing seems like
last resort, as typically exceptions indicate transitioning into error
states. Returning Optional<T> can be better.

Alex

On Sun, 8 Mar 2020, 13:37 Doug Lea, <dl at cs.oswego.edu> wrote:

> On 3/8/20 8:49 AM, Alex Otenko via Concurrency-interest wrote:
> > I think it may be useful to clarify who is meant to call each of the
> > close methods.
>
> Right; thanks especially for the questions about what confused
> programmers who aren't used to dealing with half-closed states might do.
>  Probably best to stop using "close" except for full close. And kill
> closeForReceiving. Leaving better names and simpler specs:
>
> interface Carriable<T> extends AutoCloseable {
>     boolean isClosed();
>     boolean isFinishedSending();    // closed or sending disabled
>     //...
> }
> interface CarrierSender<T> extends Carriable<T> {
>     void finishSending();           // disable sending; close when empty
>     // ...
> }
>
> Full versions as usual at: http://gee.cs.oswego.edu/dl/wwwtmp/Carrier.java
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://cs.oswego.edu/pipermail/concurrency-interest/attachments/20200308/30c98ef2/attachment.htm>


More information about the Concurrency-interest mailing list