當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。