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, int timeout) 

Source Link

Document

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

Usage

From source file:alluxio.network.thrift.ThriftUtils.java

License:Apache License

/**
 * Creates a new Thrift socket that will connect to the given address.
 *
 * @param address The given address to connect
 * @return An unconnected socket/*from   ww w  .ja v a  2s .  co  m*/
 */
public static TSocket createThriftSocket(InetSocketAddress address) {
    return new TSocket(address.getHostName(), address.getPort(), SOCKET_TIMEOUT_MS);
}

From source file:alluxio.security.authentication.AuthenticationUtils.java

License:Apache License

/**
 * Creates a new Thrift socket what will connect to the given address.
 *
 * @param address The given address to connect
 * @param timeoutMs the timeout in milliseconds
 * @return An unconnected socket/*ww w .  j a v a2  s. c om*/
 */
public static TSocket createTSocket(InetSocketAddress address, int timeoutMs) {
    return new TSocket(NetworkAddressUtils.getFqdnHost(address), address.getPort(), timeoutMs);
}

From source file:alluxio.security.authentication.TransportProviderUtils.java

License:Apache License

/**
 * Creates a new Thrift socket that will connect to the given address.
 *
 * @param address The given address to connect
 * @param timeoutMs the timeout in milliseconds
 * @return An unconnected socket/* w w  w  . j  a  v  a 2 s. co  m*/
 */
public static TSocket createThriftSocket(InetSocketAddress address, int timeoutMs) {
    return new TSocket(address.getHostName(), address.getPort(), timeoutMs);
}

From source file:andromache.hadoop.CassandraRecordReader.java

License:Apache License

public void initialize(InputSplit split, TaskAttemptContext context) throws IOException {
    this.context = context;
    this.split = (CassandraSplit) split;
    Configuration conf = context.getConfiguration();
    KeyRange jobRange = CassandraConfigHelper.getInputKeyRange(conf);
    filter = jobRange == null ? null : jobRange.row_filter;
    predicate = CassandraConfigHelper.getInputSlicePredicate(conf);
    boolean widerows = CassandraConfigHelper.getInputIsWide(conf);
    isEmptyPredicate = isEmptyPredicate(predicate);
    totalRowCount = CassandraConfigHelper.getInputSplitSize(conf);
    batchSize = CassandraConfigHelper.getRangeBatchSize(conf);
    cfName = ((CassandraSplit) split).getCf();
    consistencyLevel = CassandraConfigHelper.getReadConsistencyLevel(conf);

    keyspace = CassandraConfigHelper.getInputKeyspace(conf);

    try {//from   w ww  .  java  2 s.  co m
        // only need to connect once
        if (socket != null && socket.isOpen()) {
            return;
        }

        // create connection using thrift
        String location = getLocation();
        socket = new TSocket(location, CassandraConfigHelper.getInputRpcPort(conf), timemout);
        TTransport transport = CassandraConfigHelper.getInputTransportFactory(conf).openTransport(socket);
        TBinaryProtocol binaryProtocol = new TBinaryProtocol(transport);
        client = new Cassandra.Client(binaryProtocol);

        // log in
        client.set_keyspace(keyspace);
        if (CassandraConfigHelper.getInputKeyspaceUserName(conf) != null) {
            Map<String, String> creds = new HashMap<String, String>();
            creds.put(IAuthenticator.USERNAME_KEY, CassandraConfigHelper.getInputKeyspaceUserName(conf));
            creds.put(IAuthenticator.PASSWORD_KEY, CassandraConfigHelper.getInputKeyspacePassword(conf));
            AuthenticationRequest authRequest = new AuthenticationRequest(creds);
            client.login(authRequest);
        }
    } catch (Exception e) {
        throw new RuntimeException(e);
    }

    iter = widerows ? new WideRowIterator() : new StaticRowIterator();
    logger.debug("created {}", iter);
}

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 ww  w  .j  a  v  a  2 s  .  co 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  om
        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  .  ja va 2s .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);
    GetTaskService.Client client = new GetTaskService.Client(proto);
    return client;
}

From source file:co.cask.tephra.distributed.AbstractClientProvider.java

License:Apache License

protected TransactionServiceThriftClient newClient(int timeout) throws TException {
    initialize();/*from  w ww.  j a v  a2s  . c  o m*/
    String address;
    int port;

    if (endpointStrategy == null) {
        // if there is no discovery service, try to read host and port directly
        // from the configuration
        LOG.info("Reading address and port from configuration.");
        address = configuration.get(TxConstants.Service.CFG_DATA_TX_BIND_ADDRESS,
                TxConstants.Service.DEFAULT_DATA_TX_BIND_ADDRESS);
        port = configuration.getInt(TxConstants.Service.CFG_DATA_TX_BIND_PORT,
                TxConstants.Service.DEFAULT_DATA_TX_BIND_PORT);
        LOG.info("Service assumed at " + address + ":" + port);
    } else {
        Discoverable endpoint = endpointStrategy.pick();
        if (endpoint == null) {
            LOG.error("Unable to discover tx service.");
            throw new TException("Unable to discover tx service.");
        }
        address = endpoint.getSocketAddress().getHostName();
        port = endpoint.getSocketAddress().getPort();
        LOG.info("Service discovered at " + address + ":" + port);
    }

    // now we have an address and port, try to connect a client
    if (timeout < 0) {
        timeout = configuration.getInt(TxConstants.Service.CFG_DATA_TX_CLIENT_TIMEOUT,
                TxConstants.Service.DEFAULT_DATA_TX_CLIENT_TIMEOUT_MS);
    }
    LOG.info("Attempting to connect to tx service at " + address + ":" + port + " with timeout " + timeout
            + " ms.");
    // thrift transport layer
    TTransport transport = new TFramedTransport(new TSocket(address, port, timeout));
    try {
        transport.open();
    } catch (TTransportException e) {
        LOG.error("Unable to connect to tx service: " + e.getMessage());
        throw e;
    }
    // and create a thrift client
    TransactionServiceThriftClient newClient = new TransactionServiceThriftClient(transport);

    LOG.info("Connected to tx service at " + address + ":" + port);
    return newClient;
}

From source file:com.baifendian.swordfish.masterserver.exec.ExecutorClient.java

License:Apache License

private void connect() {
    tTransport = new TSocket(host, port, timeout);

    try {/*from   www .j a  v a 2s . c  o m*/
        TProtocol protocol = new TBinaryProtocol(tTransport);
        client = new WorkerService.Client(protocol);
        tTransport.open();
    } catch (TTransportException e) {
        logger.error("Catch an exception", e);
    }
}

From source file:com.baifendian.swordfish.rpc.client.MasterClient.java

License:Apache License

/**
 *  master/*from  w  w w.  ja  v a  2 s  . c o m*/
 *
 * @return ? true, ? false
 */
private boolean connect() {
    tTransport = new TSocket(host, port, CONNECTION_TIMEOUT);

    try {
        TProtocol protocol = new TBinaryProtocol(tTransport);

        client = new MasterService.Client(protocol);
        tTransport.open();
    } catch (TTransportException e) {
        logger.error("Connection server exception", e);
        return false;
    }

    return true;
}