|
23 | 23 | import org.slf4j.LoggerFactory;
|
24 | 24 |
|
25 | 25 | /**
|
26 |
| - * An {@link AsyncHandler} augmented with an {@link #onCompleted(Response)} convenience method which gets called when the {@link Response} processing is finished. This class also |
27 |
| - * implement the {@link ProgressAsyncHandler} callback, all doing nothing except returning {@link org.asynchttpclient.AsyncHandler.State#CONTINUE} |
| 26 | + * An {@link AsyncHandler} augmented with an {@link #onCompleted(Response)} |
| 27 | + * convenience method which gets called when the {@link Response} processing is |
| 28 | + * finished. This class also implement the {@link ProgressAsyncHandler} |
| 29 | + * callback, all doing nothing except returning |
| 30 | + * {@link org.asynchttpclient.AsyncHandler.State#CONTINUE} |
28 | 31 | *
|
29 |
| - * @param <T> Type of the value that will be returned by the associated {@link java.util.concurrent.Future} |
| 32 | + * @param <T> |
| 33 | + * Type of the value that will be returned by the associated |
| 34 | + * {@link java.util.concurrent.Future} |
30 | 35 | */
|
31 | 36 | public abstract class AsyncCompletionHandler<T> implements AsyncHandler<T>, ProgressAsyncHandler<T> {
|
32 | 37 |
|
33 |
| - private static final Logger LOGGER = LoggerFactory.getLogger(AsyncCompletionHandler.class); |
34 |
| - private final Response.ResponseBuilder builder = new Response.ResponseBuilder(); |
| 38 | + private static final Logger LOGGER = LoggerFactory.getLogger(AsyncCompletionHandler.class); |
| 39 | + private final Response.ResponseBuilder builder = new Response.ResponseBuilder(); |
35 | 40 |
|
36 |
| - @Override |
37 |
| - public State onBodyPartReceived(HttpResponseBodyPart content) throws Exception { |
38 |
| - builder.accumulate(content); |
39 |
| - return State.CONTINUE; |
40 |
| - } |
| 41 | + @Override |
| 42 | + public State onStatusReceived(HttpResponseStatus status) throws Exception { |
| 43 | + builder.reset(); |
| 44 | + builder.accumulate(status); |
| 45 | + return State.CONTINUE; |
| 46 | + } |
41 | 47 |
|
42 |
| - @Override |
43 |
| - public State onStatusReceived(HttpResponseStatus status) throws Exception { |
44 |
| - builder.reset(); |
45 |
| - builder.accumulate(status); |
46 |
| - return State.CONTINUE; |
47 |
| - } |
| 48 | + @Override |
| 49 | + public State onHeadersReceived(HttpHeaders headers) throws Exception { |
| 50 | + builder.accumulate(headers); |
| 51 | + return State.CONTINUE; |
| 52 | + } |
48 | 53 |
|
49 |
| - @Override |
50 |
| - public State onHeadersReceived(HttpHeaders headers) throws Exception { |
51 |
| - builder.accumulate(headers); |
52 |
| - return State.CONTINUE; |
53 |
| - } |
| 54 | + @Override |
| 55 | + public State onBodyPartReceived(HttpResponseBodyPart content) throws Exception { |
| 56 | + builder.accumulate(content); |
| 57 | + return State.CONTINUE; |
| 58 | + } |
54 | 59 |
|
55 |
| - @Override |
56 |
| - public State onTrailingHeadersReceived(HttpHeaders headers) throws Exception { |
57 |
| - builder.accumulate(headers); |
58 |
| - return State.CONTINUE; |
59 |
| - } |
| 60 | + @Override |
| 61 | + public State onTrailingHeadersReceived(HttpHeaders headers) throws Exception { |
| 62 | + builder.accumulate(headers); |
| 63 | + return State.CONTINUE; |
| 64 | + } |
60 | 65 |
|
61 |
| - @Override |
62 |
| - public final T onCompleted() throws Exception { |
63 |
| - return onCompleted(builder.build()); |
64 |
| - } |
| 66 | + @Override |
| 67 | + public final T onCompleted() throws Exception { |
| 68 | + return onCompleted(builder.build()); |
| 69 | + } |
65 | 70 |
|
66 |
| - @Override |
67 |
| - public void onThrowable(Throwable t) { |
68 |
| - LOGGER.debug(t.getMessage(), t); |
69 |
| - } |
| 71 | + @Override |
| 72 | + public void onThrowable(Throwable t) { |
| 73 | + LOGGER.debug(t.getMessage(), t); |
| 74 | + } |
70 | 75 |
|
71 |
| - /** |
72 |
| - * Invoked once the HTTP response processing is finished. |
73 |
| - * |
74 |
| - * @param response The {@link Response} |
75 |
| - * @return T Value that will be returned by the associated {@link java.util.concurrent.Future} |
76 |
| - * @throws Exception if something wrong happens |
77 |
| - */ |
78 |
| - abstract public T onCompleted(Response response) throws Exception; |
| 76 | + /** |
| 77 | + * Invoked once the HTTP response processing is finished. |
| 78 | + * |
| 79 | + * @param response |
| 80 | + * The {@link Response} |
| 81 | + * @return T Value that will be returned by the associated |
| 82 | + * {@link java.util.concurrent.Future} |
| 83 | + * @throws Exception |
| 84 | + * if something wrong happens |
| 85 | + */ |
| 86 | + abstract public T onCompleted(Response response) throws Exception; |
79 | 87 |
|
80 |
| - /** |
81 |
| - * Invoked when the HTTP headers have been fully written on the I/O socket. |
82 |
| - * |
83 |
| - * @return a {@link org.asynchttpclient.AsyncHandler.State} telling to CONTINUE or ABORT the current processing. |
84 |
| - */ |
85 |
| - @Override |
86 |
| - public State onHeadersWritten() { |
87 |
| - return State.CONTINUE; |
88 |
| - } |
| 88 | + /** |
| 89 | + * Invoked when the HTTP headers have been fully written on the I/O socket. |
| 90 | + * |
| 91 | + * @return a {@link org.asynchttpclient.AsyncHandler.State} telling to CONTINUE |
| 92 | + * or ABORT the current processing. |
| 93 | + */ |
| 94 | + @Override |
| 95 | + public State onHeadersWritten() { |
| 96 | + return State.CONTINUE; |
| 97 | + } |
89 | 98 |
|
90 |
| - /** |
91 |
| - * Invoked when the content (a {@link java.io.File}, {@link String} or {@link java.io.InputStream} has been fully written on the I/O socket. |
92 |
| - * |
93 |
| - * @return a {@link org.asynchttpclient.AsyncHandler.State} telling to CONTINUE or ABORT the current processing. |
94 |
| - */ |
95 |
| - @Override |
96 |
| - public State onContentWritten() { |
97 |
| - return State.CONTINUE; |
98 |
| - } |
| 99 | + /** |
| 100 | + * Invoked when the content (a {@link java.io.File}, {@link String} or |
| 101 | + * {@link java.io.InputStream} has been fully written on the I/O socket. |
| 102 | + * |
| 103 | + * @return a {@link org.asynchttpclient.AsyncHandler.State} telling to CONTINUE |
| 104 | + * or ABORT the current processing. |
| 105 | + */ |
| 106 | + @Override |
| 107 | + public State onContentWritten() { |
| 108 | + return State.CONTINUE; |
| 109 | + } |
99 | 110 |
|
100 |
| - /** |
101 |
| - * Invoked when the I/O operation associated with the {@link Request} body as been progressed. |
102 |
| - * |
103 |
| - * @param amount The amount of bytes to transfer |
104 |
| - * @param current The amount of bytes transferred |
105 |
| - * @param total The total number of bytes transferred |
106 |
| - * @return a {@link org.asynchttpclient.AsyncHandler.State} telling to CONTINUE or ABORT the current processing. |
107 |
| - */ |
108 |
| - @Override |
109 |
| - public State onContentWriteProgress(long amount, long current, long total) { |
110 |
| - return State.CONTINUE; |
111 |
| - } |
| 111 | + /** |
| 112 | + * Invoked when the I/O operation associated with the {@link Request} body as |
| 113 | + * been progressed. |
| 114 | + * |
| 115 | + * @param amount |
| 116 | + * The amount of bytes to transfer |
| 117 | + * @param current |
| 118 | + * The amount of bytes transferred |
| 119 | + * @param total |
| 120 | + * The total number of bytes transferred |
| 121 | + * @return a {@link org.asynchttpclient.AsyncHandler.State} telling to CONTINUE |
| 122 | + * or ABORT the current processing. |
| 123 | + */ |
| 124 | + @Override |
| 125 | + public State onContentWriteProgress(long amount, long current, long total) { |
| 126 | + return State.CONTINUE; |
| 127 | + } |
112 | 128 | }
|
0 commit comments