use of org.apache.thrift.protocol.TProtocol in project Honu by jboulon.
the class TServlet method doPost.
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType("application/x-thrift");
InputStream in = request.getInputStream();
OutputStream out = response.getOutputStream();
TTransport client = new TIOStreamTransport(in, out);
TProcessor processor = null;
TTransport inputTransport = null;
TTransport outputTransport = null;
TProtocol inputProtocol = null;
TProtocol outputProtocol = null;
try {
processor = processor_;
inputTransport = inputTransportFactory_.getTransport(client);
outputTransport = outputTransportFactory_.getTransport(client);
inputProtocol = inputProtocolFactory_.getProtocol(inputTransport);
outputProtocol = outputProtocolFactory_.getProtocol(outputTransport);
while (processor.process(inputProtocol, outputProtocol)) {
}
} catch (TTransportException ttx) {
// Client died, just move on
} catch (TException tx) {
tx.printStackTrace();
} catch (Exception x) {
x.printStackTrace();
}
if (inputTransport != null) {
inputTransport.close();
}
if (outputTransport != null) {
outputTransport.close();
}
}
use of org.apache.thrift.protocol.TProtocol in project pinpoint by naver.
the class SyncEchoTestClient method echo.
@Override
public final String echo(String message) throws TException {
TProtocol protocol = this.environment.getProtocolFactory().getProtocol(transport);
EchoService.Client client = new EchoService.Client(protocol);
return client.echo(message);
}
use of org.apache.thrift.protocol.TProtocol in project pinpoint by naver.
the class TServiceClientSendBaseInterceptor method before.
@Override
public void before(Object target, Object[] args) {
if (isDebug) {
logger.beforeInterceptor(target, args);
}
if (target instanceof TServiceClient) {
TServiceClient client = (TServiceClient) target;
TProtocol oprot = client.getOutputProtocol();
TTransport transport = oprot.getTransport();
final Trace trace = traceContext.currentRawTraceObject();
if (trace == null) {
return;
}
ThriftRequestProperty parentTraceInfo = new ThriftRequestProperty();
final boolean shouldSample = trace.canSampled();
if (!shouldSample) {
if (isDebug) {
logger.debug("set Sampling flag=false");
}
parentTraceInfo.setShouldSample(shouldSample);
} else {
SpanEventRecorder recorder = trace.traceBlockBegin();
recorder.recordServiceType(ThriftConstants.THRIFT_CLIENT);
// retrieve connection information
String remoteAddress = ThriftConstants.UNKNOWN_ADDRESS;
if (transport instanceof SocketFieldAccessor) {
Socket socket = ((SocketFieldAccessor) transport)._$PINPOINT$_getSocket();
if (socket != null) {
remoteAddress = ThriftUtils.getHostPort(socket.getRemoteSocketAddress());
}
} else {
if (isDebug) {
logger.debug("Invalid target object. Need field accessor({}).", SocketFieldAccessor.class.getName());
}
}
recorder.recordDestinationId(remoteAddress);
String methodName = ThriftConstants.UNKNOWN_METHOD_NAME;
if (args[0] instanceof String) {
methodName = (String) args[0];
}
String serviceName = ThriftUtils.getClientServiceName(client);
String thriftUrl = getServiceUrl(remoteAddress, serviceName, methodName);
recorder.recordAttribute(ThriftConstants.THRIFT_URL, thriftUrl);
TraceId nextId = trace.getTraceId().getNextTraceId();
recorder.recordNextSpanId(nextId.getSpanId());
parentTraceInfo.setTraceId(nextId.getTransactionId());
parentTraceInfo.setSpanId(nextId.getSpanId());
parentTraceInfo.setParentSpanId(nextId.getParentSpanId());
parentTraceInfo.setFlags(nextId.getFlags());
parentTraceInfo.setParentApplicationName(traceContext.getApplicationName());
parentTraceInfo.setParentApplicationType(traceContext.getServerTypeCode());
parentTraceInfo.setAcceptorHost(remoteAddress);
}
InterceptorScopeInvocation currentTransaction = this.scope.getCurrentInvocation();
currentTransaction.setAttachment(parentTraceInfo);
}
}
use of org.apache.thrift.protocol.TProtocol in project pinpoint by naver.
the class TProtocolReadMessageEndInterceptor method recordRootSpan.
private void recordRootSpan(final Trace trace, final ThriftRequestProperty parentTraceInfo, Object target) {
// begin root span
SpanRecorder recorder = trace.getSpanRecorder();
recorder.recordServiceType(ThriftConstants.THRIFT_SERVER);
recorder.recordApi(this.thriftServerEntryMethodDescriptor);
if (!trace.isRoot()) {
recordParentInfo(recorder, parentTraceInfo);
}
// record connection information here as the socket may be closed by the time the Span is popped in
// TBaseAsyncProcessorProcessInterceptor's after section.
TTransport transport = ((TProtocol) target).getTransport();
recordConnection(recorder, transport);
}
use of org.apache.thrift.protocol.TProtocol in project pinpoint by naver.
the class ChunkHeaderBufferedTBaseSerializer method write.
// write chunk header + header + body
private void write(final TBase<?, ?> base) throws TException {
final TProtocol protocol = protocolFactory.getProtocol(transport);
// write chunk header
writeChunkHeader(protocol);
// write header
writeHeader(protocol, locator.headerLookup(base));
base.write(protocol);
if (isNeedFlush()) {
flush();
}
}
Aggregations