use of co.cask.cdap.data.stream.StreamPropertyListener in project cdap by caskdata.
the class LocalStreamService method createSizeAggregator.
/**
* Create a new aggregator for the {@code streamId}, and add it to the existing map of {@link Cancellable}
* {@code aggregators}. This method does not cancel previously existing aggregator associated to the
* {@code streamId}.
*
* @param streamId stream name to create a new aggregator for
* @param baseCount stream size from which to start aggregating
* @param threshold notification threshold after which to publish a notification - in MB
* @return the created {@link StreamSizeAggregator}
*/
private StreamSizeAggregator createSizeAggregator(StreamId streamId, long baseCount, int threshold) {
// Handle threshold changes
final Cancellable thresholdSubscription = getStreamCoordinatorClient().addListener(streamId, new StreamPropertyListener() {
@Override
public void thresholdChanged(StreamId streamId, int threshold) {
StreamSizeAggregator aggregator = aggregators.get(streamId);
while (aggregator == null) {
Thread.yield();
aggregator = aggregators.get(streamId);
}
aggregator.setStreamThresholdMB(threshold);
}
});
StreamSizeAggregator newAggregator = new StreamSizeAggregator(streamId, baseCount, threshold, thresholdSubscription);
aggregators.put(streamId, newAggregator);
return newAggregator;
}
use of co.cask.cdap.data.stream.StreamPropertyListener in project cdap by caskdata.
the class DistributedStreamService method createSizeAggregator.
/**
* Create a new aggregator for the {@code streamId}, and add it to the existing map of {@link Cancellable}
* {@code aggregators}. This method does not cancel previously existing aggregator associated to the
* {@code streamId}.
*
* @param streamId stream Id to create a new aggregator for
* @param baseCount stream size from which to start aggregating
* @param threshold notification threshold after which to publish a notification - in MB
* @return the created {@link StreamSizeAggregator}
*/
private StreamSizeAggregator createSizeAggregator(StreamId streamId, long baseCount, int threshold) {
LOG.debug("Creating size aggregator for stream {} with baseCount {} and threshold {}", streamId, baseCount, threshold);
// Handle threshold changes
final Cancellable thresholdSubscription = getStreamCoordinatorClient().addListener(streamId, new StreamPropertyListener() {
@Override
public void thresholdChanged(StreamId streamId, int threshold) {
StreamSizeAggregator aggregator = aggregators.get(streamId);
while (aggregator == null) {
Thread.yield();
aggregator = aggregators.get(streamId);
}
aggregator.setStreamThresholdMB(threshold);
}
});
StreamSizeAggregator newAggregator = new StreamSizeAggregator(streamId, baseCount, threshold, thresholdSubscription);
newAggregator.init();
aggregators.put(streamId, newAggregator);
return newAggregator;
}
Aggregations