Cosmetics and removed unused code.

Signed-off-by: Simone Bordet <simone.bordet@gmail.com>
This commit is contained in:
Simone Bordet 2018-08-14 15:22:19 +02:00
parent 1e439535c1
commit dd428b24a7
1 changed files with 7 additions and 68 deletions

View File

@ -30,7 +30,6 @@ import org.eclipse.jetty.client.api.Result;
import org.eclipse.jetty.http.HttpField; import org.eclipse.jetty.http.HttpField;
import org.eclipse.jetty.util.Callback; import org.eclipse.jetty.util.Callback;
import org.eclipse.jetty.util.CountingCallback; import org.eclipse.jetty.util.CountingCallback;
import org.eclipse.jetty.util.IteratingNestedCallback;
import org.eclipse.jetty.util.Retainable; import org.eclipse.jetty.util.Retainable;
import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger; import org.eclipse.jetty.util.log.Logger;
@ -41,10 +40,8 @@ public class ResponseNotifier
public void notifyBegin(List<Response.ResponseListener> listeners, Response response) public void notifyBegin(List<Response.ResponseListener> listeners, Response response)
{ {
// Optimized to avoid allocations of iterator instances for (Response.ResponseListener listener : listeners)
for (int i = 0; i < listeners.size(); ++i)
{ {
Response.ResponseListener listener = listeners.get(i);
if (listener instanceof Response.BeginListener) if (listener instanceof Response.BeginListener)
notifyBegin((Response.BeginListener)listener, response); notifyBegin((Response.BeginListener)listener, response);
} }
@ -65,10 +62,8 @@ public class ResponseNotifier
public boolean notifyHeader(List<Response.ResponseListener> listeners, Response response, HttpField field) public boolean notifyHeader(List<Response.ResponseListener> listeners, Response response, HttpField field)
{ {
boolean result = true; boolean result = true;
// Optimized to avoid allocations of iterator instances for (Response.ResponseListener listener : listeners)
for (int i = 0; i < listeners.size(); ++i)
{ {
Response.ResponseListener listener = listeners.get(i);
if (listener instanceof Response.HeaderListener) if (listener instanceof Response.HeaderListener)
result &= notifyHeader((Response.HeaderListener)listener, response, field); result &= notifyHeader((Response.HeaderListener)listener, response, field);
} }
@ -90,10 +85,8 @@ public class ResponseNotifier
public void notifyHeaders(List<Response.ResponseListener> listeners, Response response) public void notifyHeaders(List<Response.ResponseListener> listeners, Response response)
{ {
// Optimized to avoid allocations of iterator instances for (Response.ResponseListener listener : listeners)
for (int i = 0; i < listeners.size(); ++i)
{ {
Response.ResponseListener listener = listeners.get(i);
if (listener instanceof Response.HeadersListener) if (listener instanceof Response.HeadersListener)
notifyHeaders((Response.HeadersListener)listener, response); notifyHeaders((Response.HeadersListener)listener, response);
} }
@ -132,10 +125,9 @@ public class ResponseNotifier
Retainable retainable = callback instanceof Retainable ? (Retainable)callback : null; Retainable retainable = callback instanceof Retainable ? (Retainable)callback : null;
for (Response.AsyncContentListener listener : contentListeners) for (Response.AsyncContentListener listener : contentListeners)
{ {
ByteBuffer slice = buffer.slice();
if (retainable != null) if (retainable != null)
retainable.retain(); retainable.retain();
listener.onContent(response, slice, counter); notifyContent(listener, response, buffer.slice(), counter);
} }
} }
} }
@ -154,10 +146,8 @@ public class ResponseNotifier
public void notifySuccess(List<Response.ResponseListener> listeners, Response response) public void notifySuccess(List<Response.ResponseListener> listeners, Response response)
{ {
// Optimized to avoid allocations of iterator instances for (Response.ResponseListener listener : listeners)
for (int i = 0; i < listeners.size(); ++i)
{ {
Response.ResponseListener listener = listeners.get(i);
if (listener instanceof Response.SuccessListener) if (listener instanceof Response.SuccessListener)
notifySuccess((Response.SuccessListener)listener, response); notifySuccess((Response.SuccessListener)listener, response);
} }
@ -177,10 +167,8 @@ public class ResponseNotifier
public void notifyFailure(List<Response.ResponseListener> listeners, Response response, Throwable failure) public void notifyFailure(List<Response.ResponseListener> listeners, Response response, Throwable failure)
{ {
// Optimized to avoid allocations of iterator instances for (Response.ResponseListener listener : listeners)
for (int i = 0; i < listeners.size(); ++i)
{ {
Response.ResponseListener listener = listeners.get(i);
if (listener instanceof Response.FailureListener) if (listener instanceof Response.FailureListener)
notifyFailure((Response.FailureListener)listener, response, failure); notifyFailure((Response.FailureListener)listener, response, failure);
} }
@ -200,10 +188,8 @@ public class ResponseNotifier
public void notifyComplete(List<Response.ResponseListener> listeners, Result result) public void notifyComplete(List<Response.ResponseListener> listeners, Result result)
{ {
// Optimized to avoid allocations of iterator instances for (Response.ResponseListener listener : listeners)
for (int i = 0; i < listeners.size(); ++i)
{ {
Response.ResponseListener listener = listeners.get(i);
if (listener instanceof Response.CompleteListener) if (listener instanceof Response.CompleteListener)
notifyComplete((Response.CompleteListener)listener, result); notifyComplete((Response.CompleteListener)listener, result);
} }
@ -262,51 +248,4 @@ public class ResponseNotifier
forwardFailure(listeners, response, responseFailure); forwardFailure(listeners, response, responseFailure);
notifyComplete(listeners, new Result(request, requestFailure, response, responseFailure)); notifyComplete(listeners, new Result(request, requestFailure, response, responseFailure));
} }
private class ContentCallback extends IteratingNestedCallback
{
private final List<Response.ResponseListener> listeners;
private final Response response;
private final ByteBuffer buffer;
private int index;
private ContentCallback(List<Response.ResponseListener> listeners, Response response, ByteBuffer buffer, Callback callback)
{
super(callback);
this.listeners = listeners;
this.response = response;
// Slice the buffer to avoid that listeners peek into data they should not look at.
this.buffer = buffer.slice();
}
@Override
protected Action process() throws Exception
{
if (index == listeners.size())
return Action.SUCCEEDED;
Response.ResponseListener listener = listeners.get(index);
if (listener instanceof Response.AsyncContentListener)
{
// The buffer was sliced, so we always clear it
// (clear => position=0, limit=capacity) before
// passing it to the listener that may consume it.
buffer.clear();
ResponseNotifier.this.notifyContent((Response.AsyncContentListener)listener, response, buffer, this);
return Action.SCHEDULED;
}
else
{
succeeded();
return Action.SCHEDULED;
}
}
@Override
public void succeeded()
{
++index;
super.succeeded();
}
}
} }