当前位置: 首页>>代码示例>>Java>>正文


Java TFieldIdEnum类代码示例

本文整理汇总了Java中org.apache.thrift.TFieldIdEnum的典型用法代码示例。如果您正苦于以下问题:Java TFieldIdEnum类的具体用法?Java TFieldIdEnum怎么用?Java TFieldIdEnum使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


TFieldIdEnum类属于org.apache.thrift包,在下文中一共展示了TFieldIdEnum类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: printTbase

import org.apache.thrift.TFieldIdEnum; //导入依赖的package包/类
/**
 * Prints a TBase.
 *
 * @param t The object to print.
 * @param depth The print nesting level.
 * @return The pretty-printed version of the TBase.
 */
private static String printTbase(TBase t, int depth) {
  List<String> fields = Lists.newArrayList();
  for (Map.Entry<? extends TFieldIdEnum, FieldMetaData> entry :
      FieldMetaData.getStructMetaDataMap(t.getClass()).entrySet()) {
    @SuppressWarnings("unchecked")
    boolean fieldSet = t.isSet(entry.getKey());
    String strValue;
    if (fieldSet) {
      @SuppressWarnings("unchecked")
      Object value = t.getFieldValue(entry.getKey());
      strValue = printValue(value, depth);
    } else {
      strValue = "not set";
    }
    fields.add(tabs(depth) + entry.getValue().fieldName + ": " + strValue);
  }

  return Joiner.on("\n").join(fields);
}
 
开发者ID:PacktPublishing,项目名称:Mastering-Mesos,代码行数:27,代码来源:Util.java

示例2: newField

import org.apache.thrift.TFieldIdEnum; //导入依赖的package包/类
/**
 * Struct use only.
 * 
 * @return
 */
public TField newField() {
	if (createIndex < obj.length()) {
		Map.Entry<TFieldIdEnum, FieldMetaData> entry = null;
		if (addStep == 2) {
			String fieldName = obj.getString(createIndex << 1);
			entry = elementMetas.get(fieldName);
			createIndex++;
		} else {
			int i = createIndex;
			Object o;
			while (i < obj.length() && ((o = obj.get(i)) == null || o == JSONObject.NULL)) {
				currentIndex();// array index: +1
				i++;
			}
			entry = elementMetaArr[i];
			createIndex = i + 1;
		}
		FieldMetaData fm = entry.getValue();
		prevFieldMetaData = fm;
		return new TField(fm.fieldName, fm.valueMetaData.type, entry.getKey().getThriftFieldId());
	}
	return null;
}
 
开发者ID:houkx,项目名称:nettythrift,代码行数:29,代码来源:BaseArray.java

示例3: thriftToMap

import org.apache.thrift.TFieldIdEnum; //导入依赖的package包/类
public static  Map<String, Object> thriftToMap(
		org.apache.thrift.TBase thriftObj) {
	Map<String, Object> ret = new HashMap<String, Object>();
	
	int i = 1;
	TFieldIdEnum field = thriftObj.fieldForId(i);
	while(field != null) {
		if (thriftObj.isSet(field)) {
			Object obj = thriftObj.getFieldValue(field);
			ret.put(field.getFieldName(), thriftToObject(obj));
			
		}
		field = thriftObj.fieldForId(++i);
	}
	
	return ret;
}
 
开发者ID:kkllwww007,项目名称:jstrom,代码行数:18,代码来源:JStormUtils.java

示例4: toRpcRequest

import org.apache.thrift.TFieldIdEnum; //导入依赖的package包/类
private static RpcRequest toRpcRequest(Class<?> serviceType, String method, TBase<?, ?> thriftArgs) {
    requireNonNull(thriftArgs, "thriftArgs");

    // NB: The map returned by FieldMetaData.getStructMetaDataMap() is an EnumMap,
    //     so the parameter ordering is preserved correctly during iteration.
    final Set<? extends TFieldIdEnum> fields =
            FieldMetaData.getStructMetaDataMap(thriftArgs.getClass()).keySet();

    // Handle the case where the number of arguments is 0 or 1.
    final int numFields = fields.size();
    switch (numFields) {
        case 0:
            return RpcRequest.of(serviceType, method);
        case 1:
            return RpcRequest.of(serviceType, method,
                                 ThriftFieldAccess.get(thriftArgs, fields.iterator().next()));
    }

    // Handle the case where the number of arguments is greater than 1.
    final List<Object> list = new ArrayList<>(numFields);
    for (TFieldIdEnum field : fields) {
        list.add(ThriftFieldAccess.get(thriftArgs, field));
    }

    return RpcRequest.of(serviceType, method, list);
}
 
