Example usage for org.apache.thrift.transport TSocket TSocket

List of usage examples for org.apache.thrift.transport TSocket TSocket

Introduction

In this page you can find the example usage for org.apache.thrift.transport TSocket TSocket.

Prototype

public TSocket(String host, int port) 

Source Link

Document

Creates a new unconnected socket that will connect to the given host on the given port.

Usage

From source file:appSetup.java

License:Apache License

private static Cassandra.Client createConnection(String host, Integer port, boolean framed)
        throws TTransportException {
    TSocket socket = new TSocket(host, port);
    TTransport trans = framed ? new TFramedTransport(socket) : socket;
    trans.open();/*from   w w w. ja v a 2 s .c  o  m*/
    TProtocol protocol = new TBinaryProtocol(trans);

    return new Cassandra.Client(protocol);
}

From source file:JavaClient2.java

License:Apache License

public static void main(String[] args) {

    // 1st args is "simple", 2nd args is server address
    if (args.length != 2 || !args[0].contains("simple")) {
        System.out.println("Please enter 'simple' ");
        System.exit(0);/*ww w  .ja  va2  s.  co m*/
    }

    try {
        TTransport transport;
        transport = new TSocket(args[1], 14264);
        transport.open();

        TProtocol protocol = new TBinaryProtocol(transport);
        Myservice.Client client = new Myservice.Client(protocol);

        perform(client);

        transport.close();
    } catch (TException x) {
        x.printStackTrace();
    }
}

From source file:SClient.java

License:Apache License

public SClient(String s, int p) {
    this.ip = s;//from  ww  w  . j  a v  a2s  . c o  m
    this.port = p;
    if (transport == null)
        transport = new TSocket(this.ip, this.port);
    if (protocol == null) {
        protocol = new TBinaryProtocol(transport);
        client = new Sentiments.Client(protocol);
        try {
            transport.open();
        } catch (TTransportException e) {
            e.printStackTrace();
        }
    }

}

From source file:FilesystemClient.java

public static void main(String[] args) {
    try {/*  w  ww  .j a va  2s . co  m*/
        TTransport transport;
        transport = new TSocket("localhost", 9090);
        transport.open();
        TProtocol protocol = new TBinaryProtocol(transport);
        FilesystemService.Client client = new FilesystemService.Client(protocol);
        perform(client);
        transport.close();
    } catch (TException x) {
        x.printStackTrace();
    } catch (IOException ex) {
        ex.printStackTrace();
    }
}

From source file:JavaClient.java

License:Apache License

public static void main(String[] args) {

    if (args.length != 1) {
        System.out.println("Please enter 'simple' or 'secure'");
        System.exit(0);//w w w  . j a  va2 s.co  m
    }

    try {
        TTransport transport;
        if (args[0].contains("simple")) {
            transport = new TSocket("localhost", 9090);
            transport.open();
        } else {
            /*
             * Similar to the server, you can use the parameters to setup client parameters or
             * use the default settings. On the client side, you will need a TrustStore which
             * contains the trusted certificate along with the public key. 
             * For this example it's a self-signed cert. 
             */
            TSSLTransportParameters params = new TSSLTransportParameters();
            params.setTrustStore("../../lib/java/test/.truststore", "thrift", "SunX509", "JKS");
            /*
             * Get a client transport instead of a server transport. The connection is opened on
             * invocation of the factory method, no need to specifically call open()
             */
            transport = TSSLTransportFactory.getClientSocket("localhost", 9091, 0, params);
        }

        TProtocol protocol = new TBinaryProtocol(transport);
        Calculator.Client client = new Calculator.Client(protocol);

        perform(client);

        transport.close();
    } catch (TException x) {
        x.printStackTrace();
    }
}

From source file:StreamerClientTest.java

License:Open Source License

