Skip to content

Commit

Permalink
Introduce MessageAggregator and DecoderResultProvider
Browse files Browse the repository at this point in the history
Motivation:

We have different message aggregator implementations for different
protocols, but they are very similar with each other.  They all stems
from HttpObjectAggregator.  If we provide an abstract class that provide
generic message aggregation functionality, we will remove their code
duplication.

Modifications:

- Add MessageAggregator which provides generic message aggregation
- Reimplement all existing aggregators using MessageAggregator
- Add DecoderResultProvider interface and extend it wherever possible so
  that MessageAggregator respects the state of the decoded message

Result:

Less code duplication
  • Loading branch information
trustin committed Jun 5, 2014
1 parent 25e2f5d commit 2e98566
Show file tree
Hide file tree
Showing 27 changed files with 733 additions and 668 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public ByteBuf content() {
}

@Override
public DecoderResult getDecoderResult() {
public DecoderResult decoderResult() {
return result;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,6 @@ public boolean release(int decrement) {
@Override
public String toString() {
return StringUtil.simpleClassName(this) +
"(data: " + content() + ", decoderResult: " + getDecoderResult() + ')';
"(data: " + content() + ", decoderResult: " + decoderResult() + ')';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ protected DefaultHttpObject() {
}

@Override
public DecoderResult getDecoderResult() {
public DecoderResult decoderResult() {
return decoderResult;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public String toString() {
StringBuilder buf = new StringBuilder();
buf.append(StringUtil.simpleClassName(this));
buf.append("(decodeResult: ");
buf.append(getDecoderResult());
buf.append(decoderResult());
buf.append(')');
buf.append(StringUtil.NEWLINE);
buf.append(getMethod());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,12 @@ public String toString() {
StringBuilder buf = new StringBuilder();
buf.append(StringUtil.simpleClassName(this));
buf.append("(decodeResult: ");
buf.append(getDecoderResult());
buf.append(decoderResult());
buf.append(')');
buf.append(StringUtil.NEWLINE);
buf.append(getProtocolVersion().text());
buf.append(' ');
buf.append(getStatus().toString());
buf.append(getStatus());
buf.append(StringUtil.NEWLINE);
appendHeaders(buf);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
*/
public abstract class HttpHeaders implements Iterable<Map.Entry<String, String>> {

private static final byte[] HEADER_SEPERATOR = { HttpConstants.COLON, HttpConstants.SP };
private static final byte[] HEADER_SEPERATOR = { COLON, SP };
private static final byte[] CRLF = { CR, LF };

public static final HttpHeaders EMPTY_HEADERS = new HttpHeaders() {
Expand Down Expand Up @@ -722,7 +722,7 @@ public static int getIntHeader(HttpMessage message, CharSequence name, int defau

try {
return Integer.parseInt(value);
} catch (NumberFormatException e) {
} catch (NumberFormatException ignored) {
return defaultValue;
}
}
Expand Down Expand Up @@ -783,7 +783,7 @@ public static Date getDateHeader(HttpMessage message, CharSequence name, Date de

try {
return HttpHeaderDateFormat.get().parse(value);
} catch (ParseException e) {
} catch (ParseException ignored) {
return defaultValue;
}
}
Expand Down Expand Up @@ -865,7 +865,7 @@ public static long getContentLength(HttpMessage message, long defaultValue) {
if (contentLength != null) {
try {
return Long.parseLong(contentLength);
} catch (NumberFormatException e) {
} catch (NumberFormatException ignored) {
return defaultValue;
}
}
Expand Down Expand Up @@ -1408,7 +1408,12 @@ public HttpHeaders set(HttpHeaders headers) {
if (headers == null) {
throw new NullPointerException("headers");
}

clear();
if (headers.isEmpty()) {
return this;
}

for (Map.Entry<String, String> e: headers) {
add(e.getKey(), e.getValue());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,6 @@
*/
package io.netty.handler.codec.http;

import io.netty.handler.codec.DecoderResult;
import io.netty.handler.codec.DecoderResultProvider;

public interface HttpObject {
/**
* Returns the result of decoding this message.
*/
DecoderResult getDecoderResult();

/**
* Updates the result of decoding this message. This method is supposed to be invoked by {@link HttpObjectDecoder}.
* Do not call this method unless you know what you are doing.
*/
void setDecoderResult(DecoderResult result);
}
public interface HttpObject extends DecoderResultProvider { }
Loading

0 comments on commit 2e98566

Please sign in to comment.