Search in sources :

Example 51 with TTransport

use of org.apache.thrift.transport.TTransport 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 52 with TTransport

use of org.apache.thrift.transport.TTransport 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)

Example 53 with TTransport

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

the class BioformatsImageDatasetReader method getImageSizeInfo.

@Override
public ImageSizeInfo getImageSizeInfo(String fileName) 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.getImageSizeInfo(fileName);
        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 54 with TTransport

use of org.apache.thrift.transport.TTransport in project janusgraph by JanusGraph.

the class ThriftConnectionTest method testConnectionDropped.

@Test
public void testConnectionDropped() throws Exception {
    CTConnectionFactory connectionFactory = spy(factoryConfig.build());
    CTConnection mockConnection = spy(connectionFactory.makeObject("janusgraph"));
    when(mockConnection.getConfig()).thenReturn(factoryConfig);
    when(mockConnection.isOpen()).thenReturn(true);
    TTransport mockClient = spy(mockConnection.getTransport());
    assertTrue(connectionFactory.validateObject(null, mockConnection));
    when(mockClient.readAll(new byte[0], 0, 0)).thenThrow(new TTransportException("Broken Pipe"));
    assertTrue(mockClient.isOpen());
}
Also used : CTConnection(org.janusgraph.diskstorage.cassandra.thrift.thriftpool.CTConnection) TTransportException(org.apache.thrift.transport.TTransportException) TTransport(org.apache.thrift.transport.TTransport) CTConnectionFactory(org.janusgraph.diskstorage.cassandra.thrift.thriftpool.CTConnectionFactory) Test(org.junit.Test)

Example 55 with TTransport

use of org.apache.thrift.transport.TTransport in project janusgraph by JanusGraph.

the class CTConnectionFactory method makeRawConnection.

/**
 * Create a Cassandra-Thrift connection, but do not attempt to
 * set a keyspace on the connection.
 *
 * @return A CTConnection ready to talk to a Cassandra cluster
 * @throws TTransportException on any Thrift transport failure
 */
public CTConnection makeRawConnection() throws TTransportException {
    final Config cfg = cfgRef.get();
    String hostname = cfg.getRandomHost();
    log.debug("Creating TSocket({}, {}, {}, {}, {})", hostname, cfg.port, cfg.username, cfg.password, cfg.timeoutMS);
    TSocket socket;
    if (null != cfg.sslTruststoreLocation && !cfg.sslTruststoreLocation.isEmpty()) {
        TSSLTransportFactory.TSSLTransportParameters params = new TSSLTransportFactory.TSSLTransportParameters() {

            {
                setTrustStore(cfg.sslTruststoreLocation, cfg.sslTruststorePassword);
            }
        };
        socket = TSSLTransportFactory.getClientSocket(hostname, cfg.port, cfg.timeoutMS, params);
    } else {
        socket = new TSocket(hostname, cfg.port, cfg.timeoutMS);
    }
    TTransport transport = new TFramedTransport(socket, cfg.frameSize);
    log.trace("Created transport {}", transport);
    TBinaryProtocol protocol = new TBinaryProtocol(transport);
    Cassandra.Client client = new Cassandra.Client(protocol);
    if (!transport.isOpen()) {
        transport.open();
    }
    if (cfg.username != null) {
        Map<String, String> credentials = new HashMap<String, String>() {

            {
                put(IAuthenticator.USERNAME_KEY, cfg.username);
                put(IAuthenticator.PASSWORD_KEY, cfg.password);
            }
        };
        try {
            client.login(new AuthenticationRequest(credentials));
        } catch (Exception e) {
            // TTransportException will propagate authentication/authorization failure
            throw new TTransportException(e);
        }
    }
    return new CTConnection(transport, client, cfg);
}
Also used : HashMap(java.util.HashMap) Cassandra(org.apache.cassandra.thrift.Cassandra) TTransportException(org.apache.thrift.transport.TTransportException) TSSLTransportFactory(org.apache.thrift.transport.TSSLTransportFactory) TTransportException(org.apache.thrift.transport.TTransportException) TException(org.apache.thrift.TException) TBinaryProtocol(org.apache.thrift.protocol.TBinaryProtocol) TFramedTransport(org.apache.thrift.transport.TFramedTransport) TTransport(org.apache.thrift.transport.TTransport) AuthenticationRequest(org.apache.cassandra.thrift.AuthenticationRequest) TSocket(org.apache.thrift.transport.TSocket)

Aggregations

TTransport (org.apache.thrift.transport.TTransport)99 TSocket (org.apache.thrift.transport.TSocket)43 TProtocol (org.apache.thrift.protocol.TProtocol)42 TBinaryProtocol (org.apache.thrift.protocol.TBinaryProtocol)36 TFramedTransport (org.apache.thrift.transport.TFramedTransport)28 TTransportException (org.apache.thrift.transport.TTransportException)20 Test (org.junit.Test)20 TException (org.apache.thrift.TException)18 IOException (java.io.IOException)12 TCompactProtocol (org.apache.thrift.protocol.TCompactProtocol)10 ArrayList (java.util.ArrayList)9 TIOStreamTransport (org.apache.thrift.transport.TIOStreamTransport)8 HashMap (java.util.HashMap)6 Socket (java.net.Socket)5 TCLIService (org.apache.hive.service.rpc.thrift.TCLIService)5 THttpClient (org.apache.thrift.transport.THttpClient)4 TSaslClientTransport (org.apache.thrift.transport.TSaslClientTransport)4 ChannelBuffer (com.alibaba.dubbo.remoting.buffer.ChannelBuffer)3 Request (com.alibaba.dubbo.remoting.exchange.Request)3 Demo (com.alibaba.dubbo.rpc.gen.thrift.Demo)3