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

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

Introduction

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

Prototype

public TFramedTransport(TTransport transport) 

Source Link

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();//w w w .  jav a  2s . c om
    TProtocol protocol = new TBinaryProtocol(trans);

    return new Cassandra.Client(protocol);
}

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

License:Apache License

public Cassandra.Client openConnection() {
    try {/* ww  w  . jav  a  2  s  . c  om*/
        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:alluxio.security.authentication.AuthenticationUtils.java

License:Apache License

/**
 * Creates a transport per the connection options. Supported transport options are:
 * {@link AuthType#NOSASL}, {@link AuthType#SIMPLE}, {link@ AuthType#CUSTOM},
 * {@link AuthType#KERBEROS}. With NOSASL as input, an unmodified TTransport is returned; with
 * SIMPLE/CUSTOM as input, a PlainClientTransport is returned; KERBEROS is not supported
 * currently. If the auth type is not supported or recognized, an
 * {@link UnsupportedOperationException} is thrown.
 *
 * @param conf Alluxio Configuration//from   w  w  w  .  jav  a 2s.c  o  m
 * @param serverAddress the server address which clients will connect to
 * @return a TTransport for client
 * @throws IOException if building a TransportFactory fails or user login fails
 */
public static TTransport getClientTransport(Configuration conf, InetSocketAddress serverAddress)
        throws IOException {
    AuthType authType = conf.getEnum(Constants.SECURITY_AUTHENTICATION_TYPE, AuthType.class);
    TTransport tTransport = AuthenticationUtils.createTSocket(serverAddress,
            conf.getInt(Constants.SECURITY_AUTHENTICATION_SOCKET_TIMEOUT_MS));
    switch (authType) {
    case NOSASL:
        return new TFramedTransport(tTransport);
    case SIMPLE: // intended to fall through
    case CUSTOM:
        String username = LoginUser.get(conf).getName();
        return PlainSaslUtils.getPlainClientTransport(username, "noPassword", tTransport);
    case KERBEROS:
        throw new UnsupportedOperationException(
                "getClientTransport: Kerberos is not " + "supported currently.");
    default:
        throw new UnsupportedOperationException(
                "getClientTransport: Unsupported authentication type: " + authType.getAuthName());
    }
}

From source file:application.middleware.ChatAdminHandler.java

public ChatAdminHandler() {
    String host = Registry.get("thrift.connection.server.host");
    int port = Integer.parseInt(Registry.get("thrift.connection.server.port"));
    transport = new TSocket(host, port);
    TFramedTransport framedTransport = new TFramedTransport(transport);
    TProtocol protocol = new TBinaryProtocol(framedTransport);
    client = new library.thrift.ChatProject.Client(protocol);
}

From source file:asyncnode.implement.cassandra.CassandraHelper.java

License:Apache License

public static void invokeCassandraCore(CassandraDescrib cassandraDescrib, IAction<Cassandra.Client> action)
        throws Exception {

    TSocket socket = new TSocket(cassandraDescrib.getIp(), cassandraDescrib.getPort());
    String keyspace = cassandraDescrib.getKeySpace();
    String columnFamily = cassandraDescrib.getColumnFamily();
    ConsistencyLevel consistencyLevel = cassandraDescrib.getConsistencyLevel();
    TTransport tr = new TFramedTransport(socket);
    try {/*from www.j av  a2 s  .c om*/
        TProtocol proto = new TBinaryProtocol(tr);
        Cassandra.Client client = new Cassandra.Client(proto);
        tr.open();
        client.set_keyspace(keyspace);
        if (action != null) {
            action.invoke(client);
        }
    } finally {
        if (tr != null) {
            tr.close();
        }
    }
}

From source file:backtype.storm.security.auth.SimpleTransportPlugin.java

License:Apache License

/**
 * Connect to the specified server via framed transport 
 * @param transport The underlying Thrift transport.
 *//*from w  w w  .  ja  v a  2s . co m*/
public TTransport connect(TTransport transport, String serverHost) throws TTransportException {
    //create a framed transport
    TTransport conn = new TFramedTransport(transport);

    //connect
    conn.open();
    LOG.debug("Simple client transport has been established");

    return conn;
}

From source file:business.middleware.BusinessChatHandler.java

public BusinessChatHandler() {
    String host = Registry.get("thrift.connection.server.host", "localhost");
    int port = Registry.getInt("thrift.connection.server.port", 9090);
    transport = new TSocket(host, port);
    TFramedTransport framedTransport = new TFramedTransport(transport);
    TProtocol protocol = new TBinaryProtocol(framedTransport);
    client = new business.library.thrift.ChatProject.Client(protocol);
}

From source file:ch.epfl.eagle.daemon.util.TClients.java

License:Apache License

public static NodeMonitorService.Client createBlockingNmClient(String host, int port, int timeout)
        throws IOException {
    TTransport tr = new TFramedTransport(new TSocket(host, port, timeout));
    try {//from   w ww. j a v  a  2 s. c  o m
        tr.open();
    } catch (TTransportException e) {
        LOG.warn("Error creating node monitor client to " + host + ":" + port);
        throw new IOException(e);
    }
    TProtocol proto = new TBinaryProtocol(tr);
    NodeMonitorService.Client client = new NodeMonitorService.Client(proto);
    return client;
}

From source file:ch.epfl.eagle.daemon.util.TClients.java

License:Apache License

public static SchedulerService.Client createBlockingSchedulerClient(String host, int port, int timeout)
        throws IOException {
    TTransport tr = new TFramedTransport(new TSocket(host, port, timeout));
    try {/*from   w  w w  .j  a v a  2  s .c o  m*/
        tr.open();
    } catch (TTransportException e) {
        LOG.warn("Error creating scheduler client to " + host + ":" + port);
        throw new IOException(e);
    }
    TProtocol proto = new TBinaryProtocol(tr);
    SchedulerService.Client client = new SchedulerService.Client(proto);
    return client;
}

From source file:ch.epfl.eagle.daemon.util.TClients.java

License:Apache License

public static GetTaskService.Client createBlockingGetTaskClient(String host, int port, int timeout)
        throws IOException {
    TTransport tr = new TFramedTransport(new TSocket(host, port, timeout));
    try {/*  ww  w.j  ava  2s. co m*/
        tr.open();
    } catch (TTransportException e) {
        LOG.warn("Error creating scheduler client to " + host + ":" + port);
        throw new IOException(e);
    }
    TProtocol proto = new TBinaryProtocol(tr);
    GetTaskService.Client client = new GetTaskService.Client(proto);
    return client;
}