[osmosis-dev] calling DataPostbox.release() multiple times
rhansen at bbn.com
Sun Jan 15 20:22:33 GMT 2012
On 2012-01-15 07:34, Brett Henderson wrote:
> You're correct in saying that Releasable classes can be released
> multiple times, however that is not typically how they're used in the
> Osmosis pipeline.
Does it make sense to change the Releasable API definition to say that
release can only be called once? Or might that break multiple-sink
stages like merge?
> DataPostbox is a bit tricky because it is the main synchronisation point
> between multiple threads. Two threads communicating via a DataPostbox
> perform handshakes during the initialize, complete, and release methods
> (the process methods run mostly independently). It is the release
> method where each threads tells the other thread that they are about to
> exit. DataPostbox does technically support multiple calls to release,
> but it would require each thread to restart after the release calls and
> this isn't supported (or even desirable) by the Osmosis pipeline.
> What changes would you suggest? I believe it's working as I originally
> intended, but that's not to say there isn't a better way :-)
Looking at the code a bit more I think it might only need minor changes.
I had thought that release() and outputRelease() changed the state to
equal that of a freshly constructed DataPostbox (to support reuse?), but
that's not true: inputExit and outputExit are false after construction
but true after release(). So simply checking inputExit at the beginning
of release() should take care of it. See the attached (untested) patch.
An alternative is to increase the burden on the users of DataPostbox.
They could be required to either ensure that the output thread restarts
or avoid calling DataPostbox.release() once the output thread exits.
For example, EntityBuffer.run() could set an 'outputThreadIsRunning'
boolean at the top and clear it at the end. Then EntityBuffer.release()
would be modified to only call buffer.release() if outputThreadIsRunning
-------------- next part --------------
A non-text attachment was scrubbed...
Size: 1382 bytes
Desc: not available
More information about the osmosis-dev