use of org.apache.thrift.transport.TTransport in project cdap by caskdata.
the class ThriftHelper method getThriftProtocol.
/**
* generic method to discover a thrift service and start up the
* thrift transport and protocol layer.
*/
public static TProtocol getThriftProtocol(String serviceName, EndpointStrategy endpointStrategy) throws ServerException {
Discoverable endpoint = endpointStrategy.pick();
if (endpoint == null) {
String message = String.format("Service '%s' is not registered in discovery service.", serviceName);
LOG.error(message);
throw new ServerException(message);
}
TTransport transport = new TFramedTransport(new TSocket(endpoint.getSocketAddress().getHostName(), endpoint.getSocketAddress().getPort()));
try {
transport.open();
} catch (TTransportException e) {
String message = String.format("Unable to connect to thrift service %s at %s. Reason: %s", serviceName, endpoint.getSocketAddress(), e.getMessage());
LOG.error(message);
throw new ServerException(message, e);
}
// now try to connect the thrift client
return new TBinaryProtocol(transport);
}
Aggregations