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


Java TSerializer类代码示例

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


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

示例1: benchSetup

import org.apache.thrift.TSerializer; //导入依赖的package包/类
@Setup(Level.Trial)
public void benchSetup(BenchmarkParams params) throws TException {
    testObject = new ThriftTestObject();
    testObject.addToField1(createElement("1"));
    testObject.addToField1(createElement("2"));
    testObject.addToField1(createElement("3"));
    testObject.addToField1(createElement("4"));

    testObject.addToField1(createElement("1"));
    testObject.addToField1(createElement("2"));
    testObject.addToField1(createElement("3"));
    testObject.addToField1(createElement("4"));

    testObject.addToField1(createElement("1"));
    testObject.addToField1(createElement("2"));
    testObject.addToField1(createElement("3"));
    testObject.addToField1(createElement("4"));

    testObject.addToField1(createElement("1"));
    testObject.addToField1(createElement("2"));
    testObject.addToField1(createElement("3"));
    testObject.addToField1(createElement("4"));
    serializer = new TSerializer(new TCompactProtocol.Factory());
    deserializer = new TDeserializer(new TCompactProtocol.Factory());
    testData = serializer.serialize(testObject);
}
 
开发者ID:json-iterator,项目名称:java-benchmark,代码行数:27,代码来源:DeserThrift.java

示例2: benchSetup

import org.apache.thrift.TSerializer; //导入依赖的package包/类
@Setup(Level.Trial)
public void benchSetup(BenchmarkParams params) throws TException {
    ThriftTestWriteObject testObject = new ThriftTestWriteObject();
    testObject.setField1(Arrays.asList("1", "2", "3", "4", "5",
            "1", "2", "3", "4", "5",
            "1", "2", "3", "4", "5"));
    HashMap<String, List<String>> field2 = new HashMap<>();
    field2.put("1", Arrays.asList("1", "2", "3", "4", "5"));
    field2.put("2", Arrays.asList("1", "2", "3", "4", "5"));
    field2.put("3", Arrays.asList("1", "2", "3", "4", "5"));
    testObject.setField2(field2);
    testObject.setField3("x-3");
    serializer = new TSerializer(new TCompactProtocol.Factory());
    deserializer = new TDeserializer(new TCompactProtocol.Factory());
    testData = serializer.serialize(testObject);
}
 
开发者ID:json-iterator,项目名称:java-benchmark,代码行数:17,代码来源:DeserThrift.java

示例3: benchSetup

import org.apache.thrift.TSerializer; //导入依赖的package包/类
@Setup(Level.Trial)
public void benchSetup(BenchmarkParams params) throws TException {
    testObject = new ThriftTestObject();
    testObject.addToField1(31.415926);
    testObject.addToField1(61.415923);
    testObject.addToField1(31.415269);
    testObject.addToField1(53.141926);
    testObject.addToField1(13.145926);
    testObject.addToField1(43.115926);
    testObject.addToField1(31.419265);
    testObject.addToField1(23.141596);
    testObject.addToField1(43.161592);
    testObject.addToField1(0.112);
    serializer = new TSerializer(new TCompactProtocol.Factory());
    deserializer = new TDeserializer(new TCompactProtocol.Factory());
    testData = serializer.serialize(testObject);
}
 
开发者ID:json-iterator,项目名称:java-benchmark,代码行数:18,代码来源:DeserThrift.java

示例4: benchSetup

import org.apache.thrift.TSerializer; //导入依赖的package包/类
@Setup(Level.Trial)
public void benchSetup(BenchmarkParams params) throws TException {
    testObject = new ThriftTestObject();
    testObject.setField1(31415926);
    testObject.setField2(61415923);
    testObject.setField3(31415269);
    testObject.setField4(53141926);
    testObject.setField5(13145926);
    testObject.setField6(43115926);
    testObject.setField7(31419265);
    testObject.setField8(23141596);
    testObject.setField9(43161592);
    testObject.setField10(112);
    serializer = new TSerializer(new TCompactProtocol.Factory());
    deserializer = new TDeserializer(new TCompactProtocol.Factory());
    testData = serializer.serialize(testObject);
}
 
开发者ID:json-iterator,项目名称:java-benchmark,代码行数:18,代码来源:DeserThrift.java

示例5: amcast

import org.apache.thrift.TSerializer; //导入依赖的package包/类
/**
 * Atomically multicast command.
 * 
 * @param command
 * @return A FutureDecision that can be waited on
 */
public void amcast(Command command) throws FSError {
	// right now, it either sends to the given partition or to the global
	// ring
	byte ringid = GLOBAL_RING;
	if (command.getInvolvedPartitions().size() == 1) {
		ringid = command.getInvolvedPartitions().iterator().next().byteValue();
	}
	// TODO: right now its not possible to submit to rings the replica is
	// not part of. Make the replica act as a proxy to one of the responsible replicas?
	log.debug(new StrBuilder().append("Submitting command to ring ").append(ringid).toString());
	Proposer p = this.proposers.get(Byte.valueOf(ringid));
	// TSerializer is not threadsafe, create a new one for each amcast. Is
	// this too expensive?
	final TSerializer serializer = new TSerializer();
	try {
		p.propose(serializer.serialize(command));
	} catch (TException e) {
		e.printStackTrace();
		throw new FSError(Errno.EREMOTEIO, "Error serializing message");
	}
}
 