开发者ID:line,项目名称:armeria,代码行数:27,代码来源:THttpService.java

示例5: 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());
    }
}
 
开发者ID:line,项目名称:armeria,代码行数:22,代码来源:ThriftFunction.java

示例6: listOf

import org.apache.thrift.TFieldIdEnum; //导入依赖的package包/类
/**
 * To consume a list of elements
 * @param c the type of the list content
 * @param consumer the consumer that will receive the list
 * @return a ListConsumer that can be passed to the DelegatingFieldConsumer
 */
public static <T extends TBase<T,? extends TFieldIdEnum>> ListConsumer listOf(Class<T> c, final Consumer<List<T>> consumer) {
  class ListConsumer implements Consumer<T> {
    List<T> list;
    @Override
    public void consume(T t) {
      list.add(t);
    }
  }
  final ListConsumer co = new ListConsumer();
  return new DelegatingListElementsConsumer(struct(c, co)) {
    @Override
    public void consumeList(TProtocol protocol,
        EventBasedThriftReader reader, TList tList) throws TException {
      co.list = new ArrayList<T>();
      super.consumeList(protocol, reader, tList);
      consumer.consume(co.list);
    }
  };
}
 
开发者ID:apache,项目名称:parquet-format,代码行数:26,代码来源:Consumers.java

示例7: ThriftRecordReader

import org.apache.thrift.TFieldIdEnum; //导入依赖的package包/类
public ThriftRecordReader(File dataFile, Schema schema, ThriftRecordReaderConfig recordReaderConfig) throws IOException, ClassNotFoundException, IllegalAccessException, InstantiationException {
    this._schema = schema;
    this._dataFile = dataFile;
    this._recordReaderConfig = recordReaderConfig;
    this._thriftClass = initThriftInstanceCreator();
    this._bufferIn = RecordReaderUtils.getFileBufferStream(dataFile);
    this._binaryIn = new TBinaryProtocol(new TIOStreamTransport(_bufferIn));
    this._fieldNameToIndexMap = new HashMap();
    TBase t = this._thriftClass.newInstance();
    int index = 1;
    TFieldIdEnum fieldIdEnum = null;
    do {
        fieldIdEnum = t.fieldForId(index);
        if (fieldIdEnum != null) {
            _fieldNameToIndexMap.put(fieldIdEnum.getFieldName(), index);
        }
        index = index + 1;
    } while (fieldIdEnum != null);
}
 
开发者ID:linkedin,项目名称:pinot,代码行数:20,代码来源:ThriftRecordReader.java

示例8: pushWriteField

import org.apache.thrift.TFieldIdEnum; //导入依赖的package包/类
private void pushWriteField(Class<? extends TBase> tbase, String fieldName) throws TException {
  //get the field ID by name
  org.apache.thrift.TFieldIdEnum tfieldIdEnum = getFieldId(tbase, fieldName);
  if(tfieldIdEnum!=null) {
    //pushWriteField(tfieldIdEnum.getThriftFieldId());
    Stack<ThriftFieldMetadata> writeStack = threadSafeFieldsStack.get();

    // First push
    if(writeStack==null) {
      writeStack = new Stack<>();
    }

    // Take the tbase class at the top of the stack
    ThriftFieldMetadata thriftFieldMetadata = getTBaseFields(tbase).get(tfieldIdEnum.getThriftFieldId());
    writeStack.push(thriftFieldMetadata);

    threadSafeFieldsStack.set(writeStack);
  }
}
 
开发者ID:BreizhBeans,项目名称:ThriftMongoBridge,代码行数:20,代码来源:TBSONUnstackedProtocol.java

示例9: thriftToMap

import org.apache.thrift.TFieldIdEnum; //导入依赖的package包/类
public static Map<String, Object> thriftToMap(
        org.apache.thrift.TBase thriftObj) {
    Map<String, Object> ret = new HashMap<>();

    int i = 1;
    TFieldIdEnum field = thriftObj.fieldForId(i);
    while (field != null) {
        if (thriftObj.isSet(field)) {
            Object obj = thriftObj.getFieldValue(field);
            ret.put(field.getFieldName(), thriftToObject(obj));

        }
        field = thriftObj.fieldForId(++i);
    }

    return ret;
}
 
