use of org.apache.thrift.transport.TFramedTransport in project incubator-heron by apache.
the class ScribeSink method open.
// Open the TTransport connection and client to scribe server
private boolean open() {
try {
TSocket socket = new TSocket((String) config.get(KEY_SCRIBE_HOST), TypeUtils.getInteger(config.get(KEY_SCRIBE_PORT)), TypeUtils.getInteger(config.get(KEY_SCRIBE_TIMEOUT_MS)));
transport = new TFramedTransport(socket);
transport.open();
} catch (TException tx) {
LOG.log(Level.SEVERE, "Failed to open connection to scribe server " + connectionString(), tx);
return false;
}
LOG.info("Opened connection to scribe server " + connectionString());
TProtocol protocol = new TBinaryProtocol(transport);
client = new scribe.Client(protocol);
return true;
}
use of org.apache.thrift.transport.TFramedTransport in project summer by foxsugar.
the class RpcManager method charge.
private static void charge(String ip, int id, int num) throws TException {
TTransport adminTransport = new TFramedTransport(new TSocket(ip, 9090));
adminTransport.open();
// TTransport adminTransport = TransportManager.getTransport(ip, 9090);
GameRPC.Client client = GameRpcClient.getAClient(adminTransport);
// client.getUserInfo(1);
Order order = new Order();
order.setUserId(id);
order.setNum(num);
order.setType(1);
int rtn = client.charge(order);
adminTransport.close();
// 充值成功
if (rtn == 0) {
// todo 插入一条充值记录
}
}
use of org.apache.thrift.transport.TFramedTransport in project dubbo by alibaba.
the class ThriftProtocol method doReferFrameAndCompact.
private <T> T doReferFrameAndCompact(Class<T> type, URL url) throws RpcException {
try {
T thriftClient = null;
String typeName = type.getName();
if (typeName.endsWith(THRIFT_IFACE)) {
String clientClsName = typeName.substring(0, typeName.indexOf(THRIFT_IFACE)) + THRIFT_CLIENT;
Class<?> clazz = Class.forName(clientClsName);
Constructor constructor = clazz.getConstructor(TProtocol.class);
try {
TSocket tSocket = new TSocket(url.getHost(), url.getPort());
TTransport transport = new TFramedTransport(tSocket);
TProtocol tprotocol = new TCompactProtocol(transport);
TMultiplexedProtocol protocol = new TMultiplexedProtocol(tprotocol, typeName);
thriftClient = (T) constructor.newInstance(protocol);
transport.open();
logger.info("nativethrift client opened for service(" + url + ")");
} catch (Exception e) {
logger.error(e.getMessage(), e);
throw new RpcException("Fail to create remote client:" + e.getMessage(), e);
}
}
return thriftClient;
} catch (Exception e) {
logger.error(e.getMessage(), e);
throw new RpcException("Fail to create remote client for service(" + url + "): " + e.getMessage(), e);
}
}
use of org.apache.thrift.transport.TFramedTransport 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.transport.TFramedTransport in project tech by ffyyhh995511.
the class ThriftService2 method getDistributedIncrease.
/**
* 分布式递增
* @return
*/
public long getDistributedIncrease() {
int timeout = 100 * 1000;
TTransport transport = null;
Long increase = 0L;
try {
// 设置传输通道,对于非阻塞服务,需要使用TFramedTransport,它将数据分块发送
transport = new TFramedTransport(new TSocket("192.168.11.173", 7911, timeout));
transport.open();
// 使用高密度二进制协议
TProtocol protocol = new TCompactProtocol(transport);
// 创建Client
ServerTime.Client client = new ServerTime.Client(protocol);
increase = client.getIncrease();
} catch (Exception e) {
// logger.error(e.getStackTrace());
e.printStackTrace();
} finally {
// 关闭资源
if (transport != null) {
transport.close();
}
}
return increase;
}
Aggregations