Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGreg Wilkins2014-10-22 11:44:18 +0000
committerGreg Wilkins2014-10-22 11:44:18 +0000
commitb65aed7d1052bb91647dc281092f2fce2314b67f (patch)
tree22cbb7811f97ac57c547d51c5fc88d78da9ff2b6
parent58b56b0cfb89ffc62f79151b12689525c78fc22f (diff)
parent921381eb7c47b7a43315e1605f81813c2660a037 (diff)
downloadorg.eclipse.jetty.project-b65aed7d1052bb91647dc281092f2fce2314b67f.tar.gz
org.eclipse.jetty.project-b65aed7d1052bb91647dc281092f2fce2314b67f.tar.xz
org.eclipse.jetty.project-b65aed7d1052bb91647dc281092f2fce2314b67f.zip
Merge remote-tracking branch 'origin/jetty-9.2.x'
-rw-r--r--jetty-util/src/main/java/org/eclipse/jetty/util/IteratingCallback.java155
1 files changed, 73 insertions, 82 deletions
diff --git a/jetty-util/src/main/java/org/eclipse/jetty/util/IteratingCallback.java b/jetty-util/src/main/java/org/eclipse/jetty/util/IteratingCallback.java
index 0dc8a055b6..0e6dc233bf 100644
--- a/jetty-util/src/main/java/org/eclipse/jetty/util/IteratingCallback.java
+++ b/jetty-util/src/main/java/org/eclipse/jetty/util/IteratingCallback.java
@@ -194,13 +194,13 @@ public abstract class IteratingCallback implements Callback
break loop;
case IDLE:
- if (!_state.compareAndSet(State.IDLE,State.PROCESSING))
+ if (!_state.compareAndSet(state,State.PROCESSING))
continue;
processing();
break loop;
case PROCESSING:
- if (!_state.compareAndSet(State.PROCESSING,State.LOCKED))
+ if (!_state.compareAndSet(state,State.LOCKED))
continue;
// Tell the thread that is processing that it must iterate again
_iterate=true;
@@ -209,8 +209,13 @@ public abstract class IteratingCallback implements Callback
case LOCKED:
Thread.yield();
- continue;
+ continue loop;
+
+ case FAILED:
+ case SUCCEEDED:
+ break loop;
+ case CLOSED:
default:
throw new IllegalStateException("state="+state);
}
@@ -242,18 +247,17 @@ public abstract class IteratingCallback implements Callback
{
// action handling needs to know the state
State state=_state.get();
- switch (action)
+
+ switch (state)
{
- case IDLE:
+ case PROCESSING:
{
- // We need to change to idle state, but may stay in processing if there
- // is a concurrent call to iterate()
- switch (state)
+ switch (action)
{
- case PROCESSING:
+ case IDLE:
{
// lock the state
- if (!_state.compareAndSet(State.PROCESSING,State.LOCKED))
+ if (!_state.compareAndSet(state,State.LOCKED))
continue acting;
// Has iterate been called while we were processing?
@@ -269,83 +273,62 @@ public abstract class IteratingCallback implements Callback
_state.set(State.IDLE);
break processing;
}
- case LOCKED:
- {
- Thread.yield();
- continue;
- }
- default:
- throw new IllegalStateException("state="+state);
- }
- }
- case SCHEDULED:
- {
- // the call to process has scheduled a callback to succeeded() or failed()
- // these callbacks are in a race with us changing to pending state. If we win the
- // race, then the callback have to keep processing, otherwise if we lose the race
- // we have to keep processing.
- switch(state)
- {
- case PROCESSING:
+
+ case SCHEDULED:
{
- if (!_state.compareAndSet(State.PROCESSING, State.PENDING))
+ if (!_state.compareAndSet(state, State.PENDING))
continue acting;
- // we won the race, so the callback has to process and we can break processing
+ // we won the race against the callback, so the callback has to process and we can break processing
break processing;
}
- case CALLED:
+ case SUCCEEDED:
{
- if (!_state.compareAndSet(State.CALLED, State.PROCESSING))
+ if (!_state.compareAndSet(state, State.LOCKED))
continue acting;
- // we lost the race, so we have to keep processing
- continue processing;
- }
-
- case LOCKED:
- {
- Thread.yield();
- continue;
- }
-
- case FAILED:
- case CLOSED:
- {
+ _iterate=false;
+ _state.set(State.SUCCEEDED);
+ onCompleteSuccess();
break processing;
}
+
default:
- throw new IllegalStateException("state="+state);
+ throw new IllegalStateException("state="+state+" action="+action);
}
}
-
- case SUCCEEDED:
+
+ case CALLED:
{
- // process() has told us that there is no more work to do, so we need
- // to switch to SUCCEEDED state. We can now ignore any concurrent calls
- // to iterate() until reset() is called.
- switch(state)
+ switch (action)
{
- case SUCCEEDED:
- case FAILED:
- // Already complete!.
- break processing;
-
- case PROCESSING:
- if (!_state.compareAndSet(State.PROCESSING, State.SUCCEEDED))
+ case SCHEDULED:
+ {
+ if (!_state.compareAndSet(state, State.PROCESSING))
continue acting;
- _iterate=false;
- onCompleteSuccess();
- break processing;
-
+ // we lost the race, so we have to keep processing
+ continue processing;
+ }
+
default:
- throw new IllegalStateException("state="+state);
+ throw new IllegalStateException("state="+state+" action="+action);
}
}
+
+ case LOCKED:
+ Thread.yield();
+ continue acting;
+
+ case SUCCEEDED:
+ case FAILED:
+ case CLOSED:
+ break processing;
+
+ case IDLE:
+ case PENDING:
default:
- throw new IllegalStateException("action="+action);
+ throw new IllegalStateException("state="+state+" action="+action);
}
}
-
}
}
@@ -364,28 +347,31 @@ public abstract class IteratingCallback implements Callback
{
case PROCESSING:
{
- if (!_state.compareAndSet(State.PROCESSING, State.CALLED))
+ if (!_state.compareAndSet(state, State.CALLED))
continue loop;
break loop;
}
-
case PENDING:
{
- if (!_state.compareAndSet(State.PENDING, State.PROCESSING))
+ if (!_state.compareAndSet(state, State.PROCESSING))
continue loop;
processing();
break loop;
}
-
case CLOSED:
+ case FAILED:
{
// Too late!
break loop;
}
-
+ case LOCKED:
+ {
+ Thread.yield();
+ continue loop;
+ }
default:
{
- throw new IllegalStateException(toString());
+ throw new IllegalStateException("state="+state);
}
}
}
@@ -408,24 +394,27 @@ public abstract class IteratingCallback implements Callback
case FAILED:
case IDLE:
case CLOSED:
+ case CALLED:
{
- // Already complete!.
+ // too late!.
break loop;
}
case LOCKED:
{
Thread.yield();
continue loop;
- }
- default:
+ }
+ case PENDING:
+ case PROCESSING:
{
if (!_state.compareAndSet(state, State.FAILED))
continue loop;
onCompleteFailure(x);
break loop;
-
}
+ default:
+ throw new IllegalStateException("state="+state);
}
}
}
@@ -454,7 +443,6 @@ public abstract class IteratingCallback implements Callback
Thread.yield();
continue loop;
}
-
default:
{
if (!_state.compareAndSet(state, State.CLOSED))
@@ -499,8 +487,8 @@ public abstract class IteratingCallback implements Callback
/**
* Resets this callback.
* <p/>
- * A callback can only be reset to INACTIVE from the
- * SUCCEEDED or FAILED states or if it is already INACTIVE.
+ * A callback can only be reset to IDLE from the
+ * SUCCEEDED or FAILED states or if it is already IDLE.
*
* @return true if the reset was successful
*/
@@ -508,21 +496,24 @@ public abstract class IteratingCallback implements Callback
{
while (true)
{
- switch(_state.get())
+ State state=_state.get();
+ switch(state)
{
case IDLE:
return true;
case SUCCEEDED:
- if (!_state.compareAndSet(State.SUCCEEDED, State.IDLE))
+ if (!_state.compareAndSet(state, State.LOCKED))
continue;
_iterate=false;
+ _state.set(State.IDLE);
return true;
case FAILED:
- if (!_state.compareAndSet(State.FAILED, State.IDLE))
+ if (!_state.compareAndSet(state, State.LOCKED))
continue;
_iterate=false;
+ _state.set(State.IDLE);
return true;
case LOCKED:

Back to the top