开发者ID:alibaba,项目名称:jstorm,代码行数:18,代码来源:JStormUtils.java

示例10: createUnion

import org.apache.thrift.TFieldIdEnum; //导入依赖的package包/类
@SuppressWarnings({"unchecked", "rawtypes"})
private static TUnion<?, ?> createUnion(
    Class<?> unionType,
    TFieldIdEnum setField,
    Object fieldValue) throws IllegalAccessException, InstantiationException {

  TUnion union = (TUnion) unionType.newInstance();
  union.setFieldValue(setField, fieldValue);
  return union;
}
 
开发者ID:PacktPublishing,项目名称:Mastering-Mesos,代码行数:11,代码来源:GsonMessageBodyHandler.java

示例11: getMetadataMap

import org.apache.thrift.TFieldIdEnum; //导入依赖的package包/类
private static Map<TFieldIdEnum, FieldMetaData> 
  getMetadataMap(Class c) 
{
  try {
    Object o = c.newInstance();
    return (Map) c.getField("metaDataMap").get(o);
  } catch (Exception e) {
    throw new RuntimeException(e);
  }
}
 
开发者ID:zirpins,项目名称:bdelab,代码行数:11,代码来源:SplitDataPailStructure.java

示例12: getIdForClass

import org.apache.thrift.TFieldIdEnum; //导入依赖的package包/类
private static TFieldIdEnum getIdForClass(
  Map<TFieldIdEnum, FieldMetaData> meta,
  Class toFind) 
{
  for(TFieldIdEnum k: meta.keySet()) {
    FieldValueMetaData md = meta.get(k).valueMetaData;
    if(md instanceof StructMetaData) {
      if(toFind.equals(((StructMetaData) md).structClass)) {
        return k;
      }
    }
  }
  throw new RuntimeException("Could not find " + toFind.toString() +
                             " in " + meta.toString());
}
 
开发者ID:zirpins,项目名称:bdelab,代码行数:16,代码来源:SplitDataPailStructure.java

示例13: PropertyStructure

import org.apache.thrift.TFieldIdEnum; //导入依赖的package包/类
public PropertyStructure(Class prop) {
  try {
    Map<TFieldIdEnum, FieldMetaData> propMeta = getMetadataMap(prop);
    Class valClass = Class.forName(prop.getName() + "Value");
    valueId = getIdForClass(propMeta, valClass);

    validIds = new HashSet<Short>();
    Map<TFieldIdEnum, FieldMetaData> valMeta = getMetadataMap(valClass);
    for(TFieldIdEnum valId: valMeta.keySet()) {
      validIds.add(valId.getThriftFieldId());
    }
  } catch(Exception e) {
    throw new RuntimeException(e);
  }
}
 
开发者ID:zirpins,项目名称:bdelab,代码行数:16,代码来源:SplitDataPailStructure.java

示例14: setException

import org.apache.thrift.TFieldIdEnum; //导入依赖的package包/类
/**
 * Sets the exception field of the specified {@code result} to the specified {@code cause}.
 */
public boolean setException(TBase<?, ?> result, Throwable cause) {
    Class<?> causeType = cause.getClass();
    for (Entry<Class<Throwable>, TFieldIdEnum> e : exceptionFields.entrySet()) {
        if (e.getKey().isAssignableFrom(causeType)) {
            ThriftFieldAccess.set(result, e.getValue(), cause);
            return true;
        }
    }
    return false;
}
 
开发者ID:line,项目名称:armeria,代码行数:14,代码来源:ThriftFunction.java

示例15: getArgFields0

import org.apache.thrift.TFieldIdEnum; //导入依赖的package包/类
private static TFieldIdEnum[] getArgFields0(Type type, Class<?> funcClass, String methodName) {
    final String fieldIdEnumTypeName = typeName(type, funcClass, methodName, methodName + "_args$_Fields");
    try {
        Class<?> fieldIdEnumType = Class.forName(fieldIdEnumTypeName, false, funcClass.getClassLoader());
        return (TFieldIdEnum[]) requireNonNull(fieldIdEnumType.getEnumConstants(),
                                               "field enum may not be empty");
    } catch (Exception e) {
        throw new IllegalStateException("cannot determine the arg fields of method: " + methodName, e);
    }
}
 
开发者ID:line,项目名称:armeria,代码行数:11,代码来源:ThriftFunction.java


注:本文中的org.apache.thrift.TFieldIdEnum类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。