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


Java TBase类代码示例

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


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

示例1: printTbase

import org.apache.thrift.TBase; //导入依赖的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: printValue

import org.apache.thrift.TBase; //导入依赖的package包/类
/**
 * Prints an object contained in a thrift message.
 *
 * @param o The object to print.
 * @param depth The print nesting level.
 * @return The pretty-printed version of the thrift field.
 */
private static String printValue(Object o, int depth) {
  if (o == null) {
    return "null";
  } else if (TBase.class.isAssignableFrom(o.getClass())) {
    return "\n" + printTbase((TBase) o, depth + 1);
  } else if (Map.class.isAssignableFrom(o.getClass())) {
    return printMap((Map) o, depth + 1);
  } else if (List.class.isAssignableFrom(o.getClass())) {
    return printList((List) o, depth + 1);
  } else if (Set.class.isAssignableFrom(o.getClass())) {
    return printSet((Set) o, depth + 1);
  } else if (String.class == o.getClass()) {
    return '"' + o.toString() + '"';
  } else {
    return o.toString();
  }
}
 
开发者ID:PacktPublishing,项目名称:Mastering-Mesos,代码行数:25,代码来源:Util.java

示例3: getStructClass

import org.apache.thrift.TBase; //导入依赖的package包/类
public static <P extends TBase<P, ?>, C extends TBase<C, ?>, G extends TBase<G, ?>>
    FieldGetter<P, G> compose(final FieldGetter<P, C> parent, final FieldGetter<C, G> child) {

  return new FieldGetter<P, G>() {
    @Override
    public Class<P> getStructClass() {
      return parent.getStructClass();
    }

    @Override
    public Class<G> getValueClass() {
      return child.getValueClass();
    }

    @Override
    public Optional<G> apply(P input) {
      Optional<C> parentValue = parent.apply(input);
      if (parentValue.isPresent()) {
        return child.apply(parentValue.get());
      } else {
        return Optional.absent();
      }
    }
  };
}
 
开发者ID:PacktPublishing,项目名称:Mastering-Mesos,代码行数:26,代码来源:FieldGetters.java

示例4: deflateNonNull

import org.apache.thrift.TBase; //导入依赖的package包/类
/**
 * Encodes a thrift object into a DEFLATE-compressed binary array.
 *
 * @param tBase Object to encode.
 * @return Deflated, encoded object.
 * @throws CodingException If the object could not be encoded.
 */
public static byte[] deflateNonNull(TBase<?, ?> tBase) throws CodingException {
  requireNonNull(tBase);

  // NOTE: Buffering is needed here for performance.
  // There are actually 2 buffers in play here - the BufferedOutputStream prevents thrift from
  // causing a call to deflate() on every encoded primitive. The DeflaterOutputStream buffer
  // allows the underlying Deflater to operate on a larger chunk at a time without stopping to
  // copy the intermediate compressed output to outBytes.
  // See http://bugs.java.com/bugdatabase/view_bug.do?bug_id=4986239
  ByteArrayOutputStream outBytes = new ByteArrayOutputStream();
  TTransport transport = new TIOStreamTransport(
      new BufferedOutputStream(
          new DeflaterOutputStream(outBytes, new Deflater(DEFLATE_LEVEL), DEFLATER_BUFFER_SIZE),
          DEFLATER_BUFFER_SIZE));
  try {
    TProtocol protocol = PROTOCOL_FACTORY.getProtocol(transport);
    tBase.write(protocol);
    transport.close(); // calls finish() on the underlying stream, completing the compression
    return outBytes.toByteArray();
  } catch (TException e) {
    throw new CodingException("Failed to serialize: " + tBase, e);
  } finally {
    transport.close();
  }
}
 
开发者ID:PacktPublishing,项目名称:Mastering-Mesos,代码行数:33,代码来源:ThriftBinaryCodec.java

示例5: inflateNonNull

import org.apache.thrift.TBase; //导入依赖的package包/类
/**
 * Decodes a thrift object from a DEFLATE-compressed byte array into a target type.
 *
 * @param clazz Class to instantiate and deserialize to.
 * @param buffer Compressed buffer to decode.
 * @return A populated message.
 * @throws CodingException If the message could not be decoded.
 */
public static <T extends TBase<T, ?>> T inflateNonNull(Class<T> clazz, byte[] buffer)
    throws CodingException {

  requireNonNull(clazz);
  requireNonNull(buffer);

  T tBase = newInstance(clazz);
  TTransport transport = new TIOStreamTransport(
        new InflaterInputStream(new ByteArrayInputStream(buffer)));
  try {
    TProtocol protocol = PROTOCOL_FACTORY.getProtocol(transport);
    tBase.read(protocol);
    return tBase;
  } catch (TException e) {
    throw new CodingException("Failed to deserialize: " + e, e);
  } finally {
    transport.close();
  }
}
 
