Java Code Examples for org.apache.thrift.transport.TTransport#isOpen()

The following examples show how to use org.apache.thrift.transport.TTransport#isOpen() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Transport.java    From presto with Apache License 2.0 6 votes vote down vote up
public static TTransport create(
        HostAndPort address,
        Optional<SSLContext> sslContext,
        Optional<HostAndPort> socksProxy,
        int timeoutMillis,
        HiveMetastoreAuthentication authentication,
        Optional<String> delegationToken)
        throws TTransportException
{
    requireNonNull(address, "address is null");
    try {
        TTransport rawTransport = createRaw(address, sslContext, socksProxy, timeoutMillis);
        TTransport authenticatedTransport = authentication.authenticate(rawTransport, address.getHost(), delegationToken);
        if (!authenticatedTransport.isOpen()) {
            authenticatedTransport.open();
        }
        return new TTransportWrapper(authenticatedTransport, address);
    }
    catch (TTransportException e) {
        throw rewriteException(e, address);
    }
}
 
Example 2
Source File: Bmv2PreControllerImpl.java    From onos with Apache License 2.0 6 votes vote down vote up
@Override
public void removePreClient(DeviceId deviceId) {
    if (!acquireWriteLock(deviceId)) {
        //reason is already logged during the lock acquisition
        return;
    }

    try {
        if (clients.containsKey(deviceId)) {
            TTransport transport = clients.get(deviceId).getLeft();
            if (transport.isOpen()) {
                transport.close();
            }
            clients.remove(deviceId);
        }
    } finally {
        releaseWriteLock(deviceId);
    }
}
 
Example 3
Source File: ServiceClientImpl.java    From ikasoa with MIT License 5 votes vote down vote up
@Override
public String get(String arg) throws IkasoaException {
	TTransport transport = oprot_.getTransport();
	try {
		if (!transport.isOpen())
			transport.open();
		log.debug("Transport is open .");
		sendGet(arg);
		return recvGet();
	} catch (TException e) {
		transport.close();
		log.debug("Transport is close .");
		throw new IkasoaException("Execute failed !", e);
	}
}
 
Example 4
Source File: ConsumerPoolFactory.java    From ourea with Apache License 2.0 5 votes vote down vote up
@Override
public void destroyObject(PooledObject<TTransport> p) throws Exception {

    try {
        TTransport transport = p.getObject();
        if (transport.isOpen()) {
            transport.close();
        }
    } catch (Exception e) {
        LOGGER.error("destroy transport object fail.maybe exist memory leek.e:", e);
        throw new OureaException("destroy transport object fail" + e.getMessage());
    }

}
 
Example 5
Source File: DefaultThriftConnectionPoolImpl.java    From thrift-pool-client with Artistic License 2.0 5 votes vote down vote up
@Override
public void destroyObject(ThriftServerInfo info, PooledObject<TTransport> p) {
    TTransport transport = p.getObject();
    if (transport != null && transport.isOpen()) {
        transport.close();
        logger.trace("close thrift connection:{}", info);
    }
}
 
Example 6
Source File: CqlRecordWriter.java    From stratio-cassandra with Apache License 2.0 5 votes vote down vote up
CqlRecordWriter(Configuration conf)
{
    super(conf);
    this.clients = new HashMap<>();

    try
    {
        Cassandra.Client client = ConfigHelper.getClientFromOutputAddressList(conf);
        if (client != null)
        {
            client.set_keyspace(ConfigHelper.getOutputKeyspace(conf));
            String user = ConfigHelper.getOutputKeyspaceUserName(conf);
            String password = ConfigHelper.getOutputKeyspacePassword(conf);
            if ((user != null) && (password != null))
                AbstractColumnFamilyOutputFormat.login(user, password, client);
            retrievePartitionKeyValidator(client);
            String cqlQuery = CqlConfigHelper.getOutputCql(conf).trim();
            if (cqlQuery.toLowerCase().startsWith("insert"))
                throw new UnsupportedOperationException("INSERT with CqlRecordWriter is not supported, please use UPDATE/DELETE statement");
            cql = appendKeyWhereClauses(cqlQuery);

            TTransport transport = client.getOutputProtocol().getTransport();
            if (transport.isOpen())
                transport.close();
        }
        else
        {
            throw new IllegalArgumentException("Invalid configuration specified " + conf);
        }
    }
    catch (Exception e)
    {
        throw new RuntimeException(e);
    }
}
 
Example 7
Source File: ColumnFamilyRecordReader.java    From stratio-cassandra with Apache License 2.0 5 votes vote down vote up
public void close()
{
    if (client != null)
    {
        TTransport transport = client.getOutputProtocol().getTransport();
        if (transport.isOpen())
            transport.close();
    }
}
 
Example 8
Source File: AbstractColumnFamilyRecordWriter.java    From stratio-cassandra with Apache License 2.0 5 votes vote down vote up
protected void closeInternal()
{
    if (client != null)
    {
        TTransport transport = client.getOutputProtocol().getTransport();
        if (transport.isOpen())
            transport.close();
    }
}