Search in sources :

Example 61 with TSocket

use of org.apache.thrift.transport.TSocket in project vcell by virtualcell.

the class BioformatsImageDatasetReader method readImageDatasetFromMultiFiles.

@Override
public ImageDataset readImageDatasetFromMultiFiles(File[] files, ClientTaskStatusSupport status, boolean isTimeSeries, double timeInterval) throws Exception {
    try (TTransport transport = new TSocket("localhost", port)) {
        transport.open();
        TProtocol protocol = new TBinaryProtocol(transport);
        ImageDatasetService.Client client = new ImageDatasetService.Client(protocol);
        ArrayList<String> fileList = new ArrayList<String>();
        for (File f : files) {
            fileList.add(f.getAbsolutePath());
        }
        org.vcell.imagedataset.ImageDataset t_imageDataset = client.readImageDatasetFromMultiFiles(fileList, isTimeSeries, timeInterval);
        ImageDataset imageDataset = getImageDataset(t_imageDataset);
        return imageDataset;
    }
}
Also used : ImageDataset(cbit.vcell.VirtualMicroscopy.ImageDataset) ArrayList(java.util.ArrayList) ImageDatasetService(org.vcell.imagedataset.ImageDatasetService) TBinaryProtocol(org.apache.thrift.protocol.TBinaryProtocol) TProtocol(org.apache.thrift.protocol.TProtocol) TTransport(org.apache.thrift.transport.TTransport) File(java.io.File) TSocket(org.apache.thrift.transport.TSocket)

Example 62 with TSocket

use of org.apache.thrift.transport.TSocket in project vcell by virtualcell.

the class BioformatsImageDatasetReader method getImageSizeInfoForceZ.

@Override
public ImageSizeInfo getImageSizeInfoForceZ(String fileName, int forceZSize) throws Exception {
    try (TTransport transport = new TSocket("localhost", port)) {
        transport.open();
        TProtocol protocol = new TBinaryProtocol(transport);
        ImageDatasetService.Client client = new ImageDatasetService.Client(protocol);
        org.vcell.imagedataset.ImageSizeInfo t_imageSizeInfo = client.getImageSizeInfoForceZ(fileName, forceZSize);
        org.vcell.imagedataset.ISize t_size = t_imageSizeInfo.getISize();
        double[] timePoints = new double[t_imageSizeInfo.getTimePoints().size()];
        for (int i = 0; i < t_imageSizeInfo.getTimePointsSize(); i++) {
            timePoints[i] = t_imageSizeInfo.getTimePoints().get(i);
        }
        ImageSizeInfo imageSizeInfo = new ImageSizeInfo(t_imageSizeInfo.imagePath, new ISize(t_size.getX(), t_size.getY(), t_size.getZ()), t_imageSizeInfo.numChannels, timePoints, t_imageSizeInfo.selectedTimeIndex);
        return imageSizeInfo;
    }
}
Also used : ISize(org.vcell.util.ISize) ImageSizeInfo(cbit.image.ImageSizeInfo) 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 63 with TSocket

use of org.apache.thrift.transport.TSocket in project tech by ffyyhh995511.

the class RedisDistributedLock method serverTimeMillis.

/**
 * 获取服务器时间
 * @return
 */
private long serverTimeMillis() {
    long time = 0;
    TTransport transport = null;
    try {
        // 设置传输通道,对于非阻塞服务,需要使用TFramedTransport,它将数据分块发送
        transport = new TFramedTransport(new TSocket("192.168.11.173", 7911));
        transport.open();
        // 使用高密度二进制协议
        TProtocol protocol = new TCompactProtocol(transport);
        // 创建Client
        ServerTime.Client client = new ServerTime.Client(protocol);
        time = client.getTime();
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        if (transport != null) {
            // 关闭资源
            transport.close();
        }
    }
    return time;
}
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) IOException(java.io.IOException) TSocket(org.apache.thrift.transport.TSocket)

Example 64 with TSocket

use of org.apache.thrift.transport.TSocket in project tech by ffyyhh995511.

the class ThriftDemo method nioClient.

/**
 * 编写客户端,调用(阻塞式IO + 多线程处理)服务
 */
public void nioClient() {
    try {
        // 设置传输通道,对于非阻塞服务,需要使用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();
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : 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 65 with TSocket

use of org.apache.thrift.transport.TSocket in project tech by ffyyhh995511.

the class Test1Client method main.

public static void main(String[] args) throws Exception {
    // 设置传输通道 - 普通IO流通道
    TTransport transport = new TSocket("localhost", 7911);
    transport.open();
    // 使用高密度二进制协议
    TProtocol protocol = new TCompactProtocol(transport);
    // 创建Client
    Hello.Client client = new Hello.Client(protocol);
    long start = System.currentTimeMillis();
    for (int i = 0; i < 10000; i++) {
        client.helloBoolean(false);
        client.helloInt(111);
        // client.helloNull();
        client.helloString("dongjian");
        client.helloVoid();
    }
    System.out.println("耗时:" + (System.currentTimeMillis() - start));
    // 关闭资源
    transport.close();
}
Also used : Hello(org.tech.model.Hello) TProtocol(org.apache.thrift.protocol.TProtocol) TTransport(org.apache.thrift.transport.TTransport) TCompactProtocol(org.apache.thrift.protocol.TCompactProtocol) TSocket(org.apache.thrift.transport.TSocket)

Aggregations

TSocket (org.apache.thrift.transport.TSocket)66 TTransport (org.apache.thrift.transport.TTransport)43 TBinaryProtocol (org.apache.thrift.protocol.TBinaryProtocol)41 TProtocol (org.apache.thrift.protocol.TProtocol)36 TFramedTransport (org.apache.thrift.transport.TFramedTransport)33 IOException (java.io.IOException)16 TException (org.apache.thrift.TException)16 TTransportException (org.apache.thrift.transport.TTransportException)15 TCompactProtocol (org.apache.thrift.protocol.TCompactProtocol)9 Cassandra (org.apache.cassandra.thrift.Cassandra)5 ImageDatasetService (org.vcell.imagedataset.ImageDatasetService)5 Socket (java.net.Socket)4 SocketException (java.net.SocketException)4 ArrayList (java.util.ArrayList)4 HashMap (java.util.HashMap)4 Hello (org.tech.model.Hello)4 ImageDataset (cbit.vcell.VirtualMicroscopy.ImageDataset)3 ByteBuffer (java.nio.ByteBuffer)3 SSLSocket (javax.net.ssl.SSLSocket)3 TBinaryProtocol (org.apache.cassandra.thrift.TBinaryProtocol)3