Search in sources :

Example 26 with TIOStreamTransport

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);
        }
    });
}
Also used : TIOStreamTransport(org.apache.thrift.transport.TIOStreamTransport) TransformedRecord(com.twitter.distributedlog.thrift.messaging.TransformedRecord) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 27 with TIOStreamTransport

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));
}
Also used : TProtocol(org.apache.thrift.protocol.TProtocol) LoggerFactory(org.slf4j.LoggerFactory) TIOStreamTransport(org.apache.thrift.transport.TIOStreamTransport) ByteArrayOutputStream(java.io.ByteArrayOutputStream) TCompactProtocol(org.apache.thrift.protocol.TCompactProtocol)

Example 28 with TIOStreamTransport

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);
}
Also used : TProtocol(org.apache.thrift.protocol.TProtocol) LoggerFactory(org.slf4j.LoggerFactory) TIOStreamTransport(org.apache.thrift.transport.TIOStreamTransport) ByteArrayOutputStream(java.io.ByteArrayOutputStream) TCompactProtocol(org.apache.thrift.protocol.TCompactProtocol) Test(org.junit.Test)

Example 29 with TIOStreamTransport

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;
}
Also used : TIOStreamTransport(org.apache.thrift.transport.TIOStreamTransport) TTransport(org.apache.thrift.transport.TTransport)

Example 30 with TIOStreamTransport

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;
    }
}
Also used : TException(org.apache.thrift.TException) TProtocol(org.apache.thrift.protocol.TProtocol) TIOStreamTransport(org.apache.thrift.transport.TIOStreamTransport) TTransport(org.apache.thrift.transport.TTransport) BufferedOutputStream(java.io.BufferedOutputStream)

Aggregations

TIOStreamTransport (org.apache.thrift.transport.TIOStreamTransport)33 TException (org.apache.thrift.TException)13 TBinaryProtocol (org.apache.thrift.protocol.TBinaryProtocol)11 TProtocol (org.apache.thrift.protocol.TProtocol)10 ByteArrayOutputStream (java.io.ByteArrayOutputStream)9 Test (org.junit.Test)9 TMessage (org.apache.thrift.protocol.TMessage)8 TTransport (org.apache.thrift.transport.TTransport)8 ByteArrayInputStream (java.io.ByteArrayInputStream)7 TCompactProtocol (org.apache.thrift.protocol.TCompactProtocol)7 Request (com.alibaba.dubbo.remoting.exchange.Request)6 Demo (com.alibaba.dubbo.rpc.gen.thrift.Demo)6 IOException (java.io.IOException)6 ChannelBuffer (com.alibaba.dubbo.remoting.buffer.ChannelBuffer)5 RpcResult (com.alibaba.dubbo.rpc.RpcResult)5 RandomAccessByteArrayOutputStream (com.alibaba.dubbo.rpc.protocol.thrift.io.RandomAccessByteArrayOutputStream)5 URL (com.alibaba.dubbo.common.URL)4 Channel (com.alibaba.dubbo.remoting.Channel)4 Response (com.alibaba.dubbo.remoting.exchange.Response)4 RpcException (com.alibaba.dubbo.rpc.RpcException)3