-
Notifications
You must be signed in to change notification settings - Fork 300
JNDI
Introduction
These general notes apply to the installation and configuration of the Hector API into the Apache Tomcat application server. The instructions should be compatible with most J2EE application servers.
Any specific exceptions are noted in the sections dedicated to each Application Server.
Note: General instructions about Tomcat JNDI configuration can be found here.
Define a CassandraHostConfigurator entry within the Tomcat application server-wide $CATALINA_BASE/conf/server.xml
or within the per-web-application context XML file (META-INF/context.xml
).
Within a web application, either in a servlet (servlet init() method) or possibly a REST-based resource class, the Cassandra client pool would be defined in this manner:
Context initCtx = new InitialContext();
Context envCtx = (Context) initCtx.lookup(“java:comp/env”);
CassandraHostConfigurator hostConfigurator = (CassandraHostConfigurator) envCtx.lookup(“cassandra/CassandraHostConfigurator”);
CassandraClientPool clientPool = CassandraClientPoolFactory.getInstance().createNew(hostConfigurator);
From there, the Cassandra client pool is treated like any other poolable collection.
public String getFoo() {
String response = null;
CassandraClient cassandraClient = null;
try {
cassandraClient = clientPool.borrowClient();
//do some stuff …….
//stick the data in the response string …
}
catch (Exception exception) {
logger.error(exception);
}
finally {
try {
clientPool.releaseClient(cassandraClient);
}
catch (Exception exception) {
logger.error(exception);
}
}
return response;
}
Perry Hoekstra