Search in sources :

Example 1 with TbSqlBlockingQueueParams

use of org.thingsboard.server.dao.sql.TbSqlBlockingQueueParams 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()));
}
Also used : AttributeKvCompositeKey(org.thingsboard.server.dao.model.sql.AttributeKvCompositeKey) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) TbSqlBlockingQueueWrapper(org.thingsboard.server.dao.sql.TbSqlBlockingQueueWrapper) Autowired(org.springframework.beans.factory.annotation.Autowired) DeviceProfileId(org.thingsboard.server.common.data.id.DeviceProfileId) ScheduledLogExecutorComponent(org.thingsboard.server.dao.sql.ScheduledLogExecutorComponent) StatsFactory(org.thingsboard.server.common.stats.StatsFactory) Function(java.util.function.Function) TenantId(org.thingsboard.server.common.data.id.TenantId) Value(org.springframework.beans.factory.annotation.Value) AttributeKvEntry(org.thingsboard.server.common.data.kv.AttributeKvEntry) PreDestroy(javax.annotation.PreDestroy) Lists(com.google.common.collect.Lists) TbSqlBlockingQueueParams(org.thingsboard.server.dao.sql.TbSqlBlockingQueueParams) EntityId(org.thingsboard.server.common.data.id.EntityId) EntityType(org.thingsboard.server.common.data.EntityType) JpaAbstractDaoListeningExecutorService(org.thingsboard.server.dao.sql.JpaAbstractDaoListeningExecutorService) Collection(java.util.Collection) Collectors(java.util.stream.Collectors) AttributesDao(org.thingsboard.server.dao.attributes.AttributesDao) Futures(com.google.common.util.concurrent.Futures) Slf4j(lombok.extern.slf4j.Slf4j) Component(org.springframework.stereotype.Component) List(java.util.List) AttributeKvEntity(org.thingsboard.server.dao.model.sql.AttributeKvEntity) PostConstruct(javax.annotation.PostConstruct) DaoUtil(org.thingsboard.server.dao.DaoUtil) Optional(java.util.Optional) Comparator(java.util.Comparator) AttributeKvEntity(org.thingsboard.server.dao.model.sql.AttributeKvEntity) TbSqlBlockingQueueParams(org.thingsboard.server.dao.sql.TbSqlBlockingQueueParams) PostConstruct(javax.annotation.PostConstruct)

Example 2 with TbSqlBlockingQueueParams

use of org.thingsboard.server.dao.sql.TbSqlBlockingQueueParams 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()));
}
Also used : Event(org.thingsboard.server.common.data.Event) JpaAbstractDao(org.thingsboard.server.dao.sql.JpaAbstractDao) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) EventEntity(org.thingsboard.server.dao.model.sql.EventEntity) TimePageLink(org.thingsboard.server.common.data.page.TimePageLink) StatisticsEventFilter(org.thingsboard.server.common.data.event.StatisticsEventFilter) TbSqlBlockingQueueWrapper(org.thingsboard.server.dao.sql.TbSqlBlockingQueueWrapper) Autowired(org.springframework.beans.factory.annotation.Autowired) ErrorEventFilter(org.thingsboard.server.common.data.event.ErrorEventFilter) ScheduledLogExecutorComponent(org.thingsboard.server.dao.sql.ScheduledLogExecutorComponent) CrudRepository(org.springframework.data.repository.CrudRepository) EventId(org.thingsboard.server.common.data.id.EventId) StatsFactory(org.thingsboard.server.common.stats.StatsFactory) StringUtils(org.apache.commons.lang3.StringUtils) Function(java.util.function.Function) TenantId(org.thingsboard.server.common.data.id.TenantId) Value(org.springframework.beans.factory.annotation.Value) LifeCycleEventFilter(org.thingsboard.server.common.data.event.LifeCycleEventFilter) EventFilter(org.thingsboard.server.common.data.event.EventFilter) PreDestroy(javax.annotation.PreDestroy) TbSqlBlockingQueueParams(org.thingsboard.server.dao.sql.TbSqlBlockingQueueParams) Uuids(com.datastax.oss.driver.api.core.uuid.Uuids) EventDao(org.thingsboard.server.dao.event.EventDao) EntityId(org.thingsboard.server.common.data.id.EntityId) NULL_UUID(org.thingsboard.server.dao.model.ModelConstants.NULL_UUID) PageRequest(org.springframework.data.domain.PageRequest) UUID(java.util.UUID) DebugEvent(org.thingsboard.server.common.data.event.DebugEvent) Objects(java.util.Objects) Slf4j(lombok.extern.slf4j.Slf4j) Component(org.springframework.stereotype.Component) List(java.util.List) AttributeKvEntity(org.thingsboard.server.dao.model.sql.AttributeKvEntity) PageData(org.thingsboard.server.common.data.page.PageData) PostConstruct(javax.annotation.PostConstruct) DaoUtil(org.thingsboard.server.dao.DaoUtil) Optional(java.util.Optional) Comparator(java.util.Comparator) EventEntity(org.thingsboard.server.dao.model.sql.EventEntity) TbSqlBlockingQueueParams(org.thingsboard.server.dao.sql.TbSqlBlockingQueueParams) PostConstruct(javax.annotation.PostConstruct)

