use of com.hazelcast.core.Pipelining in project openk9 by smclab.
the class AssociateEntitiesRunnable method run_.
@Override
public void run_() {
_log.info("start AssociateEntitiesRunnable");
IMap<AssociableEntityKey, Entity> associableEntityMap = MapUtil.getAssociableEntityMap(_hazelcastInstance);
Set<AssociableEntityKey> associableEntityKeys = associableEntityMap.localKeySet();
Map<AssociableEntityKey, Entity> localEntityMap = associableEntityMap.getAll(associableEntityKeys);
_log.info("ingestionKeys: " + localEntityMap.size());
Map<String, List<Entity>> groupingByIngestionId = localEntityMap.entrySet().stream().collect(Collectors.groupingBy(e -> e.getKey().getIngestionId(), Collectors.mapping(Map.Entry::getValue, Collectors.toList())));
List<AssociableEntityKey> entitiesToRemove = new ArrayList<>();
List<String> ingestionIds = new ArrayList<>();
for (Map.Entry<String, List<Entity>> entry : groupingByIngestionId.entrySet()) {
String ingestionId = entry.getKey();
List<Entity> v = entry.getValue();
if (v.isEmpty()) {
continue;
}
DataService dataService = CDI.current().select(DataService.class).get();
Long tenantId = v.stream().map(Entity::getTenantId).findFirst().get();
try {
boolean associated = dataService.associateEntities(tenantId, ingestionId, v.stream().map(IngestionEntity::fromEntity).collect(Collectors.toList()));
if (associated) {
for (Entity entity : v) {
entitiesToRemove.add(AssociableEntityKey.of(entity.getCacheId(), entity.getIngestionId()));
ingestionIds.add(ingestionId);
}
}
} catch (Exception ioe) {
_log.error(ioe.getMessage());
}
}
_log.info("entities associated: " + entitiesToRemove.size() + " ingestionIds: " + ingestionIds);
try {
Pipelining pipelining = new Pipelining<>(10);
for (AssociableEntityKey associateEntityKey : entitiesToRemove) {
pipelining.add(associableEntityMap.removeAsync(associateEntityKey));
}
pipelining.results();
} catch (Exception e) {
_log.error(e.getMessage(), e);
}
}
use of com.hazelcast.core.Pipelining in project openk9 by smclab.
the class CreateRelationRunnable method run_.
@Override
public void run_() {
IMap<EntityKey, Entity> entityIMap = MapUtil.getEntityMap(_hazelcastInstance);
Set<EntityKey> entityKeys = entityIMap.localKeySet(Predicates.and(Predicates.notEqual("id", null), Predicates.notEqual("graphId", null)));
_log.info("entityKeys: " + entityKeys.size());
Map<EntityKey, Entity> entityIMapAll = entityIMap.getAll(entityKeys);
_log.info("entityIMapAll: " + entityIMapAll.size());
IMap<EntityRelationKey, EntityRelation> entityRelationMap = MapUtil.getEntityRelationMap(_hazelcastInstance);
Map<String, String> collect = entityIMapAll.values().stream().collect(Collectors.toMap(Entity::getCacheId, Entity::getId));
String[] cacheIds = entityKeys.stream().map(EntityKey::getCacheId).distinct().toArray(String[]::new);
Map<EntityRelationKey, EntityRelation> entries = entityRelationMap.getAll(entityRelationMap.keySet(Predicates.in("__key.entityId", cacheIds)));
_log.info("entityRelations: " + entries.size());
EntityGraphService entityGraphService = CDI.current().select(EntityGraphService.class).get();
List<EntityRelationKey> entityRelationKeysToDelete = new ArrayList<>();
for (Map.Entry<EntityRelationKey, EntityRelation> entry : entries.entrySet()) {
EntityRelationKey key = entry.getKey();
EntityRelation value = entry.getValue();
String from = collect.get(value.getEntityCacheId());
String to = collect.get(value.getTo());
if (from != null && to != null) {
try {
entityGraphService.createRelationship(from, to, value.getName());
entityRelationKeysToDelete.add(key);
} catch (Exception e) {
_log.error(e.getMessage(), e);
}
}
}
try {
Pipelining pipelining = new Pipelining<>(10);
for (EntityRelationKey entityRelationKey : entityRelationKeysToDelete) {
pipelining.add(entityRelationMap.removeAsync(entityRelationKey));
}
pipelining.results();
} catch (Exception e) {
_log.error(e.getMessage(), e);
}
}
Aggregations