Search in sources :

Example 1 with CassandraSessionHolder

use of org.apache.camel.utils.cassandra.CassandraSessionHolder in project camel by apache.

the class CassandraEndpoint method doStart.

@Override
protected void doStart() throws Exception {
    super.doStart();
    if (cluster == null && beanRef != null) {
        Object bean = CamelContextHelper.mandatoryLookup(getCamelContext(), beanRef);
        if (bean instanceof Session) {
            session = (Session) bean;
            cluster = session.getCluster();
            keyspace = session.getLoggedKeyspace();
        } else if (bean instanceof Cluster) {
            cluster = (Cluster) bean;
            session = null;
        } else {
            throw new IllegalArgumentException("CQL Bean type should be of type Session or Cluster but was " + bean);
        }
    }
    if (cluster == null && hosts != null) {
        // use the cluster builder to create the cluster
        cluster = createClusterBuilder().build();
    }
    if (cluster != null) {
        sessionHolder = new CassandraSessionHolder(cluster, keyspace);
    } else {
        sessionHolder = new CassandraSessionHolder(session);
    }
    sessionHolder.start();
}
Also used : CassandraSessionHolder(org.apache.camel.utils.cassandra.CassandraSessionHolder) Cluster(com.datastax.driver.core.Cluster) Session(com.datastax.driver.core.Session)

Aggregations

Cluster (com.datastax.driver.core.Cluster)1 Session (com.datastax.driver.core.Session)1 CassandraSessionHolder (org.apache.camel.utils.cassandra.CassandraSessionHolder)1