try
{
String hosts = getProperties().getProperty("hosts");
if (hosts == null)
{
throw new DBException("Required property \"hosts\" missing for CassandraClient");
}
column_family = getProperties().getProperty(COLUMN_FAMILY_PROPERTY);
parent = new ColumnParent(column_family);
_table = getProperties().getProperty("schema");
ConnectionRetries = Integer.parseInt(getProperties().getProperty(CONNECTION_RETRY_PROPERTY,
CONNECTION_RETRY_PROPERTY_DEFAULT));
String username = getProperties().getProperty(USERNAME_PROPERTY);
String password = getProperties().getProperty(PASSWORD_PROPERTY);
readConsistencyLevel = ConsistencyLevel.valueOf(getProperties().getProperty(
READ_CONSISTENCY_LEVEL_PROPERTY, READ_CONSISTENCY_LEVEL_PROPERTY_DEFAULT));
writeConsistencyLevel = ConsistencyLevel.valueOf(getProperties().getProperty(
WRITE_CONSISTENCY_LEVEL_PROPERTY, WRITE_CONSISTENCY_LEVEL_PROPERTY_DEFAULT));
scanConsistencyLevel = ConsistencyLevel.valueOf(getProperties().getProperty(
SCAN_CONSISTENCY_LEVEL_PROPERTY, SCAN_CONSISTENCY_LEVEL_PROPERTY_DEFAULT));
deleteConsistencyLevel = ConsistencyLevel.valueOf(getProperties().getProperty(
DELETE_CONSISTENCY_LEVEL_PROPERTY, DELETE_CONSISTENCY_LEVEL_PROPERTY_DEFAULT));
_debug = Boolean.parseBoolean(getProperties().getProperty("debug", "false"));
String[] allhosts = hosts.split(",");
String myhost = allhosts[random.nextInt(allhosts.length)];
Exception connectexception = null;
// System.out.println("Initiating connection");
if (tr == null || client == null)
{
for (int retry = 0; retry < ConnectionRetries; retry++)
{
tr = new TFramedTransport(new TSocket(myhost, 9160));
TProtocol proto = new TBinaryProtocol(tr);
// System.out.println("creating connection::");
client = new Cassandra.Client(proto);
try
{
tr.open();
connectexception = null;
break;
}
catch (Exception e)
{
connectexception = e;
logger.error(e);
}
try
{
Thread.sleep(1000);
}
catch (InterruptedException e)
{
logger.error(e);
}
}
}
if (connectexception != null)
{
logger.info("Unable to connect to " + myhost + " after " + ConnectionRetries + " tries");
throw new DBException(connectexception);
}
if (username != null && password != null)
{
Map<String, String> cred = new HashMap<String, String>();
cred.put("username", username);
cred.put("password", password);
AuthenticationRequest req = new AuthenticationRequest(cred);
try
{
client.login(req);
}
catch (Exception e)
{
e.printStackTrace();
logger.info(e);
throw new DBException(e);
}
}
client.set_keyspace(_table);
}
catch (Exception e)