Search in sources :

Example 1 with Configuration

use of com.hmsonline.cassandra.index.Configuration in project cassandra-indexing by hmsonline.

the class ConfigurationDao method updateConfiguration.

public synchronized void updateConfiguration() {
    long currentTime = System.currentTimeMillis();
    long timeSinceRefresh = currentTime - ConfigurationDao.lastFetchTime;
    if (config == null || config.isEmpty() || timeSinceRefresh > REFRESH_INTERVAL) {
        logger.debug("Refreshing indexing configuration.");
        Configuration configuration = loadConfiguration();
        config = configuration;
    }
    ConfigurationDao.lastFetchTime = currentTime;
}
Also used : Configuration(com.hmsonline.cassandra.index.Configuration)

Example 2 with Configuration

use of com.hmsonline.cassandra.index.Configuration in project cassandra-indexing by hmsonline.

the class ConfigurationDao method loadConfiguration.

private Configuration loadConfiguration() {
    try {
        Configuration config = new Configuration();
        RangeSlicesQuery<String, String, String> rangeSlicesQuery = HFactory.createRangeSlicesQuery(this.getKeyspace(), StringSerializer.get(), StringSerializer.get(), StringSerializer.get());
        rangeSlicesQuery.setColumnFamily(COLUMN_FAMILY);
        rangeSlicesQuery.setKeys("", "");
        // MAX_COLUMNS
        rangeSlicesQuery.setRange("", "", false, 2000);
        // MAX_ROWS
        rangeSlicesQuery.setRowCount(2000);
        QueryResult<OrderedRows<String, String, String>> result = rangeSlicesQuery.execute();
        OrderedRows<String, String, String> orderedRows = result.get();
        for (Row<String, String, String> r : orderedRows) {
            ColumnSlice<String, String> slice = r.getColumnSlice();
            String indexName = r.getKey();
            Map<String, String> indexProperties = new HashMap<String, String>();
            for (HColumn<String, String> column : slice.getColumns()) {
                if (logger.isDebugEnabled()) {
                    logger.debug("got " + COLUMN_FAMILY + "['" + r.getKey() + "']" + "['" + column.getName() + "'] = '" + column.getValue() + "';");
                }
                indexProperties.put(column.getName(), column.getValue());
            }
            config.addIndex(indexName, indexProperties);
        }
        return config;
    } catch (Exception ex) {
        throw new RuntimeException("Failed to load indexing configuration: " + KEYSPACE + ":" + COLUMN_FAMILY, ex);
    }
}
Also used : Configuration(com.hmsonline.cassandra.index.Configuration) HashMap(java.util.HashMap) OrderedRows(me.prettyprint.hector.api.beans.OrderedRows)

Aggregations

Configuration (com.hmsonline.cassandra.index.Configuration)2 HashMap (java.util.HashMap)1 OrderedRows (me.prettyprint.hector.api.beans.OrderedRows)1