Transport Thrift: Upgrade to thrift 0.5.0, closes #457.

This commit is contained in:
kimchy 2010-10-27 23:12:53 +02:00
parent d487d809ea
commit b8708f276d
7 changed files with 106 additions and 84 deletions

View File

@ -16,7 +16,7 @@
<orderEntry type="module-library">
<library name="libthrift">
<CLASSES>
<root url="jar://$GRADLE_REPOSITORY$/org.elasticsearch/es-libthrift/jars/es-libthrift-0.4.0.jar!/" />
<root url="jar://$GRADLE_REPOSITORY$/org.elasticsearch/es-libthrift/jars/es-libthrift-0.5.0.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />

View File

@ -33,11 +33,11 @@ configurations {
dependencies {
compile project(':elasticsearch')
compile 'org.elasticsearch:es-libthrift:0.4.0'
compile 'org.elasticsearch:es-libthrift:0.5.0'
compile 'org.slf4j:slf4j-api:1.5.11'
compile('org.slf4j:slf4j-log4j12:1.5.11') { transitive = false }
distLib("org.elasticsearch:es-libthrift:0.4.0") { transitive = false }
distLib("org.elasticsearch:es-libthrift:0.5.0") { transitive = false }
distLib 'org.slf4j:slf4j-api:1.5.11'
distLib('org.slf4j:slf4j-log4j12:1.5.11') { transitive = false }

View File

@ -315,11 +315,6 @@ public class Rest {
return new execute_args(this);
}
@Deprecated
public execute_args clone() {
return new execute_args(this);
}
@Override
public void clear() {
this.request = null;
@ -364,10 +359,6 @@ public class Rest {
}
}
public void setFieldValue(int fieldID, Object value) {
setFieldValue(_Fields.findByThriftIdOrThrow(fieldID), value);
}
public Object getFieldValue(_Fields field) {
switch (field) {
case REQUEST:
@ -377,14 +368,14 @@ public class Rest {
throw new IllegalStateException();
}
public Object getFieldValue(int fieldId) {
return getFieldValue(_Fields.findByThriftIdOrThrow(fieldId));
}
/**
* Returns true if field corresponding to fieldID is set (has been asigned a value) and false otherwise
*/
public boolean isSet(_Fields field) {
if (field == null) {
throw new IllegalArgumentException();
}
switch (field) {
case REQUEST:
return isSetRequest();
@ -392,10 +383,6 @@ public class Rest {
throw new IllegalStateException();
}
public boolean isSet(int fieldID) {
return isSet(_Fields.findByThriftIdOrThrow(fieldID));
}
@Override
public boolean equals(Object that) {
if (that == null)
@ -447,6 +434,10 @@ public class Rest {
return 0;
}
public _Fields fieldForId(int fieldId) {
return _Fields.findByThriftId(fieldId);
}
public void read(TProtocol iprot) throws TException {
TField field;
iprot.readStructBegin();
@ -614,11 +605,6 @@ public class Rest {
return new execute_result(this);
}
@Deprecated
public execute_result clone() {
return new execute_result(this);
}
@Override
public void clear() {
this.success = null;
@ -663,10 +649,6 @@ public class Rest {
}
}
public void setFieldValue(int fieldID, Object value) {
setFieldValue(_Fields.findByThriftIdOrThrow(fieldID), value);
}
public Object getFieldValue(_Fields field) {
switch (field) {
case SUCCESS:
@ -676,14 +658,14 @@ public class Rest {
throw new IllegalStateException();
}
public Object getFieldValue(int fieldId) {
return getFieldValue(_Fields.findByThriftIdOrThrow(fieldId));
}
/**
* Returns true if field corresponding to fieldID is set (has been asigned a value) and false otherwise
*/
public boolean isSet(_Fields field) {
if (field == null) {
throw new IllegalArgumentException();
}
switch (field) {
case SUCCESS:
return isSetSuccess();
@ -691,10 +673,6 @@ public class Rest {
throw new IllegalStateException();
}
public boolean isSet(int fieldID) {
return isSet(_Fields.findByThriftIdOrThrow(fieldID));
}
@Override
public boolean equals(Object that) {
if (that == null)
@ -746,6 +724,10 @@ public class Rest {
return 0;
}
public _Fields fieldForId(int fieldId) {
return _Fields.findByThriftId(fieldId);
}
public void read(TProtocol iprot) throws TException {
TField field;
iprot.readStructBegin();

View File

@ -1,3 +1,22 @@
/*
* Licensed to Elastic Search and Shay Banon under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. Elastic Search licenses this
* file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
/**
* Autogenerated by Thrift
*
@ -184,8 +203,8 @@ public class RestRequest implements TBase<RestRequest, RestRequest._Fields>, jav
this.headers = __this__headers;
}
if (other.isSetBody()) {
this.body = ByteBuffer.wrap(new byte[other.body.limit() - other.body.arrayOffset()]);
System.arraycopy(other.body.array(), other.body.arrayOffset(), body.array(), 0, other.body.limit() - other.body.arrayOffset());
this.body = TBaseHelper.copyBinary(other.body);
;
}
}
@ -193,11 +212,6 @@ public class RestRequest implements TBase<RestRequest, RestRequest._Fields>, jav
return new RestRequest(this);
}
@Deprecated
public RestRequest clone() {
return new RestRequest(this);
}
@Override
public void clear() {
this.method = null;
@ -339,8 +353,18 @@ public class RestRequest implements TBase<RestRequest, RestRequest._Fields>, jav
}
}
public ByteBuffer getBody() {
return this.body;
public byte[] getBody() {
setBody(TBaseHelper.rightSize(body));
return body.array();
}
public ByteBuffer BufferForBody() {
return body;
}
public RestRequest setBody(byte[] body) {
setBody(ByteBuffer.wrap(body));
return this;
}
public RestRequest setBody(ByteBuffer body) {
@ -410,10 +434,6 @@ public class RestRequest implements TBase<RestRequest, RestRequest._Fields>, jav
}
}
public void setFieldValue(int fieldID, Object value) {
setFieldValue(_Fields.findByThriftIdOrThrow(fieldID), value);
}
public Object getFieldValue(_Fields field) {
switch (field) {
case METHOD:
@ -435,14 +455,14 @@ public class RestRequest implements TBase<RestRequest, RestRequest._Fields>, jav
throw new IllegalStateException();
}
public Object getFieldValue(int fieldId) {
return getFieldValue(_Fields.findByThriftIdOrThrow(fieldId));
}
/**
* Returns true if field corresponding to fieldID is set (has been asigned a value) and false otherwise
*/
public boolean isSet(_Fields field) {
if (field == null) {
throw new IllegalArgumentException();
}
switch (field) {
case METHOD:
return isSetMethod();
@ -458,10 +478,6 @@ public class RestRequest implements TBase<RestRequest, RestRequest._Fields>, jav
throw new IllegalStateException();
}
public boolean isSet(int fieldID) {
return isSet(_Fields.findByThriftIdOrThrow(fieldID));
}
@Override
public boolean equals(Object that) {
if (that == null)
@ -589,6 +605,10 @@ public class RestRequest implements TBase<RestRequest, RestRequest._Fields>, jav
return 0;
}
public _Fields fieldForId(int fieldId) {
return _Fields.findByThriftId(fieldId);
}
public void read(TProtocol iprot) throws TException {
TField field;
iprot.readStructBegin();

View File

@ -1,3 +1,22 @@
/*
* Licensed to Elastic Search and Shay Banon under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. Elastic Search licenses this
* file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
/**
* Autogenerated by Thrift
*
@ -148,8 +167,8 @@ public class RestResponse implements TBase<RestResponse, RestResponse._Fields>,
this.headers = __this__headers;
}
if (other.isSetBody()) {
this.body = ByteBuffer.wrap(new byte[other.body.limit() - other.body.arrayOffset()]);
System.arraycopy(other.body.array(), other.body.arrayOffset(), body.array(), 0, other.body.limit() - other.body.arrayOffset());
this.body = TBaseHelper.copyBinary(other.body);
;
}
}
@ -157,11 +176,6 @@ public class RestResponse implements TBase<RestResponse, RestResponse._Fields>,
return new RestResponse(this);
}
@Deprecated
public RestResponse clone() {
return new RestResponse(this);
}
@Override
public void clear() {
this.status = null;
@ -238,8 +252,18 @@ public class RestResponse implements TBase<RestResponse, RestResponse._Fields>,
}
}
public ByteBuffer getBody() {
return this.body;
public byte[] getBody() {
setBody(TBaseHelper.rightSize(body));
return body.array();
}
public ByteBuffer BufferForBody() {
return body;
}
public RestResponse setBody(byte[] body) {
setBody(ByteBuffer.wrap(body));
return this;
}
public RestResponse setBody(ByteBuffer body) {
@ -293,10 +317,6 @@ public class RestResponse implements TBase<RestResponse, RestResponse._Fields>,
}
}
public void setFieldValue(int fieldID, Object value) {
setFieldValue(_Fields.findByThriftIdOrThrow(fieldID), value);
}
public Object getFieldValue(_Fields field) {
switch (field) {
case STATUS:
@ -312,14 +332,14 @@ public class RestResponse implements TBase<RestResponse, RestResponse._Fields>,
throw new IllegalStateException();
}
public Object getFieldValue(int fieldId) {
return getFieldValue(_Fields.findByThriftIdOrThrow(fieldId));
}
/**
* Returns true if field corresponding to fieldID is set (has been asigned a value) and false otherwise
*/
public boolean isSet(_Fields field) {
if (field == null) {
throw new IllegalArgumentException();
}
switch (field) {
case STATUS:
return isSetStatus();
@ -331,10 +351,6 @@ public class RestResponse implements TBase<RestResponse, RestResponse._Fields>,
throw new IllegalStateException();
}
public boolean isSet(int fieldID) {
return isSet(_Fields.findByThriftIdOrThrow(fieldID));
}
@Override
public boolean equals(Object that) {
if (that == null)
@ -424,6 +440,10 @@ public class RestResponse implements TBase<RestResponse, RestResponse._Fields>,
return 0;
}
public _Fields fieldForId(int fieldId) {
return _Fields.findByThriftId(fieldId);
}
public void read(TProtocol iprot) throws TException {
TField field;
iprot.readStructBegin();

View File

@ -80,7 +80,7 @@ public class ThriftRestRequest extends AbstractRestRequest implements org.elasti
}
@Override public boolean hasContent() {
return request.getBody() != null && request.getBody().remaining() > 0;
return request.isSetBody() && request.BufferForBody().remaining() > 0;
}
@Override public boolean contentUnsafe() {
@ -91,21 +91,21 @@ public class ThriftRestRequest extends AbstractRestRequest implements org.elasti
if (!request.isSetBody()) {
return Bytes.EMPTY_ARRAY;
}
return request.getBody().array();
return request.BufferForBody().array();
}
@Override public int contentByteArrayOffset() {
if (!request.isSetBody()) {
return 0;
}
return request.getBody().arrayOffset();
return request.BufferForBody().arrayOffset();
}
@Override public int contentLength() {
if (!request.isSetBody()) {
return 0;
}
return request.getBody().remaining();
return request.BufferForBody().remaining();
}
@Override public String contentAsString() {

View File

@ -83,6 +83,6 @@ public class SimpleThriftTests {
}
private Map<String, Object> parseBody(RestResponse response) throws IOException {
return XContentFactory.xContent(XContentType.JSON).createParser(response.getBody().array(), response.getBody().arrayOffset(), response.getBody().remaining()).map();
return XContentFactory.xContent(XContentType.JSON).createParser(response.BufferForBody().array(), response.BufferForBody().arrayOffset(), response.BufferForBody().remaining()).map();
}
}