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
|
@Override
|
||||||
public String toString()
|
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
|
public abstract class IteratingCallback implements Callback
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The internal states of this callback
|
* The internal states of this callback
|
||||||
*/
|
*/
|
||||||
@ -86,10 +85,11 @@ public abstract class IteratingCallback implements Callback
|
|||||||
*/
|
*/
|
||||||
FAILED,
|
FAILED,
|
||||||
/**
|
/**
|
||||||
* The ICB has been closed and cannot be reset
|
* This callback has been closed and cannot be reset.
|
||||||
*/
|
*/
|
||||||
CLOSED
|
CLOSED
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The indication of the overall progress of the overall job that
|
* The indication of the overall progress of the overall job that
|
||||||
* implementations of {@link #process()} must return.
|
* implementations of {@link #process()} must return.
|
||||||
@ -123,14 +123,9 @@ public abstract class IteratingCallback implements Callback
|
|||||||
|
|
||||||
protected IteratingCallback(boolean needReset)
|
protected IteratingCallback(boolean needReset)
|
||||||
{
|
{
|
||||||
_state = new AtomicReference<>(needReset?State.SUCCEEDED:State.INACTIVE);
|
_state = new AtomicReference<>(needReset ? State.SUCCEEDED : State.INACTIVE);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected State getState()
|
|
||||||
{
|
|
||||||
return _state.get();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method called by {@link #iterate()} to process the sub task.
|
* Method called by {@link #iterate()} to process the sub task.
|
||||||
* <p/>
|
* <p/>
|
||||||
@ -149,14 +144,31 @@ public abstract class IteratingCallback implements Callback
|
|||||||
protected abstract Action process() throws Exception;
|
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 completed successfully.
|
||||||
|
*
|
||||||
|
* @see #onCompleteFailure(Throwable)
|
||||||
|
*/
|
||||||
|
protected void onCompleteSuccess()
|
||||||
|
{
|
||||||
|
completed();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Invoked when the overall task has completely failed.
|
* Invoked when the overall task has completed with a failure.
|
||||||
|
*
|
||||||
|
* @see #onCompleteSuccess()
|
||||||
*/
|
*/
|
||||||
protected abstract void onCompleteFailure(Throwable x);
|
protected void onCompleteFailure(Throwable x)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method must be invoked by applications to start the processing
|
* This method must be invoked by applications to start the processing
|
||||||
@ -318,9 +330,10 @@ public abstract class IteratingCallback implements Callback
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
case CLOSED:
|
case CLOSED:
|
||||||
// too late!
|
{
|
||||||
|
// Too late!
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
{
|
{
|
||||||
throw new IllegalStateException(toString());
|
throw new IllegalStateException(toString());
|
||||||
@ -335,49 +348,56 @@ public abstract class IteratingCallback implements Callback
|
|||||||
* {@code super.failed(Throwable)}.
|
* {@code super.failed(Throwable)}.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public final void failed(Throwable x)
|
public void failed(Throwable x)
|
||||||
{
|
{
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
State current = _state.get();
|
State current = _state.get();
|
||||||
switch(current)
|
switch (current)
|
||||||
{
|
{
|
||||||
case SUCCEEDED:
|
case SUCCEEDED:
|
||||||
case FAILED:
|
case FAILED:
|
||||||
case INACTIVE:
|
case INACTIVE:
|
||||||
case CLOSED:
|
case CLOSED:
|
||||||
|
{
|
||||||
// Already complete!.
|
// Already complete!.
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
|
{
|
||||||
if (_state.compareAndSet(current, State.FAILED))
|
if (_state.compareAndSet(current, State.FAILED))
|
||||||
{
|
{
|
||||||
onCompleteFailure(x);
|
onCompleteFailure(x);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public final void close()
|
public void close()
|
||||||
{
|
{
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
State current = _state.get();
|
State current = _state.get();
|
||||||
switch(current)
|
switch (current)
|
||||||
{
|
{
|
||||||
case INACTIVE:
|
case INACTIVE:
|
||||||
case SUCCEEDED:
|
case SUCCEEDED:
|
||||||
case FAILED:
|
case FAILED:
|
||||||
|
{
|
||||||
if (_state.compareAndSet(current, State.CLOSED))
|
if (_state.compareAndSet(current, State.CLOSED))
|
||||||
return;
|
return;
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
|
{
|
||||||
if (_state.compareAndSet(current, State.CLOSED))
|
if (_state.compareAndSet(current, State.CLOSED))
|
||||||
{
|
{
|
||||||
onCompleteFailure(new IllegalStateException("Closed with pending callback "+this));
|
onCompleteFailure(new IllegalStateException("Closed with pending callback " + this));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -412,10 +432,13 @@ public abstract class IteratingCallback implements Callback
|
|||||||
return _state.get() == State.SUCCEEDED;
|
return _state.get() == State.SUCCEEDED;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ------------------------------------------------------------ */
|
/**
|
||||||
/** Reset the 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.
|
* <p/>
|
||||||
* @return True if the reset was successful
|
* 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()
|
public boolean reset()
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user