本文整理匯總了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);
}
示例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);
}
示例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);
}
示例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);
}
示例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");
}
}
示例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.");
}
}
示例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.");
}
}
示例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);
}
}
示例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.");
}
}
示例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);
}
示例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);
}
}
示例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());
}
示例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);
}
示例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);
}
示例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;
}