use of org.apache.thrift.protocol.TProtocol in project alluxio by Alluxio.
the class ThriftClientPool method createNewResource.
/**
* Creates a thrift client instance.
*
* @return the thrift client created
* @throws IOException if it fails to create a thrift client
*/
@Override
protected T createNewResource() throws IOException {
TTransport transport = mTransportProvider.getClientTransport(mParentSubject, mAddress);
TProtocol binaryProtocol = new TBinaryProtocol(transport);
T client = createThriftClient(new TMultiplexedProtocol(binaryProtocol, mServiceName));
TException exception;
RetryPolicy retryPolicy = new ExponentialBackoffRetry(BASE_SLEEP_MS, MAX_SLEEP_MS, RPC_MAX_NUM_RETRY);
do {
LOG.info("Alluxio client (version {}) is trying to connect with {} {} @ {}", RuntimeConstants.VERSION, mServiceName, mAddress);
try {
if (!transport.isOpen()) {
transport.open();
}
if (transport.isOpen()) {
checkVersion(client);
}
LOG.info("Client registered with {} @ {}", mServiceName, mAddress);
return client;
} catch (TTransportException e) {
if (e.getCause() instanceof java.net.SocketTimeoutException) {
// Do not retry if socket timeout.
String message = "Thrift transport open times out. Please check whether the " + "authentication types match between client and server. Note that NOSASL client " + "is not able to connect to servers with SIMPLE security mode.";
throw new IOException(message, e);
}
LOG.warn("Failed to connect ({}) to {} @ {}: {}", retryPolicy.getRetryCount(), mServiceName, mAddress, e.getMessage());
exception = e;
}
} while (retryPolicy.attemptRetry());
LOG.error("Failed after " + retryPolicy.getRetryCount() + " retries.");
Preconditions.checkNotNull(exception);
throw new IOException(exception);
}
use of org.apache.thrift.protocol.TProtocol 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) {
closeStreams(stream);
} finally {
closeStreams(stream);
}
return thriftByteArray;
}
use of org.apache.thrift.protocol.TProtocol in project jena by apache.
the class BinRDF method inputStreamToStream.
/**
* Decode the contents of the input stream and send to the {@link StreamRDF}.
* @param in InputStream
* @param dest StreamRDF
*/
public static void inputStreamToStream(InputStream in, StreamRDF dest) {
TProtocol protocol = TRDF.protocol(in);
protocolToStream(protocol, dest);
}
use of org.apache.thrift.protocol.TProtocol in project jena by apache.
the class BinRDF method streamToFile.
/**
* Create an {@link StreamRDF} for output. A filename ending {@code .gz} will have
* a gzip compressor added to the output path. A filename of "-" is {@code System.out}.
* The file is closed when {@link StreamRDF#finish()} is called unless it is {@code System.out}.
* Call {@link StreamRDF#start()}...{@link StreamRDF#finish()}.
*
* @param filename The file
* @param withValues - whether to encode numeric values as values.
* @return StreamRDF A stream to send to.
*/
public static StreamRDF streamToFile(String filename, boolean withValues) {
OutputStream out = IO.openOutputFile(filename);
// Is this internally buffered as well?
BufferedOutputStream bout = new BufferedOutputStream(out, BUFSIZE_OUT);
TProtocol protocol = TRDF.protocol(bout);
return new StreamRDF2Thrift(protocol, withValues);
}
use of org.apache.thrift.protocol.TProtocol in project jena by apache.
the class BinRDF method fileToStream.
/**
* Decode the contents of the file and send to the {@link StreamRDF}.
* A filename ending {@code .gz} will have a gzip decompressor added.
* A filename of "-" is {@code System.in}.
* @param filename The file.
* @param dest Sink
*/
public static void fileToStream(String filename, StreamRDF dest) {
InputStream in = IO.openFile(filename);
TProtocol protocol = TRDF.protocol(in);
protocolToStream(protocol, dest);
}
Aggregations