Search in sources :

Example 46 with TProtocol

use of org.apache.thrift.protocol.TProtocol 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();
    }
}
Also used : TException(org.apache.thrift.TException) Hello(org.tech.model.Hello) TProtocol(org.apache.thrift.protocol.TProtocol) TFramedTransport(org.apache.thrift.transport.TFramedTransport) TTransport(org.apache.thrift.transport.TTransport) TCompactProtocol(org.apache.thrift.protocol.TCompactProtocol) TSocket(org.apache.thrift.transport.TSocket)

Example 47 with TProtocol

use of org.apache.thrift.protocol.TProtocol 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;
}
Also used : TProtocol(org.apache.thrift.protocol.TProtocol) TFramedTransport(org.apache.thrift.transport.TFramedTransport) TTransport(org.apache.thrift.transport.TTransport) TCompactProtocol(org.apache.thrift.protocol.TCompactProtocol) ServerTime(org.tech.commons.model.ServerTime) TException(org.apache.thrift.TException) TSocket(org.apache.thrift.transport.TSocket)

Example 48 with TProtocol

use of org.apache.thrift.protocol.TProtocol in project vcell by virtualcell.

the class SimpleClient method main.

public static void main(String[] args) {
    try {
        TTransport transport;
        transport = new TSocket("localhost", 9091);
        transport.open();
        TProtocol protocol = new TBinaryProtocol(transport);
        SimulationService.Client client = new SimulationService.Client(protocol);
        perform(client);
        transport.close();
    } catch (TException x) {
        x.printStackTrace();
    }
}
Also used : TException(org.apache.thrift.TException) TBinaryProtocol(org.apache.thrift.protocol.TBinaryProtocol) TProtocol(org.apache.thrift.protocol.TProtocol) TTransport(org.apache.thrift.transport.TTransport) SimulationService(org.vcell.vcellij.api.SimulationService) TSocket(org.apache.thrift.transport.TSocket)

Example 49 with TProtocol

use of org.apache.thrift.protocol.TProtocol in project vcell by virtualcell.

the class BioformatsImageDatasetReader method readImageDatasetChannels.

@Override
public ImageDataset[] readImageDatasetChannels(String imageID, ClientTaskStatusSupport status, boolean bMergeChannels, Integer timeIndex, ISize resize) throws Exception {
    try (TTransport transport = new TSocket("localhost", port)) {
        transport.open();
        TProtocol protocol = new TBinaryProtocol(transport);
        ImageDatasetService.Client client = new ImageDatasetService.Client(protocol);
        String fileName = imageID;
        org.vcell.imagedataset.ISize t_resize = null;
        if (resize != null) {
            t_resize = new org.vcell.imagedataset.ISize(resize.getX(), resize.getY(), resize.getZ());
        }
        List<org.vcell.imagedataset.ImageDataset> t_imageDatasetList = client.readImageDatasetChannels(fileName, bMergeChannels, timeIndex, t_resize);
        ImageDataset[] imageDatasets = new ImageDataset[t_imageDatasetList.size()];
        for (int i = 0; i < t_imageDatasetList.size(); i++) {
            imageDatasets[i] = getImageDataset(t_imageDatasetList.get(i));
        }
        return imageDatasets;
    }
}
Also used : ImageDataset(cbit.vcell.VirtualMicroscopy.ImageDataset) ImageDatasetService(org.vcell.imagedataset.ImageDatasetService) TBinaryProtocol(org.apache.thrift.protocol.TBinaryProtocol) TProtocol(org.apache.thrift.protocol.TProtocol) TTransport(org.apache.thrift.transport.TTransport) TSocket(org.apache.thrift.transport.TSocket)

Example 50 with TProtocol

use of org.apache.thrift.protocol.TProtocol in project vcell by virtualcell.

the class BioformatsImageDatasetReader method readImageDataset.

@Override
public ImageDataset readImageDataset(String imageID, ClientTaskStatusSupport status) throws Exception {
    try (TTransport transport = new TSocket("localhost", port)) {
        transport.open();
        TProtocol protocol = new TBinaryProtocol(transport);
        ImageDatasetService.Client client = new ImageDatasetService.Client(protocol);
        String fileName = imageID;
        org.vcell.imagedataset.ImageDataset t_imageDataset = client.readImageDataset(fileName);
        ImageDataset imageDataset = getImageDataset(t_imageDataset);
        return imageDataset;
    }
}
Also used : ImageDatasetService(org.vcell.imagedataset.ImageDatasetService) TBinaryProtocol(org.apache.thrift.protocol.TBinaryProtocol) ImageDataset(cbit.vcell.VirtualMicroscopy.ImageDataset) TProtocol(org.apache.thrift.protocol.TProtocol) TTransport(org.apache.thrift.transport.TTransport) TSocket(org.apache.thrift.transport.TSocket)

Aggregations

TProtocol (org.apache.thrift.protocol.TProtocol)93 TTransport (org.apache.thrift.transport.TTransport)42 TBinaryProtocol (org.apache.thrift.protocol.TBinaryProtocol)36 TSocket (org.apache.thrift.transport.TSocket)36 TException (org.apache.thrift.TException)25 TFramedTransport (org.apache.thrift.transport.TFramedTransport)24 TCompactProtocol (org.apache.thrift.protocol.TCompactProtocol)18 IOException (java.io.IOException)16 TIOStreamTransport (org.apache.thrift.transport.TIOStreamTransport)10 THttpClient (org.apache.thrift.transport.THttpClient)9 ArrayList (java.util.ArrayList)8 TTransportException (org.apache.thrift.transport.TTransportException)8 ByteArrayOutputStream (java.io.ByteArrayOutputStream)7 TJSONProtocol (org.apache.thrift.protocol.TJSONProtocol)7 RDF_Term (org.apache.jena.riot.thrift.wire.RDF_Term)6 TProcessor (org.apache.thrift.TProcessor)6 InputStream (java.io.InputStream)5 TTransportFactory (org.apache.thrift.transport.TTransportFactory)5 ImageDatasetService (org.vcell.imagedataset.ImageDatasetService)5 Hbase (org.apache.hadoop.hbase.thrift.generated.Hbase)4