DESCRIPTION

JVMCBC-209: Avoid race condition between disconnect and reconnect.

Motivation
----------
There is a (small) chance that both the disconnect and a reconnect
initiated by a closed socket race each other and the endpoint,
despite being explicitly disconnected, ends up in a reconnect
loop.

Modifications
-------------
The AbstractEndpoint now explicitly sets a volatile disconnected
flag which is always checked before a reconnect cycle is initiated.
This prevents the chance of states being messed up and racing
each other in the disconnect (and therefore, terminal) case.

In addition, to make sure that all states are properly observed
the state machine's observable is also serialized (this makes
sure that event transitions from multiple threads are observed
in the right order).

Result
------
Disconnect calls are now more strictly enforced, preventing
"endless" reconnects. Also, the state machine streams are
now properly serialized.

Change-Id: I586ced07a2ac3fc43f21b731ca80d3de80b4a098


COMMENTS

author: Natasha Sullivan
date: 2015-06-18 11:26:51.562000000

Uploaded patch set 2.

-------------------------------------
author: Gerrit Code Review
date: 2015-06-18 13:30:28.462000000

Change has been successfully cherry-picked as 47140e3a328da72e453f64461c092b6560081263

-------------------------------------
