use of org.thingsboard.server.dao.sql.TbSqlBlockingQueueWrapper in project thingsboard by thingsboard.
the class JpaAttributeDao method init.
@PostConstruct
private void init() {
TbSqlBlockingQueueParams params = TbSqlBlockingQueueParams.builder().logName("Attributes").batchSize(batchSize).maxDelay(maxDelay).statsPrintIntervalMs(statsPrintIntervalMs).statsNamePrefix("attributes").batchSortEnabled(batchSortEnabled).build();
Function<AttributeKvEntity, Integer> hashcodeFunction = entity -> entity.getId().getEntityId().hashCode();
queue = new TbSqlBlockingQueueWrapper<>(params, hashcodeFunction, batchThreads, statsFactory);
queue.init(logExecutor, v -> attributeKvInsertRepository.saveOrUpdate(v), Comparator.comparing((AttributeKvEntity attributeKvEntity) -> attributeKvEntity.getId().getEntityId()).thenComparing(attributeKvEntity -> attributeKvEntity.getId().getEntityType().name()).thenComparing(attributeKvEntity -> attributeKvEntity.getId().getAttributeType()).thenComparing(attributeKvEntity -> attributeKvEntity.getId().getAttributeKey()));
}
use of org.thingsboard.server.dao.sql.TbSqlBlockingQueueWrapper in project thingsboard by thingsboard.
the class JpaBaseEventDao method init.
@PostConstruct
private void init() {
TbSqlBlockingQueueParams params = TbSqlBlockingQueueParams.builder().logName("Events").batchSize(batchSize).maxDelay(maxDelay).statsPrintIntervalMs(statsPrintIntervalMs).statsNamePrefix("events").batchSortEnabled(batchSortEnabled).build();
Function<EventEntity, Integer> hashcodeFunction = entity -> entity.getEntityId().hashCode();
queue = new TbSqlBlockingQueueWrapper<>(params, hashcodeFunction, batchThreads, statsFactory);
queue.init(logExecutor, v -> eventInsertRepository.save(v), Comparator.comparing((EventEntity eventEntity) -> eventEntity.getTs()));
}
use of org.thingsboard.server.dao.sql.TbSqlBlockingQueueWrapper in project thingsboard by thingsboard.
the class TimescaleTimeseriesDao method init.
@PostConstruct
protected void init() {
TbSqlBlockingQueueParams tsParams = TbSqlBlockingQueueParams.builder().logName("TS Timescale").batchSize(tsBatchSize).maxDelay(tsMaxDelay).statsPrintIntervalMs(tsStatsPrintIntervalMs).statsNamePrefix("ts.timescale").batchSortEnabled(batchSortEnabled).build();
Function<TimescaleTsKvEntity, Integer> hashcodeFunction = entity -> entity.getEntityId().hashCode();
tsQueue = new TbSqlBlockingQueueWrapper<>(tsParams, hashcodeFunction, timescaleBatchThreads, statsFactory);
tsQueue.init(logExecutor, v -> insertRepository.saveOrUpdate(v), Comparator.comparing((Function<TimescaleTsKvEntity, UUID>) AbstractTsKvEntity::getEntityId).thenComparing(AbstractTsKvEntity::getKey).thenComparing(AbstractTsKvEntity::getTs));
}
use of org.thingsboard.server.dao.sql.TbSqlBlockingQueueWrapper in project thingsboard by thingsboard.
the class SqlTimeseriesLatestDao method init.
@PostConstruct
protected void init() {
TbSqlBlockingQueueParams tsLatestParams = TbSqlBlockingQueueParams.builder().logName("TS Latest").batchSize(tsLatestBatchSize).maxDelay(tsLatestMaxDelay).statsPrintIntervalMs(tsLatestStatsPrintIntervalMs).statsNamePrefix("ts.latest").batchSortEnabled(false).build();
java.util.function.Function<TsKvLatestEntity, Integer> hashcodeFunction = entity -> entity.getEntityId().hashCode();
tsLatestQueue = new TbSqlBlockingQueueWrapper<>(tsLatestParams, hashcodeFunction, tsLatestBatchThreads, statsFactory);
tsLatestQueue.init(logExecutor, v -> {
Map<TsKey, TsKvLatestEntity> trueLatest = new HashMap<>();
v.forEach(ts -> {
TsKey key = new TsKey(ts.getEntityId(), ts.getKey());
trueLatest.merge(key, ts, (oldTs, newTs) -> oldTs.getTs() <= newTs.getTs() ? newTs : oldTs);
});
List<TsKvLatestEntity> latestEntities = new ArrayList<>(trueLatest.values());
if (batchSortEnabled) {
latestEntities.sort(Comparator.comparing((Function<TsKvLatestEntity, UUID>) AbstractTsKvEntity::getEntityId).thenComparingInt(AbstractTsKvEntity::getKey));
}
insertLatestTsRepository.saveOrUpdate(latestEntities);
}, (l, r) -> 0);
}
use of org.thingsboard.server.dao.sql.TbSqlBlockingQueueWrapper in project thingsboard by thingsboard.
the class AbstractChunkedAggregationTimeseriesDao method init.
@PostConstruct
protected void init() {
TbSqlBlockingQueueParams tsParams = TbSqlBlockingQueueParams.builder().logName("TS").batchSize(tsBatchSize).maxDelay(tsMaxDelay).statsPrintIntervalMs(tsStatsPrintIntervalMs).statsNamePrefix("ts").batchSortEnabled(batchSortEnabled).build();
Function<TsKvEntity, Integer> hashcodeFunction = entity -> entity.getEntityId().hashCode();
tsQueue = new TbSqlBlockingQueueWrapper<>(tsParams, hashcodeFunction, tsBatchThreads, statsFactory);
tsQueue.init(logExecutor, v -> insertRepository.saveOrUpdate(v), Comparator.comparing((Function<TsKvEntity, UUID>) AbstractTsKvEntity::getEntityId).thenComparing(AbstractTsKvEntity::getKey).thenComparing(AbstractTsKvEntity::getTs));
}
Aggregations