Example 3 with TbSqlBlockingQueueParams

use of org.thingsboard.server.dao.sql.TbSqlBlockingQueueParams 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));
}
Also used : MoreExecutors(com.google.common.util.concurrent.MoreExecutors) java.util(java.util) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) TbSqlBlockingQueueWrapper(org.thingsboard.server.dao.sql.TbSqlBlockingQueueWrapper) Autowired(org.springframework.beans.factory.annotation.Autowired) CompletableFuture(java.util.concurrent.CompletableFuture) SettableFuture(com.google.common.util.concurrent.SettableFuture) StatsFactory(org.thingsboard.server.common.stats.StatsFactory) Function(java.util.function.Function) TenantId(org.thingsboard.server.common.data.id.TenantId) Value(org.springframework.beans.factory.annotation.Value) PreDestroy(javax.annotation.PreDestroy) SQLException(java.sql.SQLException) AbstractTsKvEntity(org.thingsboard.server.dao.model.sql.AbstractTsKvEntity) AbstractSqlTimeseriesDao(org.thingsboard.server.dao.sqlts.AbstractSqlTimeseriesDao) TimescaleTsKvEntity(org.thingsboard.server.dao.model.sqlts.timescale.ts.TimescaleTsKvEntity) TbSqlBlockingQueueParams(org.thingsboard.server.dao.sql.TbSqlBlockingQueueParams) EntityId(org.thingsboard.server.common.data.id.EntityId) Sort(org.springframework.data.domain.Sort) InsertTsRepository(org.thingsboard.server.dao.sqlts.insert.InsertTsRepository) TimescaleDBTsDao(org.thingsboard.server.dao.util.TimescaleDBTsDao) Aggregation(org.thingsboard.server.common.data.kv.Aggregation) PageRequest(org.springframework.data.domain.PageRequest) DeleteTsKvQuery(org.thingsboard.server.common.data.kv.DeleteTsKvQuery) TsKvEntry(org.thingsboard.server.common.data.kv.TsKvEntry) Futures(com.google.common.util.concurrent.Futures) Slf4j(lombok.extern.slf4j.Slf4j) Component(org.springframework.stereotype.Component) CollectionUtils(org.springframework.util.CollectionUtils) TimeseriesDao(org.thingsboard.server.dao.timeseries.TimeseriesDao) PostConstruct(javax.annotation.PostConstruct) DaoUtil(org.thingsboard.server.dao.DaoUtil) CallableStatement(java.sql.CallableStatement) ReadTsKvQuery(org.thingsboard.server.common.data.kv.ReadTsKvQuery) ModelConstants(org.thingsboard.server.dao.model.ModelConstants) Types(java.sql.Types) Function(java.util.function.Function) TimescaleTsKvEntity(org.thingsboard.server.dao.model.sqlts.timescale.ts.TimescaleTsKvEntity) AbstractTsKvEntity(org.thingsboard.server.dao.model.sql.AbstractTsKvEntity) TbSqlBlockingQueueParams(org.thingsboard.server.dao.sql.TbSqlBlockingQueueParams) PostConstruct(javax.annotation.PostConstruct)