开发者ID:PacktPublishing,项目名称:Mastering-Mesos,代码行数:28,代码来源:ThriftBinaryCodec.java

示例6: beforeWrite

import org.apache.thrift.TBase; //导入依赖的package包/类
@SuppressWarnings({ "rawtypes" })
@Override
public void beforeWrite(TMessage msg, TBase args, TBase result) {
	// reuse message's buffer when write? yes, we use the pool.
	ByteBuf readedBuf = message.getContent();
	int refCount = readedBuf.refCnt();
	if (refCount > 0) {
		readedBuf.release(refCount);
	}
	// voidMethod's return message is very short
	int initialCapacity = serverDef.trafficForecast.getInitBytesForWrite(msg.name);
	// logger.debug("initialCapacity = {} , msg = {}",initialCapacity, msg);
	ByteBuf buf = ctx.alloc().buffer(initialCapacity, serverDef.maxFrameSize);
	message.setContent(buf).beforeWrite(ctx);
	transport.setOutputBuffer(buf);
}
 
开发者ID:houkx,项目名称:nettythrift,代码行数:17,代码来源:DefaultWriterListener.java

示例7: writeResult

import org.apache.thrift.TBase; //导入依赖的package包/类
@SuppressWarnings("rawtypes")
private void writeResult(final TProtocol out, final TMessage msg, final WriterHandler onComplete, TBase args,
		final TBase result) {
	try {
		onComplete.beforeWrite(msg, args, result);
		// if (!isOneway()) {
		out.writeMessageBegin(new TMessage(msg.name, TMessageType.REPLY, msg.seqid));
		if (result != null) {
			result.write(out);
		} else {
			out.writeStructBegin(null);
			out.writeFieldStop();
			out.writeStructEnd();
		}
		out.writeMessageEnd();
		out.getTransport().flush();
		// }
		onComplete.afterWrite(msg, null, TMessageType.REPLY, args, result);
	} catch (Throwable e) {
		onComplete.afterWrite(msg, e, TMessageType.EXCEPTION, args, result);
	}
}
 
开发者ID:houkx,项目名称:nettythrift,代码行数:23,代码来源:DefaultNettyProcessor.java

示例8: openThriftReader

import org.apache.thrift.TBase; //导入依赖的package包/类
/**
 * This method will open the dictionary file stream for reading
 *
 * @throws IOException thrift reader open method throws IOException
 */
private void openThriftReader() throws IOException {
  // initialise dictionary file reader which will return dictionary thrift object
  // dictionary thrift object contains a list of byte buffer
  if (null == dictionaryMetadataFileReader) {
    dictionaryMetadataFileReader =
        new ThriftReader(this.columnDictionaryMetadataFilePath, new ThriftReader.TBaseCreator() {
          @Override public TBase create() {
            return new ColumnDictionaryChunkMeta();
          }
        });
    // Open it
    dictionaryMetadataFileReader.open();
  }

}
 
开发者ID:carbondata,项目名称:carbondata,代码行数:21,代码来源:CarbonDictionaryMetadataReaderImpl.java

示例9: openThriftReader

import org.apache.thrift.TBase; //导入依赖的package包/类
/**
 * This method will open the dictionary file stream for reading
 *
 * @throws IOException thrift reader open method throws IOException
 */
private void openThriftReader() throws IOException {
  if (null == dictionaryFileReader) {
    // initialise dictionary file reader which will return dictionary thrift object
    // dictionary thrift object contains a list of byte buffer
    dictionaryFileReader =
        new ThriftReader(this.columnDictionaryFilePath, new ThriftReader.TBaseCreator() {
          @Override public TBase create() {
            return new ColumnDictionaryChunk();
          }
        });
    // Open dictionary file reader
    dictionaryFileReader.open();
  }

}
 
开发者ID:carbondata,项目名称:carbondata,代码行数:21,代码来源:CarbonDictionaryReaderImpl.java

示例10: cypherToken

import org.apache.thrift.TBase; //导入依赖的package包/类
public String cypherToken(TBase<?, ?> token, KeyStore keyStore) throws TException {
  byte[] tokenAesKey = keyStore.getKey(KeyStore.AES_TOKEN);
  byte[] tokenSipHashkey = keyStore.getKey(KeyStore.SIPHASH_TOKEN);

  // Serialize the  thrift token into byte array
  byte[] serialized = serializer.serialize(token);

  // Calculate the SIP
  long sip = SipHashInline.hash24_palindromic(tokenSipHashkey, serialized);

  //Create the token byte buffer
  ByteBuffer buffer = ByteBuffer.allocate(8 + serialized.length);
  // adds the sip
  buffer.putLong(sip);
  // adds the thrift token
  buffer.put(serialized);

  // Wrap the TOKEN
  byte[] wrappedData = CryptoUtils.wrap(tokenAesKey, buffer.array());

  String accessToken = new String(OrderPreservingBase64.encode(wrappedData));

  return accessToken;
}
 
