List of usage examples for org.apache.thrift.protocol TCompactProtocol TCompactProtocol
public TCompactProtocol(TTransport transport)
From source file:com.uber.jaeger.senders.UDPSender.java
License:Open Source License
public UDPSender(String host, int port, int maxPacketSize) { if (host == null || host.length() == 0) { host = defaultUDPSpanServerHost; }// ww w. ja v a2 s . c om if (port == 0) { port = defaultUDPSpanServerPort; } if (maxPacketSize == 0) { maxPacketSize = defaultUDPPacketSize; } memoryTransport = new AutoExpandingBufferWriteTransport(maxPacketSize, 2); udpTransport = TUDPTransport.NewTUDPClient(host, port); udpClient = new Agent.Client(new TCompactProtocol(udpTransport)); maxSpanBytes = maxPacketSize - emitZipkinBatchOverhead; spanBuffer = new ArrayList<>(); }
From source file:com.uber.jaeger.senders.UDPSender.java
License:Open Source License
int getSizeOfSerializedSpan(Span span) throws SenderException { memoryTransport.reset();/*ww w .ja va 2 s. co m*/ try { span.write(new TCompactProtocol(memoryTransport)); } catch (TException e) { throw new SenderException("UDPSender failed writing to memory buffer.", e, 1); } return memoryTransport.getPos(); }
From source file:com.uber.jaeger.senders.UDPSenderTest.java
License:Open Source License
@Test public void testAppend() throws Exception { // find size of the initial span AutoExpandingBufferWriteTransport memoryTransport = new AutoExpandingBufferWriteTransport(maxPacketSize, 2); com.twitter.zipkin.thriftjava.Span span = ThriftSpanConverter .convertSpan((Span) tracer.buildSpan("raza").start()); 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.emitZipkinBatchOverhead; sender = new UDPSender(destHost, destPort, maxPacketSize); int maxPacketSizeLeft = maxPacketSize - sender.emitZipkinBatchOverhead; // add enough spans to be under buffer limit while (spanSize < maxPacketSizeLeft) { sender.append(span);/*from w w w . jav a 2 s. c om*/ maxPacketSizeLeft -= spanSize; } // add a span that overflows the limit to hit the last branch int result = sender.append(span); assertEquals(expectedNumSpans, result); }
From source file:com.uber.jaeger.senders.UDPSenderTest.java
License:Open Source License
private int calculateZipkinBatchOverheadDifference(int numberOfSpans) throws Exception { AutoExpandingBufferWriteTransport memoryTransport = new AutoExpandingBufferWriteTransport(maxPacketSize, 2); Agent.Client memoryClient = new Agent.Client(new TCompactProtocol(memoryTransport)); Span jaegerSpan = (Span) tracer.buildSpan("raza").start(); com.twitter.zipkin.thriftjava.Span span = ThriftSpanConverter.convertSpan(jaegerSpan); List<com.twitter.zipkin.thriftjava.Span> spans = new ArrayList<>(); for (int i = 0; i < numberOfSpans; i++) { spans.add(span);//from w w w . j ava2s . c om } memoryClient.emitZipkinBatch(spans); int emitZipkinBatchOverheadMultipleSpans = memoryTransport.getPos(); memoryTransport.reset(); for (int j = 0; j < numberOfSpans; j++) { span.write(new TCompactProtocol(memoryTransport)); } int writeZipkinBatchOverheadMultipleSpans = memoryTransport.getPos(); return emitZipkinBatchOverheadMultipleSpans - writeZipkinBatchOverheadMultipleSpans; }
From source file:com.vmware.photon.controller.housekeeper.helpers.TestHelper.java
License:Open Source License
public static Housekeeper.Client createLocalThriftClient(TestInjectedConfig config) throws TTransportException, InterruptedException, TimeoutException { long timeLeft = CONNECTION_TIMEOUT_IN_MS; TSocket socket = new TSocket(config.getThriftBindAddress(), config.getThriftPort()); while (true) { if (timeLeft <= 0) { throw new TimeoutException(); }//from w w w. jav a 2s . c o m timeLeft -= CONNECTION_RETRY_INTERVAL_IN_MS; try { socket.open(); } catch (TTransportException e) { Thread.sleep(CONNECTION_RETRY_INTERVAL_IN_MS); continue; } break; } return new Housekeeper.Client(new TMultiplexedProtocol( new TCompactProtocol(new TFastFramedTransport(socket)), HousekeeperServer.SERVICE_NAME)); }
From source file:com.vmware.transfer.nfc.ImageUploadTool.java
License:Open Source License
private void init() throws TTransportException { TTransport transport = new TFastFramedTransport(new TSocket(hostAddress, hostPort)); transport.open();//from ww w . j a v a 2s .co m TProtocol proto = new TCompactProtocol(transport); TMultiplexedProtocol mproto = new TMultiplexedProtocol(proto, "Host"); hostClient = new Host.Client(mproto); }
From source file:edu.jhu.hlt.concrete.streams.NamedPipeCommunicationConsumer.java
License:Open Source License
/** * @param pathStr a path to a named pipe with {@link Communication}s * @throws IOException/* w w w.j a va2 s. c o m*/ */ public NamedPipeCommunicationConsumer(final String pathStr) throws IOException { try { this.tft = new TSimpleFileTransport(pathStr); this.tft.open(); this.tcp = new TCompactProtocol(tft); } catch (TTransportException e) { throw new IOException(e); } }
From source file:edu.jhuapl.accumulo.proxy.ProxyInstance.java
License:Apache License
/** * //ww w . ja v a 2 s. c o m * @param transport * Thrift transport to communicate with Proxy Server * @param fetchSize * the fetch size for BatchScanners. Must be 0 < fetchSize <= 2000. If fetchSize is outside of this range, a warning will be logged and the * {@link #DEFAULT_FETCH_SIZE} will be used. * @throws TTransportException * thrown if the Thrift TTransport cannot be established. */ public ProxyInstance(TTransport transport, int fetchSize) throws TTransportException { if (!transport.isOpen()) { transport.open(); } TProtocol protocol = new TCompactProtocol(transport); client = new SynchronizedProxy(new AccumuloProxy.Client(protocol)); this.transport = transport; if (fetchSize <= 0 || fetchSize > 2000) { LoggerFactory.getLogger(ProxyInstance.class).warn("Fetch size out of range (0 < fetchSize <= 2000): " + fetchSize + "; using default: " + DEFAULT_FETCH_SIZE); this.fetchSize = DEFAULT_FETCH_SIZE; } else { this.fetchSize = fetchSize; } }
From source file:ezbake.thrift.ThriftUtils.java
License:Apache License
protected static TProtocol getProtocol(HostAndPort hostAndPort, String securityId, Properties properties, TTransportFactory transportFactory) throws Exception { logger.debug("getProtocol for host:port {} and security id {}", hostAndPort, securityId); TProtocol protocol;//from w w w .ja va 2 s . co m ThriftConfigurationHelper thriftConfiguration = new ThriftConfigurationHelper(properties); logger.debug("about to getTransport for host:port {} and security id {}", hostAndPort, securityId); TTransport transport = getTransport(properties, hostAndPort, securityId, transportFactory); // HsHa is using framed transport with Compact protocol, but others are using binary (for now at least) if (thriftConfiguration.getServerMode() == ThriftConfigurationHelper.ThriftServerMode.HsHa) { protocol = new TCompactProtocol(transport); } else { protocol = new TBinaryProtocol(transport); } if (!transport.isOpen()) { transport.open(); } return protocol; }
From source file:gridool.marshaller.ThriftMarshaller.java
License:Apache License
public <T extends TBase> void marshall(final T obj, final OutputStream out) throws GridException { TIOStreamTransport trans = new TIOStreamTransport(out); final TCompactProtocol prot = new TCompactProtocol(trans); try {//from ww w . j a va 2s . com obj.write(prot); } catch (TException e) { throw new GridException(e); } }