consumer
}
}
- private Throwable preSend(Callback callback, boolean commit)
+ private Throwable sending(Callback callback, boolean commit)
{
synchronized (this)
{
@@ -413,23 +413,24 @@ private Throwable preSend(Callback callback, boolean commit)
{
case IDLE:
{
- _state = State.PRE_SEND;
+ _state = State.SENDING;
_callback = callback;
_commit = commit;
return null;
}
+ case FAILED:
+ {
+ return _failure;
+ }
default:
{
- Throwable failure = _failure;
- if (failure == null)
- failure = new IllegalStateException("Invalid transport state: " + _state);
- return failure;
+ return new IllegalStateException("Invalid transport state: " + _state);
}
}
}
}
- private void postSend()
+ private void pending()
{
Callback callback;
boolean commit;
@@ -438,14 +439,14 @@ private void postSend()
{
switch (_state)
{
- case PRE_SEND:
+ case SENDING:
{
// The send has not completed the callback yet,
// wait for succeeded() or failed() to be called.
- _state = State.POST_SEND;
+ _state = State.PENDING;
return;
}
- case SUCCEED:
+ case SUCCEEDING:
{
// The send already completed successfully, but the
// call to succeeded() was delayed, so call it now.
@@ -455,7 +456,7 @@ private void postSend()
reset();
break;
}
- case FAIL:
+ case FAILING:
{
// The send already completed with a failure, but
// the call to failed() was delayed, so call it now.
@@ -491,13 +492,13 @@ public void succeeded()
{
switch (_state)
{
- case PRE_SEND:
+ case SENDING:
{
- _state = State.SUCCEED;
+ _state = State.SUCCEEDING;
// Succeeding the callback will be done in postSend().
return;
}
- case POST_SEND:
+ case PENDING:
{
callback = _callback;
commit = _commit;
@@ -524,15 +525,15 @@ public void failed(Throwable failure)
{
switch (_state)
{
- case PRE_SEND:
+ case SENDING:
{
- _state = State.FAIL;
+ _state = State.FAILING;
_failure = failure;
// Failing the callback will be done in postSend().
return;
}
case IDLE:
- case POST_SEND:
+ case PENDING:
{
_state = State.FAILED;
_failure = failure;
@@ -559,7 +560,7 @@ private boolean idleTimeout(Throwable failure)
{
switch (_state)
{
- case POST_SEND:
+ case PENDING:
{
// The send was started but idle timed out, fail it.
_state = State.FAILED;
@@ -570,11 +571,11 @@ private boolean idleTimeout(Throwable failure)
}
case IDLE:
// The application may be suspended, ignore the idle timeout.
- case PRE_SEND:
+ case SENDING:
// A send has been started at the same time of an idle timeout;
// Ignore the idle timeout and let the write continue normally.
- case SUCCEED:
- case FAIL:
+ case SUCCEEDING:
+ case FAILING:
// An idle timeout during these transient states is ignored.
case FAILED:
// Already failed, ignore the idle timeout.
@@ -644,7 +645,7 @@ private enum State
* No send initiated or in progress.
* Next states could be:
*
- * - {@link #PRE_SEND}, when {@link TransportCallback#send(Callback, boolean, Consumer)}
+ *
- {@link #SENDING}, when {@link TransportCallback#send(Callback, boolean, Consumer)}
* is called by the transport to initiate a send
* - {@link #FAILED}, when {@link TransportCallback#failed(Throwable)}
* is called by an asynchronous failure
@@ -656,15 +657,15 @@ private enum State
* cannot be notified while in this state.
* Next states could be:
*
- * - {@link #SUCCEED}, when {@link TransportCallback#succeeded()}
+ *
- {@link #SUCCEEDING}, when {@link TransportCallback#succeeded()}
* is called synchronously because the send succeeded
- * - {@link #FAIL}, when {@link TransportCallback#failed(Throwable)}
+ *
- {@link #FAILING}, when {@link TransportCallback#failed(Throwable)}
* is called synchronously because the send failed
- * - {@link #POST_SEND}, when {@link TransportCallback#postSend()}
+ *
- {@link #PENDING}, when {@link TransportCallback#pending()}
* is called before the send completes
*
*/
- PRE_SEND,
+ SENDING,
/**
* A send was initiated and is now pending, waiting for the {@link TransportCallback}
* to be notified of success or failure.
@@ -676,33 +677,33 @@ private enum State
* is called because either the send failed, or an asynchronous failure happened
*
*/
- POST_SEND,
+ PENDING,
/**
- * A send was initiated and succeeded, but {@link TransportCallback#postSend()}
+ *
A send was initiated and succeeded, but {@link TransportCallback#pending()}
* has not been called yet.
* This state indicates that the success actions (such as notifying the
* {@link TransportCallback} nested callback) must be performed when
- * {@link TransportCallback#postSend()} is called.
+ * {@link TransportCallback#pending()} is called.
* Next states could be:
*
- * - {@link #IDLE}, when {@link TransportCallback#postSend()}
+ *
- {@link #IDLE}, when {@link TransportCallback#pending()}
* is called
*
*/
- SUCCEED,
+ SUCCEEDING,
/**
- * A send was initiated and failed, but {@link TransportCallback#postSend()}
+ *
A send was initiated and failed, but {@link TransportCallback#pending()}
* has not been called yet.
* This state indicates that the failure actions (such as notifying the
* {@link TransportCallback} nested callback) must be performed when
- * {@link TransportCallback#postSend()} is called.
+ * {@link TransportCallback#pending()} is called.
* Next states could be:
*
- * - {@link #FAILED}, when {@link TransportCallback#postSend()}
+ *
- {@link #FAILED}, when {@link TransportCallback#pending()}
* is called
*
*/
- FAIL,
+ FAILING,
/**
* The terminal state indicating failure of the send.
*/