Example 4 with TbSqlBlockingQueueParams

use of org.thingsboard.server.dao.sql.TbSqlBlockingQueueParams 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);
}
Also used : MoreExecutors(com.google.common.util.concurrent.MoreExecutors) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) TbSqlBlockingQueueWrapper(org.thingsboard.server.dao.sql.TbSqlBlockingQueueWrapper) Autowired(org.springframework.beans.factory.annotation.Autowired) DeviceProfileId(org.thingsboard.server.common.data.id.DeviceProfileId) TsKvLatestCompositeKey(org.thingsboard.server.dao.model.sqlts.latest.TsKvLatestCompositeKey) HashMap(java.util.HashMap) ScheduledLogExecutorComponent(org.thingsboard.server.dao.sql.ScheduledLogExecutorComponent) StatsFactory(org.thingsboard.server.common.stats.StatsFactory) Function(java.util.function.Function) TenantId(org.thingsboard.server.common.data.id.TenantId) ArrayList(java.util.ArrayList) Value(org.springframework.beans.factory.annotation.Value) BasicTsKvEntry(org.thingsboard.server.common.data.kv.BasicTsKvEntry) PreDestroy(javax.annotation.PreDestroy) Lists(com.google.common.collect.Lists) AbstractTsKvEntity(org.thingsboard.server.dao.model.sql.AbstractTsKvEntity) TbSqlBlockingQueueParams(org.thingsboard.server.dao.sql.TbSqlBlockingQueueParams) Map(java.util.Map) EntityId(org.thingsboard.server.common.data.id.EntityId) TsKvLatestRemovingResult(org.thingsboard.server.common.data.kv.TsKvLatestRemovingResult) TsKvLatestEntity(org.thingsboard.server.dao.model.sqlts.latest.TsKvLatestEntity) BaseReadTsKvQuery(org.thingsboard.server.common.data.kv.BaseReadTsKvQuery) InsertLatestTsRepository(org.thingsboard.server.dao.sqlts.insert.latest.InsertLatestTsRepository) TimeseriesLatestDao(org.thingsboard.server.dao.timeseries.TimeseriesLatestDao) SqlTsLatestAnyDao(org.thingsboard.server.dao.util.SqlTsLatestAnyDao) Aggregation(org.thingsboard.server.common.data.kv.Aggregation) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) DeleteTsKvQuery(org.thingsboard.server.common.data.kv.DeleteTsKvQuery) TsKvEntry(org.thingsboard.server.common.data.kv.TsKvEntry) Futures(com.google.common.util.concurrent.Futures) Slf4j(lombok.extern.slf4j.Slf4j) Component(org.springframework.stereotype.Component) List(java.util.List) TsKvLatestRepository(org.thingsboard.server.dao.sqlts.latest.TsKvLatestRepository) PostConstruct(javax.annotation.PostConstruct) DaoUtil(org.thingsboard.server.dao.DaoUtil) SearchTsKvLatestRepository(org.thingsboard.server.dao.sqlts.latest.SearchTsKvLatestRepository) Optional(java.util.Optional) Comparator(java.util.Comparator) ReadTsKvQuery(org.thingsboard.server.common.data.kv.ReadTsKvQuery) StringDataEntry(org.thingsboard.server.common.data.kv.StringDataEntry) TsKvLatestEntity(org.thingsboard.server.dao.model.sqlts.latest.TsKvLatestEntity) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) UUID(java.util.UUID) TbSqlBlockingQueueParams(org.thingsboard.server.dao.sql.TbSqlBlockingQueueParams) PostConstruct(javax.annotation.PostConstruct)

Example 5 with TbSqlBlockingQueueParams

