Return-Path: Delivered-To: apmail-cassandra-user-archive@www.apache.org Received: (qmail 30491 invoked from network); 10 Jun 2010 07:11:06 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 10 Jun 2010 07:11:06 -0000 Received: (qmail 13702 invoked by uid 500); 10 Jun 2010 07:11:05 -0000 Delivered-To: apmail-cassandra-user-archive@cassandra.apache.org Received: (qmail 13499 invoked by uid 500); 10 Jun 2010 07:11:02 -0000 Mailing-List: contact user-help@cassandra.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: user@cassandra.apache.org Delivered-To: mailing list user@cassandra.apache.org Received: (qmail 13490 invoked by uid 99); 10 Jun 2010 07:11:01 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 10 Jun 2010 07:11:01 +0000 X-ASF-Spam-Status: No, hits=2.2 required=10.0 tests=FREEMAIL_FROM,HTML_MESSAGE,SPF_PASS,T_TO_NO_BRKTS_FREEMAIL X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: domain of rantav@gmail.com designates 209.85.214.172 as permitted sender) Received: from [209.85.214.172] (HELO mail-iw0-f172.google.com) (209.85.214.172) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 10 Jun 2010 07:10:55 +0000 Received: by iwn42 with SMTP id 42so6691719iwn.31 for ; Thu, 10 Jun 2010 00:10:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:mime-version:received:in-reply-to :references:from:date:message-id:subject:to:content-type; bh=inpAdohpCYqKt+ijqx+jFEQuC7ONvLKCknP4cGQcQdk=; b=XkXWPbZwKcKLRIKEoYkp/gLaM6SS6UHFLBVIKQH4RZrGbqRMVVqYIXF6MVOUWDKBH9 BRum68XzF7+BeeDKzWOV+5xU/ml+dvHzom8FoadLya3WwgGVSCWjO3WPwB1ubr8Pc/2J 3ltY+qPh4AjIp5z0gWQaTbQq1a+dpKsF3VItU= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type; b=EJIMFjK2HDbkjX+4asTA+PJyZqJHn+9h44g0kNBPgCCUwqX0hUjDmgXDypzY8YXKfk hPyX8ot53/VFUC8ONTRkx2So1fKaEFVKnBVJFw1b3myKZfEiHtgmIcGuC8we+8p4ZffJ ChhTwnqj+F0OkIpC8Ex2d7jepS3l93f8/BFMI= Received: by 10.231.156.66 with SMTP id v2mr9029460ibw.107.1276153834172; Thu, 10 Jun 2010 00:10:34 -0700 (PDT) MIME-Version: 1.0 Received: by 10.231.171.10 with HTTP; Thu, 10 Jun 2010 00:10:14 -0700 (PDT) In-Reply-To: References: From: Ran Tavory Date: Thu, 10 Jun 2010 10:10:14 +0300 Message-ID: Subject: Re: Passing client as parameter To: user@cassandra.apache.org Content-Type: multipart/alternative; boundary=001636ed77e9f6f1a20488a7b747 X-Virus-Checked: Checked by ClamAV on apache.org --001636ed77e9f6f1a20488a7b747 Content-Type: text/plain; charset=UTF-8 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 wrote: > C# > > > On Wed, Jun 9, 2010 at 2:34 PM, Ran Tavory 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" 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. >> >> > --001636ed77e9f6f1a20488a7b747 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
You can look at=C2=A0http://github.com/rantav/hector/blob/master/src/main/jav= a/me/prettyprint/cassandra/service/CassandraClientFactory.java

so, to close the client you can just get the transport out of the = client (bold):

=C2=A0=C2=A0private void closeClient= (CassandraClient cclient) {
=C2=A0=C2=A0 =C2=A0log.debug("Cl= osing client {}", cclient);
=C2=A0=C2=A0 =C2=A0((CassandraClientPoolImpl) pool).reportDestroyed(cc= lient);
=C2=A0=C2=A0 =C2=A0Cassandra.Client client =3D cclient.ge= tCassandra();
=C2=A0=C2=A0 =C2=A0client.getInputProtocol().get= Transport().close();
=C2=A0=C2=A0 =C2=A0client.getOutputPr= otocol().getTransport().close();
=C2=A0=C2=A0 =C2=A0cclient.markAsClosed();
=C2=A0=C2=A0}

But to create a client you need a transport (bold):

=C2=A0=C2=A0private Cassandra.Client createThr= iftClient(String =C2=A0url, int port)
=C2=A0=C2=A0 =C2=A0 =C2=A0throws TTransportException , TException {
=C2=A0=C2=A0 =C2=A0log.debug("Creating a new thrift connection= to {}:{}", url, port);
=C2=A0=C2=A0 =C2=A0TTransport tr;
=C2=A0=C2=A0 =C2=A0if (useThriftFramedTransport) {
=C2=A0=C2=A0 =C2=A0 =C2=A0tr =3D new TFramedTransport(new TSocket(url,= port, timeout));
=C2=A0=C2=A0 =C2=A0} else {
=C2=A0=C2= =A0 =C2=A0 =C2=A0tr =3D new TSocket(url, port, timeout);
=C2=A0= =C2=A0 =C2=A0}
=C2=A0=C2=A0 =C2=A0TProtocol proto =3D new TBinary= Protocol(tr);
=C2=A0=C2=A0 =C2=A0Cassandra.Client client =3D new Cassandra.Client= (proto);
=C2=A0=C2=A0 =C2=A0try {
=C2=A0=C2=A0 =C2= =A0 =C2=A0tr.open();
=C2=A0=C2=A0 =C2=A0} catch (TTransportExcept= ion e) {
=C2=A0=C2=A0 =C2=A0 =C2=A0// Thrift exceptions aren'= t very good in reporting, so we have to catch the exception here and
=C2=A0=C2=A0 =C2=A0 =C2=A0// add details to it.
=C2=A0=C2=A0= =C2=A0 =C2=A0log.error("Unable to open transport to " + url + &q= uot;:" + port, e);
=C2=A0=C2=A0 =C2=A0 =C2=A0clientMonitor.i= ncCounter(Counter.CONNECT_ERROR);
=C2=A0=C2=A0 =C2=A0 =C2=A0throw= new TTransportException("Unable to open transport to " + url + &= quot;:" + port + " , " +
=C2=A0=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0e.getLocalizedMessage(), e);
=C2=A0=C2=A0 =C2=A0}
=C2=A0=C2=A0 =C2=A0return client;
=C2=A0=C2=A0}


So wha= t you can do is instead of passing a client to the method, pass a URL to th= e method. The method would open the transport, create a client, make some c= assandra operations and then close the transport.=C2=A0

On Wed, Jun 9, 2010 at 10:35 PM, Steven Haar= <shaar@v= intagesoftware.com> wrote:
C#


On Wed, Jun 9, 2010 at 2:34 PM, Ran Tavory <rant= av@gmail.com> wrote:

Some languages have higher level clients that might help you. What langu= age are you using?

On Jun 9, 2010 9:01 PM, "Steven Haar&quo= t; <shaar= @vintagesoftware.com> 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 tra= nsport direclty from the client?
=C2=A0
Essentailly what I want to do is pass a Cassandra client to a method a= nd 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.



--001636ed77e9f6f1a20488a7b747--