當前位置: 首頁>>代碼示例>>Java>>正文


Java TSocket.close方法代碼示例

本文整理匯總了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;
}
 
開發者ID:airlift,項目名稱:drift,代碼行數:19,代碼來源:TestApacheThriftMethodInvoker.java

示例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();
}
 
開發者ID:RandyAbernethy,項目名稱:ThriftBook,代碼行數:16,代碼來源:ExcepClient.java

示例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();
}
 
開發者ID:RandyAbernethy,項目名稱:ThriftBook,代碼行數:11,代碼來源:HelloClient.java

示例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();
}
 
開發者ID:RandyAbernethy,項目名稱:ThriftBook,代碼行數:15,代碼來源:HelloClient.java

示例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();
}
 
開發者ID:RandyAbernethy,項目名稱:ThriftBook,代碼行數:13,代碼來源:ThriftClient.java

示例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();
}
 
開發者ID:RandyAbernethy,項目名稱:ThriftBook,代碼行數:13,代碼來源:ThriftClient.java

示例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();
    }
}
 
開發者ID:silverprize,項目名稱:thrift-tutorial,代碼行數:13,代碼來源:ExampleClient.java

示例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();
        }
    }
}
 
開發者ID:silverprize,項目名稱:thrift-tutorial,代碼行數:41,代碼來源:ExampleClient.java

示例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;
}
 
開發者ID:silverprize,項目名稱:thrift-tutorial,代碼行數:15,代碼來源:ExampleClient.java

示例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();
		}
	}
 
開發者ID:smallmiro,項目名稱:NettyThrift,代碼行數:25,代碼來源:JavaClient.java

示例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();
        }
    }
}
 
開發者ID:silverprize,項目名稱:thrift-tutorial,代碼行數:45,代碼來源:ExampleClient.java


注:本文中的org.apache.thrift.transport.TSocket.close方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。