com.hmsonline.trident.cql.incremental.CassandraCqlIncrementalStateFactory Maven / Gradle / Ivy
package com.hmsonline.trident.cql.incremental;
import java.util.Map;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import storm.trident.operation.CombinerAggregator;
import storm.trident.state.State;
import storm.trident.state.StateFactory;
import backtype.storm.task.IMetricsContext;
import com.hmsonline.trident.cql.CqlClientFactory;
import com.hmsonline.trident.cql.MapConfiguredCqlClientFactory;
@SuppressWarnings("rawtypes")
// TODO: Is it worth subclassing from CassandraCqlStateFactory?
public class CassandraCqlIncrementalStateFactory implements StateFactory {
private static final long serialVersionUID = 1L;
private static final Logger LOG = LoggerFactory.getLogger(CassandraCqlIncrementalStateFactory.class);
private CqlClientFactory clientFactory;
private CombinerAggregator aggregator;
private CqlIncrementMapper mapper;
public CassandraCqlIncrementalStateFactory(CombinerAggregator aggregator, CqlIncrementMapper mapper) {
this.aggregator = aggregator;
this.mapper = mapper;
}
protected void setCqlClientFactory(CqlClientFactory clientFactory){
this.clientFactory = clientFactory;
}
@SuppressWarnings("unchecked")
@Override
public State makeState(Map configuration, IMetricsContext metrics, int partitionIndex, int numPartitions) {
// NOTE: Lazy instantiation because Cluster is not serializable.
if (clientFactory == null) {
clientFactory = new MapConfiguredCqlClientFactory(configuration);
}
LOG.debug("Creating State for partition [{}] of [{}]", new Object[]{partitionIndex, numPartitions});
return new CassandraCqlIncrementalState(clientFactory, aggregator, mapper, partitionIndex);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy