Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGreg Wilkins2012-08-03 09:41:56 +0000
committerGreg Wilkins2012-08-03 09:41:56 +0000
commit2d7b6c9c06f7e7ee73a2cb9ec8ae3b0e94adac2c (patch)
tree595114427d852aedce7a4414768986ace3ec0892
parent99a4b5955fd4e5ece47c824b1c88b8a01d68e51f (diff)
downloadorg.eclipse.jetty.project-2d7b6c9c06f7e7ee73a2cb9ec8ae3b0e94adac2c.tar.gz
org.eclipse.jetty.project-2d7b6c9c06f7e7ee73a2cb9ec8ae3b0e94adac2c.tar.xz
org.eclipse.jetty.project-2d7b6c9c06f7e7ee73a2cb9ec8ae3b0e94adac2c.zip
jetty-9 some post simone review changes to WriteFlusher
-rw-r--r--jetty-io/src/main/java/org/eclipse/jetty/io/WriteFlusher.java37
-rw-r--r--jetty-io/src/test/java/org/eclipse/jetty/io/WriteFlusherTest.java7
2 files changed, 29 insertions, 15 deletions
diff --git a/jetty-io/src/main/java/org/eclipse/jetty/io/WriteFlusher.java b/jetty-io/src/main/java/org/eclipse/jetty/io/WriteFlusher.java
index 587c80448e..91f367c07a 100644
--- a/jetty-io/src/main/java/org/eclipse/jetty/io/WriteFlusher.java
+++ b/jetty-io/src/main/java/org/eclipse/jetty/io/WriteFlusher.java
@@ -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);
}
}
diff --git a/jetty-io/src/test/java/org/eclipse/jetty/io/WriteFlusherTest.java b/jetty-io/src/test/java/org/eclipse/jetty/io/WriteFlusherTest.java
index ffabbe90d6..cab02a6da9 100644
--- a/jetty-io/src/test/java/org/eclipse/jetty/io/WriteFlusherTest.java
+++ b/jetty-io/src/test/java/org/eclipse/jetty/io/WriteFlusherTest.java
@@ -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!"));
}

Back to the top