first commit for new repo
[sdc/sdc-titan-cassandra.git] / src / main / java / com / thinkaurelius / titan / diskstorage / cassandra / thrift / thriftpool / CTConnection.java
1 package com.thinkaurelius.titan.diskstorage.cassandra.thrift.thriftpool;
2
3 import org.apache.cassandra.thrift.Cassandra;
4 import org.apache.cassandra.thrift.Cassandra.Client;
5 import org.apache.thrift.transport.TTransport;
6
7 import java.io.Closeable;
8
9 /**
10  * Wraps a {@code Cassandra.Client} instance, its underlying {@code TTransport}
11  * instance, and the {@link com.thinkaurelius.titan.diskstorage.cassandra.thrift.thriftpool.CTConnectionFactory.Config} instance used to setup
12  * the connection.
13  * 
14  * @see CTConnectionFactory
15  * @see CTConnectionPool
16  * @author Dan LaRocque <dalaro@hopcount.org>
17  */
18 public class CTConnection implements Closeable {
19     
20     private final TTransport transport;
21     private final Cassandra.Client client;
22     private final CTConnectionFactory.Config cfg;
23
24     public CTConnection(TTransport transport, Client client, CTConnectionFactory.Config cfg) {
25         this.transport = transport;
26         this.client = client;
27         this.cfg = cfg;
28     }
29
30     public TTransport getTransport() {
31         return transport;
32     }
33
34     public Cassandra.Client getClient() {
35         return client;
36     }
37     
38     public CTConnectionFactory.Config getConfig() {
39      return cfg;
40     }
41
42     public boolean isOpen() {
43         return transport.isOpen();
44     }
45     @Override
46     public void close() {
47         if (transport != null && transport.isOpen())
48             transport.close();
49     }
50
51     @Override
52     public String toString() {
53         return "CTConnection [transport=" + transport + ", client=" + client + ", cfg=" + cfg + "]";
54     }
55 }