Search in sources :

Example 1 with TCompactProtocol

use of org.apache.thrift.protocol.TCompactProtocol in project jaeger-client-java by jaegertracing.

the class UdpSenderTest method testAppend.

@Test
public void testAppend() throws Exception {
    // find size of the initial span
    Span jaegerSpan = (Span) tracer.buildSpan("raza").startManual();
    com.uber.jaeger.thriftjava.Span span = JaegerThriftSpanConverter.convertSpan(jaegerSpan);
    Process process = new Process(tracer.getServiceName()).setTags(JaegerThriftSpanConverter.buildTags(tracer.tags()));
    AutoExpandingBufferWriteTransport memoryTransport = new AutoExpandingBufferWriteTransport(maxPacketSize, 2);
    process.write(new TCompactProtocol(memoryTransport));
    int processSize = memoryTransport.getPos();
    memoryTransport.reset();
    span.write(new TCompactProtocol((memoryTransport)));
    int spanSize = memoryTransport.getPos();
    // create a sender thats a multiple of the span size (accounting for span overhead)
    // this allows us to test the boundary conditions of writing spans.
    int expectedNumSpans = 11;
    int maxPacketSize = (spanSize * expectedNumSpans) + sender.EMIT_BATCH_OVERHEAD + processSize;
    int maxPacketSizeLeft = maxPacketSize - sender.EMIT_BATCH_OVERHEAD - processSize;
    // add enough spans to be under buffer limit
    sender = new UdpSender(destHost, destPort, maxPacketSize);
    while (spanSize < maxPacketSizeLeft) {
        sender.append(jaegerSpan);
        maxPacketSizeLeft -= spanSize;
    }
    // add a span that overflows the limit to hit the last branch
    int result = sender.append(jaegerSpan);
    assertEquals(expectedNumSpans, result);
}
Also used : AutoExpandingBufferWriteTransport(org.apache.thrift.transport.AutoExpandingBufferWriteTransport) Process(com.uber.jaeger.thriftjava.Process) TCompactProtocol(org.apache.thrift.protocol.TCompactProtocol) Span(com.uber.jaeger.Span) Test(org.junit.Test)

Example 2 with TCompactProtocol

use of org.apache.thrift.protocol.TCompactProtocol in project carbondata by apache.

the class CarbonUtil method getByteArray.

/**
 * Below method will be used to convert the thrift object to byte array.
 */
public static byte[] getByteArray(TBase t) {
    ByteArrayOutputStream stream = new ByteArrayOutputStream();
    byte[] thriftByteArray = null;
    TProtocol binaryOut = new TCompactProtocol(new TIOStreamTransport(stream));
    try {
        t.write(binaryOut);
        stream.flush();
        thriftByteArray = stream.toByteArray();
    } catch (TException | IOException e) {
        LOGGER.error("Error while converting to byte array from thrift object: " + e.getMessage());
        closeStreams(stream);
    } finally {
        closeStreams(stream);
    }
    return thriftByteArray;
}
Also used : TException(org.apache.thrift.TException) TProtocol(org.apache.thrift.protocol.TProtocol) TIOStreamTransport(org.apache.thrift.transport.TIOStreamTransport) TCompactProtocol(org.apache.thrift.protocol.TCompactProtocol)

Example 3 with TCompactProtocol

use of org.apache.thrift.protocol.TCompactProtocol in project carbondata by apache.

the class CarbonUtil method readDataChunk3.

public static DataChunk3 readDataChunk3(InputStream stream) throws IOException {
    TBaseCreator creator = new ThriftReader.TBaseCreator() {

        @Override
        public TBase create() {
            return new DataChunk3();
        }
    };
    TProtocol binaryIn = new TCompactProtocol(new TIOStreamTransport(stream));
    TBase t = creator.create();
    try {
        t.read(binaryIn);
    } catch (TException e) {
        throw new IOException(e);
    }
    return (DataChunk3) t;
}
Also used : TException(org.apache.thrift.TException) TProtocol(org.apache.thrift.protocol.TProtocol) TBaseCreator(org.apache.carbondata.core.reader.ThriftReader.TBaseCreator) DataChunk3(org.apache.carbondata.format.DataChunk3) TIOStreamTransport(org.apache.thrift.transport.TIOStreamTransport) TBase(org.apache.thrift.TBase) TCompactProtocol(org.apache.thrift.protocol.TCompactProtocol)

Example 4 with TCompactProtocol

use of org.apache.thrift.protocol.TCompactProtocol in project carbondata by apache.

the class ThriftWriter method open.

/**
 * Open the file for writing.
 */
public void open() throws IOException {
    FileFactory.FileType fileType = FileFactory.getFileType(fileName);
    dataOutputStream = FileFactory.getDataOutputStream(fileName, fileType, bufferSize, append);
    binaryOut = new TCompactProtocol(new TIOStreamTransport(dataOutputStream));
}
Also used : TIOStreamTransport(org.apache.thrift.transport.TIOStreamTransport) TCompactProtocol(org.apache.thrift.protocol.TCompactProtocol) FileFactory(org.apache.carbondata.core.datastore.impl.FileFactory)

Example 5 with TCompactProtocol

use of org.apache.thrift.protocol.TCompactProtocol in project carbondata by apache.

the class ThriftWriter method open.

/**
 * Method for opening file writing for atomic operations
 *
 * @param fileWriteOperation
 * @throws IOException
 */
public void open(FileWriteOperation fileWriteOperation) throws IOException {
    FileFactory.FileType fileType = FileFactory.getFileType(fileName);
    atomicFileOperationsWriter = new AtomicFileOperationsImpl(fileName, fileType);
    dataOutputStream = atomicFileOperationsWriter.openForWrite(fileWriteOperation);
    binaryOut = new TCompactProtocol(new TIOStreamTransport(dataOutputStream));
}
Also used : TIOStreamTransport(org.apache.thrift.transport.TIOStreamTransport) TCompactProtocol(org.apache.thrift.protocol.TCompactProtocol) AtomicFileOperationsImpl(org.apache.carbondata.core.fileoperations.AtomicFileOperationsImpl) FileFactory(org.apache.carbondata.core.datastore.impl.FileFactory)

Aggregations

TCompactProtocol (org.apache.thrift.protocol.TCompactProtocol)54 TProtocol (org.apache.thrift.protocol.TProtocol)38 THttpClient (org.apache.thrift.transport.THttpClient)18 TSocket (org.apache.thrift.transport.TSocket)18 TException (org.apache.thrift.TException)15 TTransport (org.apache.thrift.transport.TTransport)11 TFramedTransport (org.apache.thrift.transport.TFramedTransport)9 IOException (java.io.IOException)8 UserGroupInformation (org.apache.hadoop.security.UserGroupInformation)7 TBinaryProtocol (org.apache.thrift.protocol.TBinaryProtocol)7 TIOStreamTransport (org.apache.thrift.transport.TIOStreamTransport)7 TTransportException (org.apache.thrift.transport.TTransportException)5 TFramedTransport (org.apache.thrift.transport.layered.TFramedTransport)5 Test (org.junit.Test)5 LoginException (javax.security.auth.login.LoginException)4 Hello (org.tech.model.Hello)4 URI (java.net.URI)3 ArrayList (java.util.ArrayList)3 UGIAssumingTransport (org.apache.accumulo.core.rpc.UGIAssumingTransport)3 AccumuloProxy (org.apache.accumulo.proxy.thrift.AccumuloProxy)3