本文整理汇总了Java中org.apache.thrift.transport.TSocket.close方法的典型用法代码示例。如果您正苦于以下问题:Java TSocket.close方法的具体用法?Java TSocket.close怎么用?Java TSocket.close使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.thrift.transport.TSocket
的用法示例。
在下文中一共展示了TSocket.close方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: logThrift
import org.apache.thrift.transport.TSocket; //导入方法依赖的package包/类
private static int logThrift(HostAndPort address, List<LogEntry> messages)
{
try {
TSocket socket = new TSocket(address.getHost(), address.getPort());
socket.open();
try {
TBinaryProtocol tp = new TBinaryProtocol(new TFramedTransport(socket));
assertEquals(new scribe.Client(tp).Log(messages), ResultCode.OK);
}
finally {
socket.close();
}
}
catch (TException e) {
throw new RuntimeException(e);
}
return 1;
}
示例2: main
import org.apache.thrift.transport.TSocket; //导入方法依赖的package包/类
public static void main(String[] args) throws TException {
TSocket trans = new TSocket("localhost", 9090);
TBinaryProtocol proto = new TBinaryProtocol(trans);
TradeHistory.Client client = new TradeHistory.Client(proto);
try {
trans.open();
double price = client.GetLastSale(args[0]);
System.out.println("[Client] received: " + price);
} catch (BadFish bf) {
System.out.println("[Client] GetLastSale() call failed for fish: " +
bf.fish + ", error " + bf.error_code);
}
trans.close();
}
示例3: main
import org.apache.thrift.transport.TSocket; //导入方法依赖的package包/类
public static void main(String[] args) throws TException {
TSocket trans = new TSocket("localhost", 9090);
TBinaryProtocol proto = new TBinaryProtocol(trans);
HelloSvc.Client client = new HelloSvc.Client(proto);
trans.open();
String str = client.hello_func();
System.out.println("[Client] received: " + str);
trans.close();
}
示例4: main
import org.apache.thrift.transport.TSocket; //导入方法依赖的package包/类
public static void main(String[] args) {
TSocket trans = new TSocket("localhost", 9090);
TBinaryProtocol proto = new TBinaryProtocol(trans);
helloSvc.Client client = new helloSvc.Client(proto);
try {
trans.open();
String str = client.getMessage("world");
System.out.println("[Client] received: " + str);
} catch (TException ex) {
System.out.println("Error: " + ex.toString());
}
trans.close();
}
示例5: main
import org.apache.thrift.transport.TSocket; //导入方法依赖的package包/类
public static void main(String[] args)
throws IOException, TException {
TSocket trans = new TSocket("localhost", 9090);
TJSONProtocol proto = new TJSONProtocol(trans);
TradeHistory.Client client = new TradeHistory.Client(proto);
trans.open();
for (int i = 0; i < 1000000; i++) {
TradeReport tr = client.get_last_sale("APPL");
}
trans.close();
}
示例6: main
import org.apache.thrift.transport.TSocket; //导入方法依赖的package包/类
public static void main(String[] args)
throws IOException, TException {
TSocket trans = new TSocket("localhost", 9090);
TBinaryProtocol proto = new TBinaryProtocol(trans);
TradeHistory.Client client = new TradeHistory.Client(proto);
trans.open();
for (int i = 0; i < 1000000; i++) {
TradeReport tr = client.get_last_sale("APPL");
}
trans.close();
}
示例7: echo
import org.apache.thrift.transport.TSocket; //导入方法依赖的package包/类
private static void echo(TSocket socket, String msg) {
try {
TProtocol protocol = new TBinaryProtocol(socket);
EchoService.Client client = new EchoService.Client(protocol);
socket.open();
String rev = client.echo(msg);
System.out.println(rev);
socket.close();
} catch (TException e) {
e.printStackTrace();
}
}
示例8: upload
import org.apache.thrift.transport.TSocket; //导入方法依赖的package包/类
private static void upload(TSocket socket, String path) throws URISyntaxException, IOException {
File file = new File(path);
if (!file.exists()) {
System.out.println("File not found \"" + file.getAbsolutePath() + "\"");
return;
}
FileInputStream fis = new FileInputStream(file);
try {
TransferInfo reqInfo = new TransferInfo();
reqInfo.type = TransferType.REQUEST;
reqInfo.fileName = file.getName();
reqInfo.length = file.length();
socket.open();
TProtocol protocol = new TBinaryProtocol(socket);
UploadService.Client client = new UploadService.Client(protocol);
client.upload(reqInfo);
reqInfo.type = TransferType.PROGRESS;
reqInfo.data = ByteBuffer.allocate(1024 * 10);
FileChannel fileChannel = fis.getChannel();
while ((reqInfo.length = fileChannel.read(reqInfo.data)) > 0) {
reqInfo.data.flip();
client.upload(reqInfo);
reqInfo.data.clear();
}
System.out.println("Success to upload.");
} catch (TException e) {
e.printStackTrace();
fis.close();
fis = null;
file.delete();
} finally {
socket.close();
if (fis != null) {
fis.close();
}
}
}
示例9: getAvailableFileList
import org.apache.thrift.transport.TSocket; //导入方法依赖的package包/类
private static List<String> getAvailableFileList(TSocket socket) {
try {
TProtocol protocol = new TBinaryProtocol(socket);
DownloadService.Client client = new DownloadService.Client(protocol);
socket.open();
List<String> list = client.getFileList();
return list;
} catch (TException e) {
e.printStackTrace();
} finally {
socket.close();
}
return null;
}
示例10: main
import org.apache.thrift.transport.TSocket; //导入方法依赖的package包/类
public static void main(String[] args) {
try {
TSocket transport = new TSocket("localhost", 9090);
transport.open();
TBinaryProtocol protocol = new TBinaryProtocol(transport);
TMultiplexedProtocol mp = new TMultiplexedProtocol(protocol, "Calculator");
Calculator.Client client = new Calculator.Client(mp);
TMultiplexedProtocol mp2 = new TMultiplexedProtocol(protocol, "Scribe");
scribe.Client client2 = new scribe.Client(mp2);
testCalculator(client);
testScribe(client2);
transport.close();
} catch (TException x) {
x.printStackTrace();
}
}
示例11: download
import org.apache.thrift.transport.TSocket; //导入方法依赖的package包/类
private static void download(TSocket socket, String fileName)
throws IOException {
int dot = fileName.lastIndexOf('.');
String name = dot != -1 ? fileName.substring(0, fileName.indexOf('.')) : fileName;
String ext = dot != -1 ? fileName.substring(name.length()) : ".unknown";
File destinationDir = new File("downloads");
File destination = File.createTempFile(name, ext, destinationDir);
FileOutputStream fos = new FileOutputStream(destination);
try {
TransferInfo reqInfo = new TransferInfo();
reqInfo.type = TransferType.REQUEST;
reqInfo.fileName = fileName;
socket.open();
TProtocol protocol = new TBinaryProtocol(socket);
DownloadService.Client client = new DownloadService.Client(protocol);
TransferInfo recvInfo = client.download(reqInfo);
if (!destinationDir.exists()) {
destinationDir.mkdirs();
}
long total = recvInfo.length;
long offset = 0;
reqInfo.type = TransferType.PROGRESS;
do {
recvInfo = client.download(reqInfo);
offset += recvInfo.length;
fos.getChannel().write(recvInfo.data);
} while (total > offset);
System.out.println("Success to download.");
} catch (TException e) {
e.printStackTrace();
fos.close();
fos = null;
destination.delete();
} finally {
socket.close();
if (fos != null) {
fos.close();
}
}
}