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