Skip to content
Browse files

Updated Thrift to 0.5.0 + Added the thrift file of MockMessage for ot…

…hers to understand
  • Loading branch information...
1 parent 0966e58 commit 3beffa824864b8ab6634854669f10b8bdb985228 @rsumbaly rsumbaly committed Mar 1, 2011
View
2 .classpath
@@ -41,7 +41,6 @@
<classpathentry kind="lib" path="lib/commons-pool-1.5.2.jar"/>
<classpathentry kind="lib" path="lib/protobuf-java-2.3.0.jar"/>
<classpathentry kind="lib" path="contrib/ec2-testing/lib/typica.jar"/>
- <classpathentry kind="lib" path="lib/libthrift-0.2.0.jar"/>
<classpathentry kind="lib" path="lib/paranamer-2.1.jar"/>
<classpathentry kind="lib" path="lib/jackson-mapper-asl-1.4.0.jar"/>
<classpathentry kind="lib" path="lib/jackson-core-asl-1.4.0.jar"/>
@@ -52,5 +51,6 @@
<classpathentry kind="lib" path="lib/je-4.0.92.jar"/>
<classpathentry kind="lib" path="lib/mockito-all-1.8.5.jar"/>
<classpathentry kind="lib" path="lib/avro-1.4.0.jar"/>
+ <classpathentry kind="lib" path="lib/libthrift-0.5.0.jar"/>
<classpathentry kind="output" path="classes"/>
</classpath>
View
BIN lib/libthrift-0.2.0.jar
Binary file not shown.
View
BIN lib/libthrift-0.5.0.jar
Binary file not shown.
View
2 src/java/voldemort/serialization/DefaultSerializerFactory.java
@@ -72,7 +72,7 @@
} else if(name.equals(PROTO_BUF_TYPE_NAME)) {
return new ProtoBufSerializer<Message>(serializerDef.getCurrentSchemaInfo());
} else if(name.equals(THRIFT_TYPE_NAME)) {
- return new ThriftSerializer<TBase<?>>(serializerDef.getCurrentSchemaInfo());
+ return new ThriftSerializer<TBase<?,?>>(serializerDef.getCurrentSchemaInfo());
} else if(name.equals(AVRO_GENERIC_TYPE_NAME)) {
return new AvroGenericSerializer(serializerDef.getCurrentSchemaInfo());
} else if(name.equals(AVRO_SPECIFIC_TYPE_NAME)) {
View
4 src/java/voldemort/serialization/SerializationUtils.java
@@ -26,15 +26,15 @@
private static final Logger logger = Logger.getLogger(SerializationUtils.class);
- private static final String ONLY_JAVA_CLIENTS_SUPPORTED = "Only Java clients are supported currently, so the format of the schema-info should be: <schema-info>java=foo.Bar</schema-info> where foo.Bar is the fully qualified name of the message.";
-
/**
* Extracts the java class name from the schema info
*
* @param schemaInfo the schema info, a string like: java=java.lang.String
* @return the name of the class extracted from the schema info
*/
public static String getJavaClassFromSchemaInfo(String schemaInfo) {
+ final String ONLY_JAVA_CLIENTS_SUPPORTED = "Only Java clients are supported currently, so the format of the schema-info should be: <schema-info>java=foo.Bar</schema-info> where foo.Bar is the fully qualified name of the message.";
+
if(StringUtils.isEmpty(schemaInfo))
throw new IllegalArgumentException("This serializer requires a non-empty schema-info.");
View
2 src/java/voldemort/serialization/thrift/ThriftSerializer.java
@@ -30,7 +30,7 @@
* languages is available, a semi-colon separated list will be accepted for the
* schema-info element (one for each language).
*/
-public class ThriftSerializer<T extends TBase<?>> implements Serializer<T> {
+public class ThriftSerializer<T extends TBase<?, ?>> implements Serializer<T> {
private static final String ONLY_JAVA_CLIENTS_SUPPORTED = "Only Java clients are supported currently, so the format of the schema-info should be: <schema-info>java=com.xyz.Foo,protocol=binary</schema-info> where com.xyz.Foo is the fully qualified name of the message.";
View
290 test/unit/voldemort/serialization/thrift/MockMessage.java
@@ -2,15 +2,6 @@
* Autogenerated by Thrift
*
* DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
- *
- * Here is the thrift file that defines the MockMessage struct.
- *
- * #!thrift --gen java
- *
- * namespace java voldemort.serialization.thrift
- *
- * struct MockMessage { 1: string name, 2: map<i64, map<string, i32>> mappings,
- * 3: list<i16> intList, 4: set<string> strSet, }
*/
package voldemort.serialization.thrift;
@@ -25,6 +16,7 @@
import java.util.Set;
import org.apache.thrift.TBase;
+import org.apache.thrift.TBaseHelper;
import org.apache.thrift.TException;
import org.apache.thrift.TFieldIdEnum;
import org.apache.thrift.TFieldRequirementType;
@@ -42,8 +34,8 @@
import org.apache.thrift.protocol.TStruct;
import org.apache.thrift.protocol.TType;
-@SuppressWarnings("serial")
-public class MockMessage implements TBase<MockMessage._Fields>, java.io.Serializable, Cloneable {
+public class MockMessage implements TBase<MockMessage, MockMessage._Fields>, java.io.Serializable,
+ Cloneable {
private static final TStruct STRUCT_DESC = new TStruct("MockMessage");
@@ -67,12 +59,10 @@
INT_LIST((short) 3, "intList"),
STR_SET((short) 4, "strSet");
- private static final Map<Integer, _Fields> byId = new HashMap<Integer, _Fields>();
private static final Map<String, _Fields> byName = new HashMap<String, _Fields>();
static {
for(_Fields field: EnumSet.allOf(_Fields.class)) {
- byId.put((int) field._thriftId, field);
byName.put(field.getFieldName(), field);
}
}
@@ -82,7 +72,18 @@
* found.
*/
public static _Fields findByThriftId(int fieldId) {
- return byId.get(fieldId);
+ switch(fieldId) {
+ case 1: // NAME
+ return NAME;
+ case 2: // MAPPINGS
+ return MAPPINGS;
+ case 3: // INT_LIST
+ return INT_LIST;
+ case 4: // STR_SET
+ return STR_SET;
+ default:
+ return null;
+ }
}
/**
@@ -123,32 +124,30 @@ public String getFieldName() {
// isset id assignments
- public static final Map<_Fields, FieldMetaData> metaDataMap = Collections.unmodifiableMap(new EnumMap<_Fields, FieldMetaData>(_Fields.class) {
-
- {
- put(_Fields.NAME, new FieldMetaData("name",
- TFieldRequirementType.DEFAULT,
- new FieldValueMetaData(TType.STRING)));
- put(_Fields.MAPPINGS,
- new FieldMetaData("mappings",
- TFieldRequirementType.DEFAULT,
- new MapMetaData(TType.MAP,
- new FieldValueMetaData(TType.I64),
- new MapMetaData(TType.MAP,
- new FieldValueMetaData(TType.STRING),
- new FieldValueMetaData(TType.I32)))));
- put(_Fields.INT_LIST,
- new FieldMetaData("intList",
- TFieldRequirementType.DEFAULT,
- new ListMetaData(TType.LIST, new FieldValueMetaData(TType.I16))));
- put(_Fields.STR_SET,
- new FieldMetaData("strSet",
- TFieldRequirementType.DEFAULT,
- new SetMetaData(TType.SET, new FieldValueMetaData(TType.STRING))));
- }
- });
-
+ public static final Map<_Fields, FieldMetaData> metaDataMap;
static {
+ Map<_Fields, FieldMetaData> tmpMap = new EnumMap<_Fields, FieldMetaData>(_Fields.class);
+ tmpMap.put(_Fields.NAME, new FieldMetaData("name",
+ TFieldRequirementType.DEFAULT,
+ new FieldValueMetaData(TType.STRING)));
+ tmpMap.put(_Fields.MAPPINGS,
+ new FieldMetaData("mappings",
+ TFieldRequirementType.DEFAULT,
+ new MapMetaData(TType.MAP,
+ new FieldValueMetaData(TType.I64),
+ new MapMetaData(TType.MAP,
+ new FieldValueMetaData(TType.STRING),
+ new FieldValueMetaData(TType.I32)))));
+ tmpMap.put(_Fields.INT_LIST,
+ new FieldMetaData("intList",
+ TFieldRequirementType.DEFAULT,
+ new ListMetaData(TType.LIST, new FieldValueMetaData(TType.I16))));
+ tmpMap.put(_Fields.STR_SET,
+ new FieldMetaData("strSet",
+ TFieldRequirementType.DEFAULT,
+ new SetMetaData(TType.SET,
+ new FieldValueMetaData(TType.STRING))));
+ metaDataMap = Collections.unmodifiableMap(tmpMap);
FieldMetaData.addStructMetaDataMap(MockMessage.class, metaDataMap);
}
@@ -219,10 +218,11 @@ public MockMessage deepCopy() {
return new MockMessage(this);
}
- @Override
- @Deprecated
- public MockMessage clone() {
- return new MockMessage(this);
+ public void clear() {
+ this.name = null;
+ this.mappings = null;
+ this.intList = null;
+ this.strSet = null;
}
public String getName() {
@@ -374,7 +374,6 @@ public void setStrSetIsSet(boolean value) {
}
}
- @SuppressWarnings("unchecked")
public void setFieldValue(_Fields field, Object value) {
switch(field) {
case NAME:
@@ -412,10 +411,6 @@ public void setFieldValue(_Fields field, Object value) {
}
}
- public void setFieldValue(int fieldID, Object value) {
- setFieldValue(_Fields.findByThriftIdOrThrow(fieldID), value);
- }
-
public Object getFieldValue(_Fields field) {
switch(field) {
case NAME:
@@ -434,15 +429,15 @@ public Object getFieldValue(_Fields field) {
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 NAME:
return isSetName();
@@ -456,10 +451,6 @@ public boolean isSet(_Fields field) {
throw new IllegalStateException();
}
- public boolean isSet(int fieldID) {
- return isSet(_Fields.findByThriftIdOrThrow(fieldID));
- }
-
@Override
public boolean equals(Object that) {
if(that == null)
@@ -517,6 +508,61 @@ public int hashCode() {
return 0;
}
+ public int compareTo(MockMessage other) {
+ if(!getClass().equals(other.getClass())) {
+ return getClass().getName().compareTo(other.getClass().getName());
+ }
+
+ int lastComparison = 0;
+ MockMessage typedOther = (MockMessage) other;
+
+ lastComparison = Boolean.valueOf(isSetName()).compareTo(typedOther.isSetName());
+ if(lastComparison != 0) {
+ return lastComparison;
+ }
+ if(isSetName()) {
+ lastComparison = TBaseHelper.compareTo(this.name, typedOther.name);
+ if(lastComparison != 0) {
+ return lastComparison;
+ }
+ }
+ lastComparison = Boolean.valueOf(isSetMappings()).compareTo(typedOther.isSetMappings());
+ if(lastComparison != 0) {
+ return lastComparison;
+ }
+ if(isSetMappings()) {
+ lastComparison = TBaseHelper.compareTo(this.mappings, typedOther.mappings);
+ if(lastComparison != 0) {
+ return lastComparison;
+ }
+ }
+ lastComparison = Boolean.valueOf(isSetIntList()).compareTo(typedOther.isSetIntList());
+ if(lastComparison != 0) {
+ return lastComparison;
+ }
+ if(isSetIntList()) {
+ lastComparison = TBaseHelper.compareTo(this.intList, typedOther.intList);
+ if(lastComparison != 0) {
+ return lastComparison;
+ }
+ }
+ lastComparison = Boolean.valueOf(isSetStrSet()).compareTo(typedOther.isSetStrSet());
+ if(lastComparison != 0) {
+ return lastComparison;
+ }
+ if(isSetStrSet()) {
+ lastComparison = TBaseHelper.compareTo(this.strSet, typedOther.strSet);
+ if(lastComparison != 0) {
+ return lastComparison;
+ }
+ }
+ return 0;
+ }
+
+ public _Fields fieldForId(int fieldId) {
+ return _Fields.findByThriftId(fieldId);
+ }
+
public void read(TProtocol iprot) throws TException {
TField field;
iprot.readStructBegin();
@@ -525,82 +571,79 @@ public void read(TProtocol iprot) throws TException {
if(field.type == TType.STOP) {
break;
}
- _Fields fieldId = _Fields.findByThriftId(field.id);
- if(fieldId == null) {
- TProtocolUtil.skip(iprot, field.type);
- } else {
- switch(fieldId) {
- case NAME:
- if(field.type == TType.STRING) {
- this.name = iprot.readString();
- } else {
- TProtocolUtil.skip(iprot, field.type);
- }
- break;
- case MAPPINGS:
- if(field.type == TType.MAP) {
- {
- TMap _map0 = iprot.readMapBegin();
- this.mappings = new HashMap<Long, Map<String, Integer>>(2 * _map0.size);
- for(int _i1 = 0; _i1 < _map0.size; ++_i1) {
- long _key2;
- Map<String, Integer> _val3;
- _key2 = iprot.readI64();
- {
- TMap _map4 = iprot.readMapBegin();
- _val3 = new HashMap<String, Integer>(2 * _map4.size);
- for(int _i5 = 0; _i5 < _map4.size; ++_i5) {
- String _key6;
- int _val7;
- _key6 = iprot.readString();
- _val7 = iprot.readI32();
- _val3.put(_key6, _val7);
- }
- iprot.readMapEnd();
+ switch(field.id) {
+ case 1: // NAME
+ if(field.type == TType.STRING) {
+ this.name = iprot.readString();
+ } else {
+ TProtocolUtil.skip(iprot, field.type);
+ }
+ break;
+ case 2: // MAPPINGS
+ if(field.type == TType.MAP) {
+ {
+ TMap _map0 = iprot.readMapBegin();
+ this.mappings = new HashMap<Long, Map<String, Integer>>(2 * _map0.size);
+ for(int _i1 = 0; _i1 < _map0.size; ++_i1) {
+ long _key2;
+ Map<String, Integer> _val3;
+ _key2 = iprot.readI64();
+ {
+ TMap _map4 = iprot.readMapBegin();
+ _val3 = new HashMap<String, Integer>(2 * _map4.size);
+ for(int _i5 = 0; _i5 < _map4.size; ++_i5) {
+ String _key6;
+ int _val7;
+ _key6 = iprot.readString();
+ _val7 = iprot.readI32();
+ _val3.put(_key6, _val7);
}
- this.mappings.put(_key2, _val3);
+ iprot.readMapEnd();
}
- iprot.readMapEnd();
+ this.mappings.put(_key2, _val3);
}
- } else {
- TProtocolUtil.skip(iprot, field.type);
+ iprot.readMapEnd();
}
- break;
- case INT_LIST:
- if(field.type == TType.LIST) {
- {
- TList _list8 = iprot.readListBegin();
- this.intList = new ArrayList<Short>(_list8.size);
- for(int _i9 = 0; _i9 < _list8.size; ++_i9) {
- short _elem10;
- _elem10 = iprot.readI16();
- this.intList.add(_elem10);
- }
- iprot.readListEnd();
+ } else {
+ TProtocolUtil.skip(iprot, field.type);
+ }
+ break;
+ case 3: // INT_LIST
+ if(field.type == TType.LIST) {
+ {
+ TList _list8 = iprot.readListBegin();
+ this.intList = new ArrayList<Short>(_list8.size);
+ for(int _i9 = 0; _i9 < _list8.size; ++_i9) {
+ short _elem10;
+ _elem10 = iprot.readI16();
+ this.intList.add(_elem10);
}
- } else {
- TProtocolUtil.skip(iprot, field.type);
+ iprot.readListEnd();
}
- break;
- case STR_SET:
- if(field.type == TType.SET) {
- {
- TSet _set11 = iprot.readSetBegin();
- this.strSet = new HashSet<String>(2 * _set11.size);
- for(int _i12 = 0; _i12 < _set11.size; ++_i12) {
- String _elem13;
- _elem13 = iprot.readString();
- this.strSet.add(_elem13);
- }
- iprot.readSetEnd();
+ } else {
+ TProtocolUtil.skip(iprot, field.type);
+ }
+ break;
+ case 4: // STR_SET
+ if(field.type == TType.SET) {
+ {
+ TSet _set11 = iprot.readSetBegin();
+ this.strSet = new HashSet<String>(2 * _set11.size);
+ for(int _i12 = 0; _i12 < _set11.size; ++_i12) {
+ String _elem13;
+ _elem13 = iprot.readString();
+ this.strSet.add(_elem13);
}
- } else {
- TProtocolUtil.skip(iprot, field.type);
+ iprot.readSetEnd();
}
- break;
- }
- iprot.readFieldEnd();
+ } else {
+ TProtocolUtil.skip(iprot, field.type);
+ }
+ break;
+ default:
+ TProtocolUtil.skip(iprot, field.type);
}
+ iprot.readFieldEnd();
}
iprot.readStructEnd();
@@ -707,7 +750,6 @@ public String toString() {
return sb.toString();
}
- @SuppressWarnings("unused")
public void validate() throws TException {
// check for required fields
}
View
28 test/unit/voldemort/serialization/thrift/MockMessage.thrift
@@ -0,0 +1,28 @@
+#
+# Copyright 2011 LinkedIn, Inc
+#
+# Licensed 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.
+#
+
+# To generate the java -
+# > thrift --gen java MockMessage.thrift
+#
+namespace java voldemort.serialization.thrift
+
+struct MockMessage
+{
+1: string name,
+2: map<i64, map<string, i32>> mappings,
+3: list<i16> intList,
+4: set<string> strSet
+}

0 comments on commit 3beffa8

Please sign in to comment.
Something went wrong with that request. Please try again.