开发者ID:cityzendata,项目名称:warp10-platform,代码行数:25,代码来源:QuasarTokenEncoder.java

示例11: buildTransportRequest

import org.apache.thrift.TBase; //导入依赖的package包/类
private TransportRequest buildTransportRequest(
    DefaultCall<?> call, Context ctx, String procedure, TBase reqBody)
    throws ThriftEncodingException {
  TSerializer serializer = new TSerializer(protocolFactory);
  try {
    return DefaultTransportRequest.builder()
        .caller(clientConfig.getCaller())
        .service(clientConfig.getService())
        .procedure(procedure)
        .encoding(ThriftEncoding.ENCODING)
        .headers(call.getHeaders())
        .deadline(ctx.getDeadline())
        .span(ctx.getSpan())
        .body(TransportBody.fromByteArray(serializer.serialize(reqBody)))
        .build();
  } catch (TException e) {
    throw new ThriftEncodingException(e);
  }
}
 
开发者ID:yarpc,项目名称:yarpc-java,代码行数:20,代码来源:ThriftClient.java

示例12: deserialize

import org.apache.thrift.TBase; //导入依赖的package包/类
/**
 * Deserialize the Thrift object from a byte array.
 *
 * @param bytes   The array to read from
 */
public TBase<?, ?> deserialize(byte[] bytes) throws TException {
    try {
        trans.reset(bytes);
        Header header = readHeader();
        final int validate = validate(header);
        if (validate == HeaderUtils.OK) {
            TBase<?, ?> base = locator.tBaseLookup(header.getType());
            base.read(protocol);
            return base;
        }
        if (validate == HeaderUtils.PASS_L4) {
            return new L4Packet(header);
        }
        throw new IllegalStateException("invalid validate " + validate);
    } finally {
        trans.clear();
        protocol.reset();
    }
}
 
开发者ID:masonmei,项目名称:apm-agent,代码行数:25,代码来源:HeaderTBaseDeserializer.java

示例13: serialize

import org.apache.thrift.TBase; //导入依赖的package包/类
@Deprecated
public static void serialize(TSerializer serializer, TBase struct, DataOutput out)
throws IOException
{
    assert serializer != null;
    assert struct != null;
    assert out != null;
    byte[] bytes;
    try
    {
        bytes = serializer.serialize(struct);
    }
    catch (TException e)
    {
        throw new RuntimeException(e);
    }
    out.writeInt(bytes.length);
    out.write(bytes);
}
 
开发者ID:vcostet,项目名称:cassandra-kmean,代码行数:20,代码来源:FBUtilities.java

示例14: deserialize

import org.apache.thrift.TBase; //导入依赖的package包/类
@Deprecated
public static void deserialize(TDeserializer deserializer, TBase struct, DataInput in)
throws IOException
{
    assert deserializer != null;
    assert struct != null;
    assert in != null;
    byte[] bytes = new byte[in.readInt()];
    in.readFully(bytes);
    try
    {
        deserializer.deserialize(struct, bytes);
    }
    catch (TException ex)
    {
        throw new IOException(ex);
    }
}
 
开发者ID:vcostet,项目名称:cassandra-kmean,代码行数:19,代码来源:FBUtilities.java

示例15: decodeBody

import org.apache.thrift.TBase; //导入依赖的package包/类
@Override
public @Nullable <T> T decodeBody(@NotNull ByteBuf arg3, @NotNull Class<T> bodyType) {

    try {
        // Create a new instance of type 'T'
        T base = bodyType.newInstance();

        // Get byte[] from ByteBuf
        byte[] payloadBytes = new byte[arg3.readableBytes()];
        arg3.readBytes(payloadBytes);

        // Actually deserialize the payload
        TDeserializer deserializer = new TDeserializer(new TBinaryProtocol.Factory());
        deserializer.deserialize((TBase<?, ?>) base, payloadBytes);

        return base;
    } catch (InstantiationException | IllegalAccessException | TException e) {
        logger.error("Failed to decode body to {}", bodyType.getName(), e);
    }

    return null;

}
 
开发者ID:uber,项目名称:tchannel-java,代码行数:24,代码来源:ThriftSerializer.java


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