use of org.apache.thrift.protocol.TCompactProtocol in project tech by ffyyhh995511.
the class Test2Client method main.
public static void main(String[] args) throws Exception {
// 设置传输通道,对于非阻塞服务,需要使用TFramedTransport,它将数据分块发送
TTransport transport = new TFramedTransport(new TSocket("localhost", 7911));
transport.open();
// 使用高密度二进制协议
TProtocol protocol = new TCompactProtocol(transport);
// 创建Client
Hello.Client client = new Hello.Client(protocol);
System.out.println("starting...");
long start = System.currentTimeMillis();
for (int i = 0; i < 10000; i++) {
client.helloBoolean(false);
client.helloInt(111);
// client.helloNull();
client.helloString("360buy");
client.helloVoid();
}
System.out.println("耗时:" + (System.currentTimeMillis() - start));
// 关闭资源
transport.close();
}
use of org.apache.thrift.protocol.TCompactProtocol in project tech by ffyyhh995511.
the class Test3Client method main.
public static void main(String[] args) throws Exception {
String address = "localhost";
int port = 7911;
int timeout = 100 * 1000;
// 使用非阻塞方式,按块的大小进行传输,类似于Java中的NIO。记得调用close释放资源
TTransport transport = new TFramedTransport(new TSocket(address, port, timeout));
// 高效率的、密集的二进制编码格式进行数据传输协议
TProtocol protocol = new TCompactProtocol(transport);
Hello.Client client = new Hello.Client(protocol);
try {
transport.open();
System.out.println(client.helloInt(111));
transport.close();
} catch (TException e) {
e.printStackTrace();
}
}
use of org.apache.thrift.protocol.TCompactProtocol in project tech by ffyyhh995511.
the class ThriftService method getDistributedIncrease.
/**
* 分布式递增
* @return
*/
public long getDistributedIncrease() {
TTransport transport = null;
Long increase = 0L;
try {
// 设置传输通道,对于非阻塞服务,需要使用TFramedTransport,它将数据分块发送
transport = new TFramedTransport(new TSocket("192.168.11.170", 7911));
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;
}
use of org.apache.thrift.protocol.TCompactProtocol in project hbase by apache.
the class TestThriftServerCmdLine method talkToThriftServer.
private void talkToThriftServer() throws Exception {
TSocket sock = new TSocket(InetAddress.getLocalHost().getHostName(), port);
TTransport transport = sock;
if (specifyFramed || implType.isAlwaysFramed) {
transport = new TFramedTransport(transport);
}
sock.open();
try {
TProtocol prot;
if (specifyCompact) {
prot = new TCompactProtocol(transport);
} else {
prot = new TBinaryProtocol(transport);
}
Hbase.Client client = new Hbase.Client(prot);
if (!tableCreated) {
TestThriftServer.createTestTables(client);
tableCreated = true;
}
TestThriftServer.checkTableList(client);
} finally {
sock.close();
}
}
use of org.apache.thrift.protocol.TCompactProtocol in project pinpoint by naver.
the class BytesUtilsTest method writeVInt32.
private TMemoryBuffer writeVInt32(int i) throws TException {
TMemoryBuffer tMemoryBuffer = new TMemoryBuffer(10);
TCompactProtocol tCompactProtocol = new TCompactProtocol(tMemoryBuffer);
tCompactProtocol.writeI32(i);
return tMemoryBuffer;
}
Aggregations