mirror of
https://github.com/jetty/jetty.project.git
synced 2025-03-01 11:29:29 +00:00
Restored IteratingCallback APIs (in particular the completed()
method) to keep compatibility over micro versions of Jetty. Removed getState() - can't return a private class from a protected method, plus it was only used in a toString() with the wrong formatting string, that was already printing the state. Removed also final modifiers to keep compatibility.
This commit is contained in:
parent
987800c419
commit
4daba1ba79
@ -705,7 +705,7 @@ public class HttpConnection extends AbstractConnection implements Runnable, Http
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return String.format("%s[i=%s,cb=%s]",super.toString(),getState(),_info,_callback);
|
||||
return String.format("%s[i=%s,cb=%s]",super.toString(),_info,_callback);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -50,7 +50,6 @@ import java.util.concurrent.atomic.AtomicReference;
|
||||
*/
|
||||
public abstract class IteratingCallback implements Callback
|
||||
{
|
||||
|
||||
/**
|
||||
* The internal states of this callback
|
||||
*/
|
||||
@ -86,10 +85,11 @@ public abstract class IteratingCallback implements Callback
|
||||
*/
|
||||
FAILED,
|
||||
/**
|
||||
* The ICB has been closed and cannot be reset
|
||||
* This callback has been closed and cannot be reset.
|
||||
*/
|
||||
CLOSED
|
||||
}
|
||||
|
||||
/**
|
||||
* The indication of the overall progress of the overall job that
|
||||
* implementations of {@link #process()} must return.
|
||||
@ -126,11 +126,6 @@ public abstract class IteratingCallback implements Callback
|
||||
_state = new AtomicReference<>(needReset ? State.SUCCEEDED : State.INACTIVE);
|
||||
}
|
||||
|
||||
protected State getState()
|
||||
{
|
||||
return _state.get();
|
||||
}
|
||||
|
||||
/**
|
||||
* Method called by {@link #iterate()} to process the sub task.
|
||||
* <p/>
|
||||
@ -149,14 +144,31 @@ public abstract class IteratingCallback implements Callback
|
||||
protected abstract Action process() throws Exception;
|
||||
|
||||
/**
|
||||
* Invoked when the overall task has completed successfully.
|
||||
* @deprecated Use {@link #onCompleteSuccess()} instead.
|
||||
*/
|
||||
protected abstract void onCompleteSuccess();
|
||||
@Deprecated
|
||||
protected void completed()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Invoked when the overall task has completely failed.
|
||||
* Invoked when the overall task has completed successfully.
|
||||
*
|
||||
* @see #onCompleteFailure(Throwable)
|
||||
*/
|
||||
protected abstract void onCompleteFailure(Throwable x);
|
||||
protected void onCompleteSuccess()
|
||||
{
|
||||
completed();
|
||||
}
|
||||
|
||||
/**
|
||||
* Invoked when the overall task has completed with a failure.
|
||||
*
|
||||
* @see #onCompleteSuccess()
|
||||
*/
|
||||
protected void onCompleteFailure(Throwable x)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* This method must be invoked by applications to start the processing
|
||||
@ -318,9 +330,10 @@ public abstract class IteratingCallback implements Callback
|
||||
return;
|
||||
}
|
||||
case CLOSED:
|
||||
// too late!
|
||||
{
|
||||
// Too late!
|
||||
return;
|
||||
|
||||
}
|
||||
default:
|
||||
{
|
||||
throw new IllegalStateException(toString());
|
||||
@ -335,7 +348,7 @@ public abstract class IteratingCallback implements Callback
|
||||
* {@code super.failed(Throwable)}.
|
||||
*/
|
||||
@Override
|
||||
public final void failed(Throwable x)
|
||||
public void failed(Throwable x)
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
@ -346,10 +359,12 @@ public abstract class IteratingCallback implements Callback
|
||||
case FAILED:
|
||||
case INACTIVE:
|
||||
case CLOSED:
|
||||
{
|
||||
// Already complete!.
|
||||
return;
|
||||
|
||||
}
|
||||
default:
|
||||
{
|
||||
if (_state.compareAndSet(current, State.FAILED))
|
||||
{
|
||||
onCompleteFailure(x);
|
||||
@ -358,8 +373,9 @@ public abstract class IteratingCallback implements Callback
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public final void close()
|
||||
public void close()
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
@ -369,10 +385,13 @@ public abstract class IteratingCallback implements Callback
|
||||
case INACTIVE:
|
||||
case SUCCEEDED:
|
||||
case FAILED:
|
||||
{
|
||||
if (_state.compareAndSet(current, State.CLOSED))
|
||||
return;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
if (_state.compareAndSet(current, State.CLOSED))
|
||||
{
|
||||
onCompleteFailure(new IllegalStateException("Closed with pending callback " + this));
|
||||
@ -381,6 +400,7 @@ public abstract class IteratingCallback implements Callback
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* only for testing
|
||||
@ -412,10 +432,13 @@ public abstract class IteratingCallback implements Callback
|
||||
return _state.get() == State.SUCCEEDED;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/** Reset the callback
|
||||
* <p>A callback can only be reset to INACTIVE from the SUCCEEDED or FAILED states or if it is already INACTIVE.
|
||||
* @return True if the reset was successful
|
||||
/**
|
||||
* Resets this callback.
|
||||
* <p/>
|
||||
* A callback can only be reset to INACTIVE from the
|
||||
* SUCCEEDED or FAILED states or if it is already INACTIVE.
|
||||
*
|
||||
* @return true if the reset was successful
|
||||
*/
|
||||
public boolean reset()
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user