use of org.apache.thrift.protocol.TProtocol in project eiger by wlloyd.
the class ClientOnlyExample method createConnection.
private static Cassandra.Client createConnection(String host, Integer port, boolean framed) throws TTransportException {
TSocket socket = new TSocket(host, port);
TTransport trans = framed ? new TFramedTransport(socket) : socket;
trans.open();
TProtocol protocol = new TBinaryProtocol(trans);
return new Cassandra.Client(protocol);
}
use of org.apache.thrift.protocol.TProtocol in project eiger by wlloyd.
the class EmbeddedCassandraServiceTest method getClient.
/**
* Gets a connection to the localhost client
*
* @return
* @throws TTransportException
*/
private Cassandra.Client getClient() throws TTransportException {
TTransport tr = new TFramedTransport(new TSocket("localhost", DatabaseDescriptor.getRpcPort()));
TProtocol proto = new TBinaryProtocol(tr);
Cassandra.Client client = new Cassandra.Client(proto);
tr.open();
return client;
}
use of org.apache.thrift.protocol.TProtocol in project alluxio by Alluxio.
the class AbstractClient method connect.
/**
* Connects with the remote.
*
* @throws IOException if an I/O error occurs
* @throws ConnectionFailedException if network connection failed
*/
public synchronized void connect() throws IOException, ConnectionFailedException {
if (mConnected) {
return;
}
disconnect();
Preconditions.checkState(!mClosed, "Client is closed, will not try to connect.");
RetryPolicy retryPolicy = new ExponentialBackoffRetry(BASE_SLEEP_MS, MAX_SLEEP_MS, RPC_MAX_NUM_RETRY);
while (!mClosed) {
mAddress = getAddress();
LOG.info("Alluxio client (version {}) is trying to connect with {} {} @ {}", RuntimeConstants.VERSION, getServiceName(), mMode, mAddress);
TProtocol binaryProtocol = new TBinaryProtocol(mTransportProvider.getClientTransport(mParentSubject, mAddress));
mProtocol = new TMultiplexedProtocol(binaryProtocol, getServiceName());
try {
mProtocol.getTransport().open();
LOG.info("Client registered with {} {} @ {}", getServiceName(), mMode, mAddress);
mConnected = true;
afterConnect();
checkVersion(getClient(), getServiceVersion());
return;
} catch (IOException e) {
if (e.getMessage() != null && FRAME_SIZE_EXCEPTION_PATTERN.matcher(e.getMessage()).find()) {
// See an error like "Frame size (67108864) larger than max length (16777216)!",
// pointing to the helper page.
String message = String.format("Failed to connect to %s %s @ %s: %s. " + "This exception may be caused by incorrect network configuration. " + "Please consult %s for common solutions to address this problem.", getServiceName(), mMode, mAddress, e.getMessage(), RuntimeConstants.ALLUXIO_DEBUG_DOCS_URL);
throw new IOException(message, e);
}
throw e;
} catch (TTransportException e) {
LOG.warn("Failed to connect ({}) to {} {} @ {}: {}", retryPolicy.getRetryCount(), getServiceName(), mMode, mAddress, e.getMessage());
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);
}
// TODO(peis): Consider closing the connection here as well.
if (!retryPolicy.attemptRetry()) {
break;
}
}
}
// Reaching here indicates that we did not successfully connect.
throw new ConnectionFailedException("Failed to connect to " + getServiceName() + " " + mMode + " @ " + mAddress + " after " + (retryPolicy.getRetryCount()) + " attempts");
}
use of org.apache.thrift.protocol.TProtocol in project yyl_example by Relucent.
the class HelloClient method main.
public static void main(String[] args) {
TTransport transport = null;
try {
transport = new TSocket("localhost", 8090);
transport.open();
TProtocol protocol = new TBinaryProtocol(transport);
HelloService.Client client = new HelloService.Client(protocol);
System.out.println(client.hello("thrift world"));
} catch (TException e) {
e.printStackTrace();
} finally {
transport.close();
}
}
use of org.apache.thrift.protocol.TProtocol in project jena by apache.
the class ThriftConverter method getInputProtocol.
private static TProtocol getInputProtocol() {
TProtocol protocol = inputProtocols.get();
if (protocol != null)
return protocol;
protocol = new TCompactProtocol(getInputTransport());
inputProtocols.set(protocol);
return protocol;
}
Aggregations