public static void main(String[] args) throws Exception {

    TTransport transport;//w  ww .jav  a  2s.co m

    transport = new TSocket("localhost", 7911);

    TProtocol protocol = new TBinaryProtocol(transport);

    Streamer.Client client = new Streamer.Client(protocol);
    transport.open();

    String accessKey = "defaultAccessKey";
    String secretKey = "defaultSecretKey";

    int count = 100;
    Random rnd = new Random();
    for (int i = 0; i < count; i++) {
        Tuple tuple = new Tuple();

        String id = UUID.randomUUID().toString();
        tuple.setId(id);

        String topic = "testTopic01";
        tuple.setTopic(topic);

        String correlationId = UUID.randomUUID().toString();
        tuple.setCorrelationId(correlationId);

        Map<String, String> headers = new HashMap<String, String>();
        headers.put("category", "test");
        tuple.setHeaders(headers);

        Map<String, String> payload = new HashMap<String, String>();
        payload.put("id", 6900 + i + "");
        String name = "Aditya" + rnd.nextInt();
        payload.put("name", name);
        tuple.setPayload(payload);

        client.tellTuple(accessKey, secretKey, tuple);
        System.out.println("Sent: " + name);
    }

    transport.close();
    System.out.println("Done!");
    System.exit(0);
}

From source file:MapDExample.java

License:Apache License

public static MapD.Client get_client(String host_or_uri, int port, boolean http) {
    THttpClient httpTransport;/*  w w  w  . j a  va 2s .  com*/
    TTransport transport;
    TBinaryProtocol protocol;
    TJSONProtocol jsonProtocol;
    TSocket socket;
    MapD.Client client;

    try {
        if (http) {
            httpTransport = new THttpClient(host_or_uri);
            jsonProtocol = new TJSONProtocol(httpTransport);
            client = new MapD.Client(jsonProtocol);
            httpTransport.open();
            return client;
        } else {
            transport = new TSocket(host_or_uri, port);
            protocol = new TBinaryProtocol(transport);
            client = new MapD.Client(protocol);
            transport.open();
            return client;
        }
    } catch (TException x) {
        x.printStackTrace();
    }
    return null;
}

From source file:agiato.cassandra.connect.Connector.java

License:Apache License

public Cassandra.Client openConnection() {
    try {//from   w  ww.  j  av  a  2 s  .  c  o m
        if (null == trans) {
            //trans = new TSocket("localhost", 9160);
            trans = new TFramedTransport(new TSocket(getHost().getName(), getHost().getPort()));

            TProtocol proto = new TBinaryProtocol(trans);
            client = new Cassandra.Client(proto);
            trans.open();
        }
    } catch (TTransportException exception) {
        System.out.println("failed to open Cassandra connection" + exception);
        exception.printStackTrace();
    }

    return client;
}

From source file:andromache.config.CassandraConfigHelper.java

License:Apache License

public static Cassandra.Client createConnection(Configuration conf, String host, Integer port)
        throws IOException {
    try {//  ww w  .  j  a va  2 s .  c o  m
        TSocket socket = new TSocket(host, port);
        TTransport transport = ConfigHelper.getInputTransportFactory(conf).openTransport(socket);
        return new Cassandra.Client(new TBinaryProtocol(transport));
    } catch (LoginException e) {
        throw new IOException("Unable to login to server " + host + ":" + port, e);
    } catch (TTransportException e) {
        throw new IOException("Unable to connect to server " + host + ":" + port, e);
    }
}

From source file:apache.JavaClient.java

License:Apache License

public static void main(String[] args) {

    if (args.length != 1) {
        System.out.println("Please enter 'simple' or 'secure'");
        System.exit(0);/*w  w w. j  ava  2 s.  com*/
    }

    try {
        TTransport transport;
        if (args[0].contains("simple")) {
            transport = new TSocket("localhost", 9090);
            transport.open();
        } else {
            /*
             * Similar to the server, you can use the parameters to setup
             * client parameters or use the default settings. On the client
             * side, you will need a TrustStore which contains the trusted
             * certificate along with the public key. For this example it's
             * a self-signed cert.
             */
            TSSLTransportParameters params = new TSSLTransportParameters();
            params.setTrustStore(JavaClient.class.getClass().getResource("/") + "key.truststore", "thrift",
                    "SunX509", "JKS");
            /*
             * Get a client transport instead of a server transport. The
             * connection is opened on invocation of the factory method, no
             * need to specifically call open()
             */
            transport = TSSLTransportFactory.getClientSocket("localhost", 9091, 0, params);
        }

        TProtocol protocol = new TBinaryProtocol(transport);
        Calculator.Client client = new Calculator.Client(protocol);

        perform(client);

        transport.close();
    } catch (TException x) {
        x.printStackTrace();
    }
}