开发者ID:pacheco,项目名称:GlobalFS,代码行数:28,代码来源:CommunicationService.java

示例6: gtsOp

import org.apache.thrift.TSerializer; //导入依赖的package包/类
@Override
protected Object gtsOp(Map<String, Object> params, GeoTimeSerie gts) throws WarpScriptException {

  GTSWrapper wrapper;
  
  if (opt) {
    wrapper = GTSWrapperHelper.fromGTSToGTSWrapper(gts, true, 1.0, true);
  } else {
    wrapper = GTSWrapperHelper.fromGTSToGTSWrapper(gts, true);
  }
  
  TSerializer serializer = new TSerializer(new TCompactProtocol.Factory());
  
  try {
    byte[] bytes = serializer.serialize(wrapper);
    
    return bytes;
  } catch (TException te) {
    throw new WarpScriptException(getName() + " failed to wrap GTS.");
  }        
}
 
开发者ID:cityzendata,项目名称:warp10-platform,代码行数:22,代码来源:WRAPRAW.java

示例7: gtsOp

import org.apache.thrift.TSerializer; //导入依赖的package包/类
@Override
protected Object gtsOp(Map<String, Object> params, GeoTimeSerie gts) throws WarpScriptException {

  GTSWrapper wrapper;
  
  if (opt) {
    wrapper = GTSWrapperHelper.fromGTSToGTSWrapper(gts, this.compress, 1.0, true);
  } else {
    wrapper = GTSWrapperHelper.fromGTSToGTSWrapper(gts, this.compress);
  }
  
  TSerializer serializer = new TSerializer(new TCompactProtocol.Factory());
  
  try {
    byte[] bytes = serializer.serialize(wrapper);
    
    return new String(OrderPreservingBase64.encode(bytes), Charsets.US_ASCII);
  } catch (TException te) {
    throw new WarpScriptException(getName() + " failed to wrap GTS.");
  }        
}
 
开发者ID:cityzendata,项目名称:warp10-platform,代码行数:22,代码来源:WRAP.java

示例8: pack

import org.apache.thrift.TSerializer; //导入依赖的package包/类
public static String pack(GeoXPShape shape) throws WarpScriptException {
  long[] cells = GeoXPLib.getCells(shape);
  
  GTSEncoder encoder = new GTSEncoder();
  
  try {
    for (long cell: cells) {
      encoder.addValue(cell, GeoTimeSerie.NO_LOCATION, GeoTimeSerie.NO_ELEVATION, true);
    }      
  } catch (IOException ioe) {
    throw new WarpScriptException(ioe);
  }
  
  GTSWrapper wrapper = GTSWrapperHelper.fromGTSEncoderToGTSWrapper(encoder, true);
  
  TSerializer serializer = new TSerializer(new TCompactProtocol.Factory());
  
  try {
    byte[] serialized = serializer.serialize(wrapper);
    
    return new String(OrderPreservingBase64.encode(serialized, 0, serialized.length), Charsets.US_ASCII);      
  } catch (TException te) {
    throw new WarpScriptException(te);
  }
}
 
开发者ID:cityzendata,项目名称:warp10-platform,代码行数:26,代码来源:GEOPACK.java

示例9: pushMetadataMessage

import org.apache.thrift.TSerializer; //导入依赖的package包/类
void pushMetadataMessage(Metadata metadata) throws IOException {
  
  if (null == metadata) {
    pushMetadataMessage(null, null);
    return;
  }
  
  //
  // Compute class/labels Id
  //
  
  metadata.setClassId(GTSHelper.classId(this.classKey, metadata.getName()));
  metadata.setLabelsId(GTSHelper.labelsId(this.labelsKey, metadata.getLabels()));
  
  TSerializer serializer = new TSerializer(new TCompactProtocol.Factory());
  try {
    byte[] bytes = new byte[16];
    GTSHelper.fillGTSIds(bytes, 0, metadata.getClassId(), metadata.getLabelsId());
    pushMetadataMessage(bytes, serializer.serialize(metadata));
  } catch (TException te) {
    throw new IOException("Unable to push metadata.");
  }
}
 
开发者ID:cityzendata,项目名称:warp10-platform,代码行数:24,代码来源:Ingress.java

示例10: serializeLoggingEvent

import org.apache.thrift.TSerializer; //导入依赖的package包/类
public static final String serializeLoggingEvent(KeyStore keystore, LoggingEvent event) {
  if (null == event) {
    return null;
  }
  
  TSerializer serializer = new TSerializer(new TCompactProtocol.Factory());
  
  byte[] serialized = null;
  
  try {
    serialized = serializer.serialize(event);
  } catch (TException te) {
    return null;
  }
  
  if (!checkedAESKey) {
    checkedAESKey = true;
    loggingAESKey = keystore.getKey(KeyStore.AES_LOGGING);      
  }
  if (null != loggingAESKey) {
    serialized = CryptoUtils.wrap(loggingAESKey, serialized);
  }
  
  return new String(OrderPreservingBase64.encode(serialized), Charsets.US_ASCII); 
}
 
