use of org.apache.thrift.protocol.TProtocol in project logprocessing by cloudian.
the class CassandraClient method open.
public void open() throws IOException {
try {
this.currentServer = this.serverSet.get();
} catch (ServerSet.NoServersAvailableException e) {
throw new IOException("No Cassandra servers available.");
}
int splitIndex = this.currentServer.indexOf(':');
if (splitIndex == -1) {
throw new IOException("Bad host:port pair: " + this.currentServer);
}
String host = this.currentServer.substring(0, splitIndex);
int port = Integer.parseInt(this.currentServer.substring(splitIndex + 1));
TSocket sock = new TSocket(host, port);
this.transport = new TFramedTransport(sock);
TProtocol protocol = new TBinaryProtocol(transport);
this.client = new Cassandra.Client(protocol);
try {
this.transport.open();
this.client.set_keyspace(this.keyspace);
} catch (TException texc) {
throw new IOException(texc.getMessage());
} catch (InvalidRequestException exc) {
throw new IOException(exc.getMessage());
}
}
use of org.apache.thrift.protocol.TProtocol in project commons by twitter.
the class PingPongClient method run.
@Override
public void run() {
TTransport transport = new TSocket("localhost", THRIFT_PORT.get());
try {
transport.open();
} catch (TTransportException e) {
throw new RuntimeException(e);
}
TProtocol protocol = new TBinaryProtocol(transport);
PingPong.Client client = new PingPong.Client(protocol);
try {
LOG.info("Pinging...");
LOG.info(client.ping());
} catch (TException e) {
throw new RuntimeException(e);
}
}
use of org.apache.thrift.protocol.TProtocol 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.protocol.TProtocol 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.protocol.TProtocol in project pinpoint by naver.
the class TBaseProcessorProcessInterceptor method processTraceObject.
private void processTraceObject(final Trace trace, Object target, Object[] args, Throwable throwable) {
// end spanEvent
try {
SpanEventRecorder recorder = trace.currentSpanEventRecorder();
// TODO Might need a way to collect and record method arguments
// trace.recordAttribute(...);
recorder.recordException(throwable);
recorder.recordApi(this.descriptor);
} catch (Throwable t) {
logger.warn("Error processing trace object. Cause:{}", t.getMessage(), t);
} finally {
trace.traceBlockEnd();
}
// end root span
SpanRecorder recorder = trace.getSpanRecorder();
String methodUri = getMethodUri(target);
recorder.recordRpcName(methodUri);
// retrieve connection information
String localIpPort = ThriftConstants.UNKNOWN_ADDRESS;
String remoteAddress = ThriftConstants.UNKNOWN_ADDRESS;
if (args.length == 2 && args[0] instanceof TProtocol) {
TProtocol inputProtocol = (TProtocol) args[0];
TTransport inputTransport = inputProtocol.getTransport();
if (inputTransport instanceof SocketFieldAccessor) {
Socket socket = ((SocketFieldAccessor) inputTransport)._$PINPOINT$_getSocket();
if (socket != null) {
localIpPort = ThriftUtils.getHostPort(socket.getLocalSocketAddress());
remoteAddress = ThriftUtils.getHost(socket.getRemoteSocketAddress());
}
} else {
if (isDebug) {
logger.debug("Invalid target object. Need field accessor({}).", SocketFieldAccessor.class.getName());
}
}
}
if (localIpPort != ThriftConstants.UNKNOWN_ADDRESS) {
recorder.recordEndPoint(localIpPort);
}
if (remoteAddress != ThriftConstants.UNKNOWN_ADDRESS) {
recorder.recordRemoteAddress(remoteAddress);
}
}
Aggregations