use of org.apache.thrift.transport.TIOStreamTransport in project distributedlog by twitter.
the class StreamTransformer method transform.
private static void transform(final AsyncLogWriter writer, LogRecordWithDLSN record, Transformer<byte[], byte[]> replicationTransformer, final CountDownLatch keepAliveLatch) throws Exception {
DLSN srcDLSN = record.getDlsn();
byte[] payload = record.getPayload();
byte[] transformedPayload = replicationTransformer.transform(payload);
TransformedRecord transformedRecord = new TransformedRecord(ByteBuffer.wrap(transformedPayload));
transformedRecord.setSrcDlsn(srcDLSN.serializeBytes());
ByteArrayOutputStream baos = new ByteArrayOutputStream(4096);
transformedRecord.write(protocolFactory.getProtocol(new TIOStreamTransport(baos)));
byte[] data = baos.toByteArray();
writer.write(new LogRecord(record.getSequenceId(), data)).addEventListener(new FutureEventListener<DLSN>() {
@Override
public void onFailure(Throwable cause) {
System.err.println("Encountered error on writing records to stream " + writer.getStreamName());
cause.printStackTrace(System.err);
keepAliveLatch.countDown();
}
@Override
public void onSuccess(DLSN dlsn) {
System.out.println("Write transformed record " + dlsn);
}
});
}
use of org.apache.thrift.transport.TIOStreamTransport in project pinpoint by naver.
the class AnnotationTranscoderTest method write.
private void write(int value) throws TException {
TCompactProtocol.Factory factory = new TCompactProtocol.Factory();
ByteArrayOutputStream baos = new ByteArrayOutputStream(16);
TIOStreamTransport transport = new TIOStreamTransport(baos);
TProtocol protocol = factory.getProtocol(transport);
protocol.writeI32(value);
byte[] buffer = baos.toByteArray();
logger.debug(Arrays.toString(buffer));
}
use of org.apache.thrift.transport.TIOStreamTransport in project pinpoint by naver.
the class ByteSizeTest method test.
@Test
public void test() throws TException {
TCompactProtocol.Factory factory = new TCompactProtocol.Factory();
ByteArrayOutputStream baos = new ByteArrayOutputStream(16);
TIOStreamTransport transport = new TIOStreamTransport(baos);
TProtocol protocol = factory.getProtocol(transport);
long l = TimeUnit.DAYS.toMillis(1);
logger.debug("day:{}", l);
long currentTime = System.currentTimeMillis();
logger.debug("currentTime:{}" + currentTime);
protocol.writeI64(l);
byte[] buffer = baos.toByteArray();
logger.debug("{}", buffer.length);
}
use of org.apache.thrift.transport.TIOStreamTransport in project jena by apache.
the class ThriftConverter method getOutputTransport.
private static TTransport getOutputTransport() {
TTransport transport = outputTransports.get();
if (transport != null)
return transport;
transport = new TIOStreamTransport(getOutputStream());
outputTransports.set(transport);
return transport;
}
use of org.apache.thrift.transport.TIOStreamTransport in project jena by apache.
the class TRDF method protocol.
/**
* Create Thrift protocol for the OutputStream.
* The caller must call {@link TRDF#flush(TProtocol)}
* which will flush the underlying (internally buffered) output stream.
* @param out OutputStream
*/
public static TProtocol protocol(OutputStream out) {
try {
// Flushing the protocol will flush the BufferedOutputStream
if (!(out instanceof BufferedOutputStream))
out = new BufferedOutputStream(out, OutputBufferSize);
TTransport transport = new TIOStreamTransport(out);
transport.open();
TProtocol protocol = protocol(transport);
return protocol;
} catch (TException ex) {
TRDF.exception(ex);
return null;
}
}
Aggregations