use of org.thingsboard.server.dao.sql.TbSqlBlockingQueueParams 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));
}
Also used : MoreExecutors(com.google.common.util.concurrent.MoreExecutors) java.util(java.util) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) TbSqlBlockingQueueWrapper(org.thingsboard.server.dao.sql.TbSqlBlockingQueueWrapper) Autowired(org.springframework.beans.factory.annotation.Autowired) CompletableFuture(java.util.concurrent.CompletableFuture) SettableFuture(com.google.common.util.concurrent.SettableFuture) StatsFactory(org.thingsboard.server.common.stats.StatsFactory) Function(java.util.function.Function) TenantId(org.thingsboard.server.common.data.id.TenantId) Value(org.springframework.beans.factory.annotation.Value) PreDestroy(javax.annotation.PreDestroy) AbstractTsKvEntity(org.thingsboard.server.dao.model.sql.AbstractTsKvEntity) TsKvEntity(org.thingsboard.server.dao.model.sqlts.ts.TsKvEntity) TbSqlBlockingQueueParams(org.thingsboard.server.dao.sql.TbSqlBlockingQueueParams) EntityId(org.thingsboard.server.common.data.id.EntityId) Sort(org.springframework.data.domain.Sort) InsertTsRepository(org.thingsboard.server.dao.sqlts.insert.InsertTsRepository) TsKvRepository(org.thingsboard.server.dao.sqlts.ts.TsKvRepository) Aggregation(org.thingsboard.server.common.data.kv.Aggregation) PageRequest(org.springframework.data.domain.PageRequest) Collectors(java.util.stream.Collectors) DeleteTsKvQuery(org.thingsboard.server.common.data.kv.DeleteTsKvQuery) TsKvEntry(org.thingsboard.server.common.data.kv.TsKvEntry) Futures(com.google.common.util.concurrent.Futures) Slf4j(lombok.extern.slf4j.Slf4j) TimeseriesDao(org.thingsboard.server.dao.timeseries.TimeseriesDao) PostConstruct(javax.annotation.PostConstruct) DaoUtil(org.thingsboard.server.dao.DaoUtil) ReadTsKvQuery(org.thingsboard.server.common.data.kv.ReadTsKvQuery) Function(java.util.function.Function) AbstractTsKvEntity(org.thingsboard.server.dao.model.sql.AbstractTsKvEntity) TsKvEntity(org.thingsboard.server.dao.model.sqlts.ts.TsKvEntity) AbstractTsKvEntity(org.thingsboard.server.dao.model.sql.AbstractTsKvEntity) TbSqlBlockingQueueParams(org.thingsboard.server.dao.sql.TbSqlBlockingQueueParams) PostConstruct(javax.annotation.PostConstruct)

Aggregations

ListenableFuture (com.google.common.util.concurrent.ListenableFuture)5 Function (java.util.function.Function)5 PostConstruct (javax.annotation.PostConstruct)5 PreDestroy (javax.annotation.PreDestroy)5 Slf4j (lombok.extern.slf4j.Slf4j)5 Autowired (org.springframework.beans.factory.annotation.Autowired)5 Value (org.springframework.beans.factory.annotation.Value)5 EntityId (org.thingsboard.server.common.data.id.EntityId)5 TenantId (org.thingsboard.server.common.data.id.TenantId)5 StatsFactory (org.thingsboard.server.common.stats.StatsFactory)5 DaoUtil (org.thingsboard.server.dao.DaoUtil)5 TbSqlBlockingQueueParams (org.thingsboard.server.dao.sql.TbSqlBlockingQueueParams)5 TbSqlBlockingQueueWrapper (org.thingsboard.server.dao.sql.TbSqlBlockingQueueWrapper)5 Futures (com.google.common.util.concurrent.Futures)4 Component (org.springframework.stereotype.Component)4 MoreExecutors (com.google.common.util.concurrent.MoreExecutors)3 Comparator (java.util.Comparator)3 List (java.util.List)3 Optional (java.util.Optional)3 Collectors (java.util.stream.Collectors)3