Remove content thread safe from REST layer

there is no need for this anymore, for some time, since in netty now we rely on copying over the buffer and reusing it
closes #10429
This commit is contained in:
Shay Banon 2015-04-04 16:24:06 +03:00
parent ca6f6d4283
commit af19ec3006
6 changed files with 10 additions and 32 deletions

View File

@ -137,11 +137,7 @@ public class NettyHttpChannel extends HttpChannel {
ChannelBuffer buffer;
boolean addedReleaseListener = false;
try {
if (response.contentThreadSafe()) {
buffer = content.toChannelBuffer();
} else {
buffer = content.copyBytesArray().toChannelBuffer();
}
buffer = content.toChannelBuffer();
resp.setContent(buffer);
// If our response doesn't specify a content-type header, set one
@ -180,7 +176,7 @@ public class NettyHttpChannel extends HttpChannel {
future = channel.write(resp);
}
if (response.contentThreadSafe() && content instanceof Releasable) {
if (content instanceof Releasable) {
future.addListener(new ReleaseChannelFutureListener((Releasable) content));
addedReleaseListener = true;
}

View File

@ -34,48 +34,46 @@ public class BytesRestResponse extends RestResponse {
private final RestStatus status;
private final BytesReference content;
private final boolean contentThreadSafe;
private final String contentType;
public BytesRestResponse(RestStatus status) {
this(status, TEXT_CONTENT_TYPE, BytesArray.EMPTY, true);
this(status, TEXT_CONTENT_TYPE, BytesArray.EMPTY);
}
/**
* Creates a new response based on {@link XContentBuilder}.
*/
public BytesRestResponse(RestStatus status, XContentBuilder builder) {
this(status, builder.contentType().restContentType(), builder.bytes(), true);
this(status, builder.contentType().restContentType(), builder.bytes());
}
/**
* Creates a new plain text response.
*/
public BytesRestResponse(RestStatus status, String content) {
this(status, TEXT_CONTENT_TYPE, new BytesArray(content), true);
this(status, TEXT_CONTENT_TYPE, new BytesArray(content));
}
/**
* Creates a new plain text response.
*/
public BytesRestResponse(RestStatus status, String contentType, String content) {
this(status, contentType, new BytesArray(content), true);
this(status, contentType, new BytesArray(content));
}
/**
* Creates a binary response.
*/
public BytesRestResponse(RestStatus status, String contentType, byte[] content) {
this(status, contentType, new BytesArray(content), true);
this(status, contentType, new BytesArray(content));
}
/**
* Creates a binary response.
*/
public BytesRestResponse(RestStatus status, String contentType, BytesReference content, boolean contentThreadSafe) {
public BytesRestResponse(RestStatus status, String contentType, BytesReference content) {
this.status = status;
this.content = content;
this.contentThreadSafe = contentThreadSafe;
this.contentType = contentType;
}
@ -96,7 +94,6 @@ public class BytesRestResponse extends RestResponse {
if (t instanceof HasRestHeaders) {
addHeaders(((HasRestHeaders) t).getHeaders());
}
this.contentThreadSafe = true;
}
@Override
@ -104,11 +101,6 @@ public class BytesRestResponse extends RestResponse {
return this.contentType;
}
@Override
public boolean contentThreadSafe() {
return this.contentThreadSafe;
}
@Override
public BytesReference content() {
return this.content;

View File

@ -42,11 +42,6 @@ public abstract class RestResponse implements HasRestHeaders {
*/
public abstract String contentType();
/**
* Can the content byte[] be used only with this thread (<tt>false</tt>), or by any thread (<tt>true</tt>).
*/
public abstract boolean contentThreadSafe();
/**
* The response content. Note, if the content is {@link org.elasticsearch.common.lease.Releasable} it
* should automatically be released when done by the channel sending it.

View File

@ -61,7 +61,7 @@ public abstract class AbstractCatAction extends BaseRestHandler {
out.append("\n");
}
out.close();
channel.sendResponse(new BytesRestResponse(RestStatus.OK, BytesRestResponse.TEXT_CONTENT_TYPE, bytesOutput.bytes(), true));
channel.sendResponse(new BytesRestResponse(RestStatus.OK, BytesRestResponse.TEXT_CONTENT_TYPE, bytesOutput.bytes()));
} else {
doRequest(request, channel, client);
}

View File

@ -93,7 +93,7 @@ public class RestTable {
out.append("\n");
}
out.close();
return new BytesRestResponse(RestStatus.OK, BytesRestResponse.TEXT_CONTENT_TYPE, bytesOut.bytes(), true);
return new BytesRestResponse(RestStatus.OK, BytesRestResponse.TEXT_CONTENT_TYPE, bytesOut.bytes());
}
private static List<DisplayHeader> buildDisplayHeaders(Table table, RestRequest request) {

View File

@ -253,11 +253,6 @@ public class RestFilterChainTests extends ElasticsearchTestCase {
return null;
}
@Override
public boolean contentThreadSafe() {
return false;
}
@Override
public BytesReference content() {
return null;