jetty-9 some post simone review changes to WriteFlusher

This commit is contained in:
Greg Wilkins 2012-08-03 19:41:56 +10:00
parent 99a4b5955f
commit 2d7b6c9c06
2 changed files with 29 additions and 15 deletions

View File

@ -106,7 +106,7 @@ abstract public class WriteFlusher
return _state.compareAndSet(previous,next);
}
private void pendingFail(PendingState<?> pending)
private void fail(PendingState<?> pending)
{
State current = _state.get();
if (current.getType()==StateType.FAILED)
@ -120,6 +120,17 @@ abstract public class WriteFlusher
}
throw new IllegalStateException();
}
private void ignoreFail()
{
State current = _state.get();
while (current.getType()==StateType.FAILED)
{
if (updateState(current,__IDLE))
return;
current = _state.get();
}
}
private boolean isTransitionAllowed(State currentState, State newState)
{
@ -290,22 +301,23 @@ abstract public class WriteFlusher
PendingState<?> pending=new PendingState<>(buffers, context, callback);
if (updateState(__WRITING,pending))
onIncompleteFlushed();
else
fail(new PendingState<>(buffers, context, callback));
return;
}
}
// If updateState didn't succeed, we don't care as our buffers have been written
if (updateState(__WRITING,__IDLE))
callback.completed(context);
else
pendingFail(new PendingState<>(buffers, context, callback));
if (!updateState(__WRITING,__IDLE))
ignoreFail();
callback.completed(context);
}
catch (IOException e)
{
if (updateState(__WRITING,__IDLE))
callback.failed(context, e);
else
pendingFail(new PendingState<>(buffers, context, callback));
fail(new PendingState<>(buffers, context, callback));
}
}
@ -343,22 +355,23 @@ abstract public class WriteFlusher
{
if (updateState(__COMPLETING,pending))
onIncompleteFlushed();
else
fail(pending);
return;
}
}
// If updateState didn't succeed, we don't care as our buffers have been written
if(updateState(__COMPLETING,__IDLE))
pending.complete();
else
pendingFail(pending);
if (!updateState(__COMPLETING,__IDLE))
ignoreFail();
pending.complete();
}
catch (IOException e)
{
if(updateState(__COMPLETING,__IDLE))
pending.fail(e);
else
pendingFail(pending);
fail(pending);
}
}

View File

@ -262,13 +262,14 @@ public class WriteFlusherTest
}
@Override
public void run()
public synchronized void run()
{
_content.append(_endp.takeOutputString());
completeWrite();
}
public String toString()
@Override
public synchronized String toString()
{
_content.append(_endp.takeOutputString());
return _content.toString();
@ -301,7 +302,7 @@ public class WriteFlusherTest
flusher.onFail(new Throwable("THE CAUSE"));
}
}
,50,TimeUnit.MILLISECONDS);
,random.nextInt(75)+1,TimeUnit.MILLISECONDS);
flusher.write(_context,callback,BufferUtil.toBuffer("How Now Brown Cow."),BufferUtil.toBuffer(" The quick brown fox jumped over the lazy dog!"));
}