You can look at
http://github.com/rantav/hector/blob/master/src/main/java/me/prettyprint/cassandra/service/CassandraClientFactory.java
so, to close the client you can just get the transport out of the client
(bold):
private void closeClient(CassandraClient cclient) {
log.debug("Closing client {}", cclient);
((CassandraClientPoolImpl) pool).reportDestroyed(cclient);
Cassandra.Client client = cclient.getCassandra();
* client.getInputProtocol().getTransport().close();*
* client.getOutputProtocol().getTransport().close();*
cclient.markAsClosed();
}
But to create a client you need a transport (bold):
private Cassandra.Client createThriftClient(String url, int port)
throws TTransportException , TException {
log.debug("Creating a new thrift connection to {}:{}", url, port);
TTransport tr;
if (useThriftFramedTransport) {
tr = new TFramedTransport(new TSocket(url, port, timeout));
} else {
tr = new TSocket(url, port, timeout);
}
TProtocol proto = new TBinaryProtocol(tr);
* Cassandra.Client client = new Cassandra.Client(proto);*
try {
tr.open();
} catch (TTransportException e) {
// Thrift exceptions aren't very good in reporting, so we have to
catch the exception here and
// add details to it.
log.error("Unable to open transport to " + url + ":" + port, e);
clientMonitor.incCounter(Counter.CONNECT_ERROR);
throw new TTransportException("Unable to open transport to " + url +
":" + port + " , " +
e.getLocalizedMessage(), e);
}
return client;
}
So what you can do is instead of passing a client to the method, pass a URL
to the method. The method would open the transport, create a client, make
some cassandra operations and then close the transport.
On Wed, Jun 9, 2010 at 10:35 PM, Steven Haar <[email protected]>wrote:
> C#
>
>
> On Wed, Jun 9, 2010 at 2:34 PM, Ran Tavory <[email protected]> wrote:
>
>> Some languages have higher level clients that might help you. What
>> language are you using?
>>
>> On Jun 9, 2010 9:01 PM, "Steven Haar" <[email protected]> wrote:
>>
>> What is the best way to pass a Cassandra client as a parameter? If you
>> pass it as a parameter, do you also have to pass the transport in order to
>> be able to close the connection? Is there any way to open or close the
>> transport direclty from the client?
>>
>> Essentailly what I want to do is pass a Cassandra client to a method and
>> then within that method be able to open the transport, execute a get or set
>> to the Cassandra database, and then close the transport all witihin the
>> method. The only way I see to do this is to also pass the transport to the
>> method.
>>
>>
>