本文整理汇总了Java中org.apache.thrift.TFieldIdEnum.getFieldName方法的典型用法代码示例。如果您正苦于以下问题:Java TFieldIdEnum.getFieldName方法的具体用法?Java TFieldIdEnum.getFieldName怎么用?Java TFieldIdEnum.getFieldName使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.thrift.TFieldIdEnum
的用法示例。
在下文中一共展示了TFieldIdEnum.getFieldName方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getResult
import org.apache.thrift.TFieldIdEnum; //导入方法依赖的package包/类
/**
* Converts the specified {@code result} into a Java object.
*/
public Object getResult(TBase<?, ?> result) throws TException {
for (TFieldIdEnum fieldIdEnum : exceptionFields()) {
if (ThriftFieldAccess.isSet(result, fieldIdEnum)) {
throw (TException) ThriftFieldAccess.get(result, fieldIdEnum);
}
}
final TFieldIdEnum successField = successField();
if (successField == null) { //void method
return null;
} else if (ThriftFieldAccess.isSet(result, successField)) {
return ThriftFieldAccess.get(result, successField);
} else {
throw new TApplicationException(
TApplicationException.MISSING_RESULT,
result.getClass().getName() + '.' + successField.getFieldName());
}
}
示例2: ThriftFunction
import org.apache.thrift.TFieldIdEnum; //导入方法依赖的package包/类
private ThriftFunction(
Class<?> serviceType, String name, Object func, Type type,
TFieldIdEnum[] argFields, TBase<?, ?> result, Class<?>[] declaredExceptions) throws Exception {
this.func = func;
this.type = type;
this.serviceType = serviceType;
this.name = name;
this.argFields = argFields;
this.result = result;
this.declaredExceptions = declaredExceptions;
// Determine the success and exception fields of the function.
final ImmutableMap.Builder<Class<Throwable>, TFieldIdEnum> exceptionFieldsBuilder =
ImmutableMap.builder();
TFieldIdEnum successField = null;
if (result != null) { // if not oneway
@SuppressWarnings("unchecked")
final Class<? extends TBase<?, ?>> resultType = (Class<? extends TBase<?, ?>>) result.getClass();
@SuppressWarnings("unchecked")
final Map<TFieldIdEnum, FieldMetaData> metaDataMap =
(Map<TFieldIdEnum, FieldMetaData>) FieldMetaData.getStructMetaDataMap(resultType);
for (Entry<TFieldIdEnum, FieldMetaData> e : metaDataMap.entrySet()) {
final TFieldIdEnum key = e.getKey();
final String fieldName = key.getFieldName();
if ("success".equals(fieldName)) {
successField = key;
continue;
}
Class<?> fieldType = resultType.getField(fieldName).getType();
if (Throwable.class.isAssignableFrom(fieldType)) {
@SuppressWarnings("unchecked")
Class<Throwable> exceptionFieldType = (Class<Throwable>) fieldType;
exceptionFieldsBuilder.put(exceptionFieldType, key);
}
}
}
this.successField = successField;
exceptionFields = exceptionFieldsBuilder.build();
}
示例3: getTBaseFields
import org.apache.thrift.TFieldIdEnum; //导入方法依赖的package包/类
private Map<Short, ThriftFieldMetadata> getTBaseFields(Class<? extends TBase> tbase) throws TException {
try {
// First read if the ThriftFieldMetadata was not already readed
Map<Class<?>,Map<Short, ThriftFieldMetadata>> thriftFields = threadSafeTFields.get();
if(thriftFields==null){
thriftFields = new HashMap<>();
}
Map<Short, ThriftFieldMetadata> thriftStructFields = thriftFields.get(tbase);
// Finded return it
if(thriftStructFields!=null){
return thriftStructFields;
}
// Load it
thriftStructFields = new HashMap<>();
Field metafaField = tbase.getField("metaDataMap");
Map<?, FieldMetaData> fields = (Map<?, org.apache.thrift.meta_data.FieldMetaData>) metafaField.get(tbase);
// list all fields
for (Map.Entry<?, FieldMetaData> entry : fields.entrySet()) {
TFieldIdEnum field = (TFieldIdEnum) entry.getKey();
ThriftFieldMetadata tfieldMetadata = new ThriftFieldMetadata();
// An enum type is deserialized as an I32
byte type = entry.getValue().valueMetaData.type;
if (TType.ENUM == type) {
type = TType.I32;
}
TBSONSecuredWrapper.ThriftSecuredField securedField=tbsonSecuredWrapper.getField(tbase, field.getThriftFieldId());
tfieldMetadata.tfield = new TField(field.getFieldName(), type, field.getThriftFieldId());
tfieldMetadata.fieldMetaData = entry.getValue();
tfieldMetadata.tbaseClass = tbase;
tfieldMetadata.securedFieldMetaData=securedField;
thriftStructFields.put( field.getThriftFieldId(), tfieldMetadata);
}
//store it
thriftFields.put(tbase, thriftStructFields);
threadSafeTFields.set(thriftFields);
return thriftStructFields;
} catch(Exception exp) {
throw new TException(exp);
}
}
示例4: secureThriftFields
import org.apache.thrift.TFieldIdEnum; //导入方法依赖的package包/类
public void secureThriftFields(Class<? extends TBase> tbase, boolean hash, TFieldIdEnum... fields) throws Exception {
Map<Short, ThriftSecuredField> classSecuredFields = securedFields.get(tbase);
if(classSecuredFields==null) {
classSecuredFields = new ConcurrentHashMap<>();
}
// get the Field class
Class<?> fieldClass = null;
Class<?>[] innerClasses = tbase.getClasses();
for (Class<?> innerClass : innerClasses) {
if ("_Fields".equals(innerClass.getSimpleName())) {
fieldClass = innerClass;
break;
}
}
// extract _Fields
Class[] findByNameArgs = new Class[1];
findByNameArgs[0] = String.class;
Method findByNameMethod = fieldClass.getMethod("findByName", findByNameArgs);
// extract metadataMap
Field metafaField = tbase.getField("metaDataMap");
Map<?, FieldMetaData> metaDataMap = (Map<?, org.apache.thrift.meta_data.FieldMetaData>) metafaField.get(tbase);
for(TFieldIdEnum field : fields) {
// get the _Field instance
org.apache.thrift.TFieldIdEnum tfieldEnum = (TFieldIdEnum) findByNameMethod.invoke(null, field.getFieldName());
// get the matadata
FieldMetaData fieldMetaData = metaDataMap.get(tfieldEnum);
// only string are supported
switch(fieldMetaData.valueMetaData.type) {
case TType.STRING:
break;
case TType.MAP:
MapMetaData mapMetaData = (MapMetaData) fieldMetaData.valueMetaData;
if (mapMetaData.valueMetaData.type != TType.STRING) {
throw new UnsupportedTTypeException("Unsupported secured type - FIELD:" + field.getFieldName() + " TYPE:" + mapMetaData.valueMetaData.type);
}
break;
default:
throw new UnsupportedTTypeException("Unsupported secured type - FIELD:" + field.getFieldName() + " TYPE:" + fieldMetaData.valueMetaData.type);
}
classSecuredFields.put(field.getThriftFieldId(), new ThriftSecuredField(true, hash));
}
securedFields.put(tbase,classSecuredFields);
}