Search in sources :

Example 1 with NotFoundException

use of org.hypertrace.entity.data.service.client.exception.NotFoundException in project entity-service by hypertrace.

the class EdsCacheClient method initCache.

private void initCache(EntityServiceClientCacheConfig cacheConfig, Executor executor) {
    this.enrichedEntityCache = CacheBuilder.newBuilder().refreshAfterWrite(cacheConfig.getEnrichedEntityCacheRefreshMs(), TimeUnit.MILLISECONDS).expireAfterWrite(cacheConfig.getEnrichedEntityCacheExpiryMs(), TimeUnit.MILLISECONDS).maximumSize(cacheConfig.getEnrichedEntityMaxCacheSize()).recordStats().build(CacheLoader.asyncReloading(new CacheLoader<>() {

        public EnrichedEntity load(@Nonnull EdsCacheKey key) throws Exception {
            EnrichedEntity enrichedEntity = client.getEnrichedEntityById(key.tenantId, key.entityId);
            if (enrichedEntity == null) {
                throw new NotFoundException("Enriched entity not found");
            }
            return enrichedEntity;
        }
    }, executor));
    this.entityCache = CacheBuilder.newBuilder().refreshAfterWrite(cacheConfig.getEntityCacheRefreshMs(), TimeUnit.MILLISECONDS).expireAfterWrite(cacheConfig.getEntityCacheExpiryMs(), TimeUnit.MILLISECONDS).maximumSize(cacheConfig.getEntityMaxCacheSize()).recordStats().build(CacheLoader.asyncReloading(new CacheLoader<>() {

        public Entity load(@Nonnull EdsCacheKey key) throws Exception {
            Entity entity = client.getById(key.tenantId, key.entityId);
            if (entity == null) {
                throw new NotFoundException("Entity not found");
            }
            return entity;
        }
    }, executor));
    this.entityIdsCache = CacheBuilder.newBuilder().refreshAfterWrite(cacheConfig.getEntityIdsCacheRefreshMs(), TimeUnit.MILLISECONDS).expireAfterWrite(cacheConfig.getEntityIdsCacheExpiryMs(), TimeUnit.MILLISECONDS).maximumSize(cacheConfig.getEntityIdsMaxCacheSize()).recordStats().build(CacheLoader.asyncReloading(new CacheLoader<>() {

        public String load(@Nonnull EdsTypeAndIdAttributesCacheKey key) throws Exception {
            Entity entity = client.getByTypeAndIdentifyingAttributes(key.tenantId, key.byTypeAndIdentifyingAttributes);
            if (entity == null) {
                throw new NotFoundException("Entity not found!!");
            }
            entityCache.put(new EdsCacheKey(entity.getTenantId(), entity.getEntityId()), entity);
            return entity.getEntityId();
        }
    }, executor));
    PlatformMetricsRegistry.registerCache(this.getClass().getName() + ".enrichedEntityCache", enrichedEntityCache, Collections.emptyMap());
    PlatformMetricsRegistry.registerCache(this.getClass().getName() + ".entityCache", entityCache, Collections.emptyMap());
    PlatformMetricsRegistry.registerCache(this.getClass().getName() + ".entityIdsCache", entityIdsCache, Collections.emptyMap());
}
Also used : Entity(org.hypertrace.entity.data.service.v1.Entity) EnrichedEntity(org.hypertrace.entity.data.service.v1.EnrichedEntity) NotFoundException(org.hypertrace.entity.data.service.client.exception.NotFoundException) NotFoundException(org.hypertrace.entity.data.service.client.exception.NotFoundException) ExecutionException(java.util.concurrent.ExecutionException) EnrichedEntity(org.hypertrace.entity.data.service.v1.EnrichedEntity)

Aggregations

ExecutionException (java.util.concurrent.ExecutionException)1 NotFoundException (org.hypertrace.entity.data.service.client.exception.NotFoundException)1 EnrichedEntity (org.hypertrace.entity.data.service.v1.EnrichedEntity)1 Entity (org.hypertrace.entity.data.service.v1.Entity)1