开发者ID:cityzendata,项目名称:warp10-platform,代码行数:26,代码来源:LogUtil.java

示例11: buildTransportRequest

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

import org.apache.thrift.TSerializer; //导入依赖的package包/类
@Test
public void testHandleUnary() throws Exception {
  KeyValue.getValue_args reqData = new KeyValue.getValue_args("foo");
  TSerializer serializer = new TSerializer(ThriftEncoding.defaultProtocolFactory());
  when(req.getBody()).thenReturn(TransportBody.fromByteArray(serializer.serialize(reqData)));
  when(dataHandler.handleUnary(any(), argThat(data -> "foo".equals(data.getKey()))))
      .thenReturn(
          CompletableFuture.completedFuture(
              DefaultReply.<KeyValue.getValue_result>builder()
                  .body(new KeyValue.getValue_result("result", null))
                  .build()));
  UnaryThriftTransportHandler<KeyValue.getValue_args, KeyValue.getValue_result> transportHandler =
      new UnaryThriftTransportHandler<>(dataHandler, KeyValue.getValue_args.class);
  TransportResponse res = transportHandler.handleUnary(req).blockingGet();

  TDeserializer deserializer = new TDeserializer(ThriftEncoding.defaultProtocolFactory());
  KeyValue.getValue_result resData = KeyValue.getValue_result.class.newInstance();
  deserializer.deserialize(resData, res.getBody().blockingSingle().array());

  assertEquals("result", resData.getSuccess());
  assertNull(resData.getNotFound());
}
 
开发者ID:yarpc,项目名称:yarpc-java,代码行数:23,代码来源:UnaryThriftTransportHandlerTest.java

示例13: serialize

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

import org.apache.thrift.TSerializer; //导入依赖的package包/类
public Connection getEzPostgresConnection(EzSecurityToken token) throws SQLException, TException {
    String appName = ezProperties.getProperty(EzBakePropertyConstants.EZBAKE_APPLICATION_NAME);
    Properties dbProperties = new Properties();
    dbProperties.putAll(ezProperties);
    dbProperties.put("user", ezProperties.getProperty(EzBakePropertyConstants.POSTGRES_USERNAME, appName));
    dbProperties.put("password", ezProperties.getProperty(EzBakePropertyConstants.POSTGRES_PASSWORD, appName));
    if (useSSL()) {
        dbProperties.put("ssl", "true");
        dbProperties.put("sslfactory", "org.postgresql.ssl.NonValidatingFactory");
    }

    if (token != null) {
        dbProperties.put("ezbakeTokenProvider", "ezbake.data.postgres.ExplicitTokenProvider");
        dbProperties.put("ezbakeToken", new String(Base64.encodeBase64(new TSerializer().serialize(token)),
                Charsets.US_ASCII));
    }

    return DriverManager.getConnection(String.format("jdbc:ezbake:postgresql://%s:%s/%s",
                    ezProperties.getProperty(EzBakePropertyConstants.POSTGRES_HOST, "localhost"),
                    ezProperties.getProperty(EzBakePropertyConstants.POSTGRES_PORT, "5432"),
                    ezProperties.getProperty(EzBakePropertyConstants.POSTGRES_DB, appName)),
            dbProperties);
}
 
开发者ID:ezbake,项目名称:ezbake-common-java,代码行数:24,代码来源:PostgresConfigurationHelper.java

示例15: convert

import org.apache.thrift.TSerializer; //导入依赖的package包/类
@Override
public SSRJSON convert(TweetWithRaw tweetAndRaw) throws TException {
    Tweet tweet = tweetAndRaw.getTweet();
    SSRJSON ssrJson = new SSRJSON();
    SSR ssr = new SSR();
    ssr.setUri(uriPrefix + tweet.getId());
    ssr.setTitle(String.valueOf(tweet.getId()));
    ssr.setVisibility(new Visibility().setFormalVisibility("U"));
    ssr.setSnippet(tweet.getText());
    if (tweet.getGeoLocation() != null) {
        Coordinate coordinate = new Coordinate();
        coordinate.setLatitude(tweet.getGeoLocation().getLatitude());
        coordinate.setLongitude(tweet.getGeoLocation().getLongitude());
    }
    ssr.setResultDate(TimeUtil.convertToThriftDateTime(tweet.getTimestamp()));
    ssrJson.setSsr(ssr);
    ssrJson.setJsonString(new TSerializer(new TSimpleJSONProtocol.Factory()).toString(tweet));
    return ssrJson;
}
 
开发者ID:ezbake,项目名称:ezbake-training,代码行数:20,代码来源:SSRConverter.java


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