Ejemplo n.º 1
0
  private IndexOperationMessage handleEdgeDelete(final QueueMessage message) {

    Preconditions.checkNotNull(message, "Queue Message cannot be null for handleEdgeDelete");

    final AsyncEvent event = (AsyncEvent) message.getBody();

    Preconditions.checkNotNull(message, "QueueMessage Body cannot be null for handleEdgeDelete");
    Preconditions.checkArgument(
        event instanceof EdgeDeleteEvent,
        String.format(
            "Event Type for handleEdgeDelete must be EDGE_DELETE, got %s", event.getClass()));

    final EdgeDeleteEvent edgeDeleteEvent = (EdgeDeleteEvent) event;

    final ApplicationScope applicationScope = edgeDeleteEvent.getApplicationScope();
    final Edge edge = edgeDeleteEvent.getEdge();

    if (logger.isDebugEnabled()) {
      logger.debug("Deleting in app scope {} with edge {}", applicationScope, edge);
    }

    // default this observable's return to empty index operation message if nothing is emitted
    return eventBuilder
        .buildDeleteEdge(applicationScope, edge)
        .toBlocking()
        .lastOrDefault(new IndexOperationMessage());
  }
Ejemplo n.º 2
0
  private IndexOperationMessage handleEdgeIndex(final QueueMessage message) {

    Preconditions.checkNotNull(message, "Queue Message cannot be null for handleEdgeIndex");

    final AsyncEvent event = (AsyncEvent) message.getBody();

    Preconditions.checkNotNull(message, "QueueMessage Body cannot be null for handleEdgeIndex");
    Preconditions.checkArgument(
        event instanceof EdgeIndexEvent,
        String.format(
            "Event Type for handleEdgeIndex must be EDGE_INDEX, got %s", event.getClass()));

    final EdgeIndexEvent edgeIndexEvent = (EdgeIndexEvent) event;

    final EntityCollectionManager ecm =
        entityCollectionManagerFactory.createCollectionManager(
            edgeIndexEvent.getApplicationScope());

    // default this observable's return to empty index operation message if nothing is emitted
    return ecm.load(edgeIndexEvent.getEntityId())
        .flatMap(
            loadedEntity ->
                eventBuilder.buildNewEdge(
                    edgeIndexEvent.getApplicationScope(), loadedEntity, edgeIndexEvent.getEdge()))
        .toBlocking()
        .lastOrDefault(new IndexOperationMessage());
  }
Ejemplo n.º 3
0
  private IndexOperationMessage handleEntityIndexUpdate(final QueueMessage message) {

    Preconditions.checkNotNull(message, "Queue Message cannot be null for handleEntityIndexUpdate");

    final AsyncEvent event = (AsyncEvent) message.getBody();

    Preconditions.checkNotNull(
        message, "QueueMessage Body cannot be null for handleEntityIndexUpdate");
    Preconditions.checkArgument(
        event instanceof EntityIndexEvent,
        String.format(
            "Event Type for handleEntityIndexUpdate must be ENTITY_INDEX, got %s",
            event.getClass()));

    final EntityIndexEvent entityIndexEvent = (EntityIndexEvent) event;

    // process the entity immediately
    // only process the same version, otherwise ignore
    final EntityIdScope entityIdScope = entityIndexEvent.getEntityIdScope();
    final ApplicationScope applicationScope = entityIdScope.getApplicationScope();
    final Id entityId = entityIdScope.getId();
    final long updatedAfter = entityIndexEvent.getUpdatedAfter();

    final EntityIndexOperation entityIndexOperation =
        new EntityIndexOperation(applicationScope, entityId, updatedAfter);

    // default this observable's return to empty index operation message if nothing is emitted
    return eventBuilder
        .buildEntityIndex(entityIndexOperation)
        .toBlocking()
        .lastOrDefault(new IndexOperationMessage());
  }
Ejemplo n.º 4
0
  public void index(final ApplicationScope applicationScope, final Id id, final long updatedSince) {

    EntityIndexOperation entityIndexOperation =
        new EntityIndexOperation(applicationScope, id, updatedSince);

    queueIndexOperationMessage(
        eventBuilder.buildEntityIndex(entityIndexOperation).toBlocking().lastOrDefault(null));
  }
Ejemplo n.º 5
0
  public IndexOperationMessage handleDeIndexOldVersionEvent(
      final DeIndexOldVersionsEvent deIndexOldVersionsEvent) {

    final ApplicationScope applicationScope =
        deIndexOldVersionsEvent.getEntityIdScope().getApplicationScope();
    final Id entityId = deIndexOldVersionsEvent.getEntityIdScope().getId();
    final UUID markedVersion = deIndexOldVersionsEvent.getMarkedVersion();

    // default this observable's return to empty index operation message if nothing is emitted
    return eventBuilder
        .deIndexOldVersions(applicationScope, entityId, markedVersion)
        .toBlocking()
        .lastOrDefault(new IndexOperationMessage());
  }
Ejemplo n.º 6
0
  @Override
  public void queueEntityIndexUpdate(
      final ApplicationScope applicationScope, final Entity entity, long updatedAfter) {

    offer(
        new EntityIndexEvent(
            queueFig.getPrimaryRegion(), new EntityIdScope(applicationScope, entity.getId()), 0));

    final EntityIndexOperation entityIndexOperation =
        new EntityIndexOperation(applicationScope, entity.getId(), updatedAfter);

    final IndexOperationMessage indexMessage =
        eventBuilder.buildEntityIndex(entityIndexOperation).toBlocking().lastOrDefault(null);

    queueIndexOperationMessage(indexMessage);
  }
Ejemplo n.º 7
0
  public void indexBatch(final List<EdgeScope> edges, final long updatedSince) {

    IndexOperationMessage batch = new IndexOperationMessage();

    for (EdgeScope e : edges) {

      EntityIndexOperation entityIndexOperation =
          new EntityIndexOperation(
              e.getApplicationScope(), e.getEdge().getTargetNode(), updatedSince);

      IndexOperationMessage indexOperationMessage =
          eventBuilder.buildEntityIndex(entityIndexOperation).toBlocking().lastOrDefault(null);

      if (indexOperationMessage != null) {
        batch.ingest(indexOperationMessage);
      }
    }

    queueIndexOperationMessage(batch);
  }
Ejemplo n.º 8
0
  private IndexOperationMessage handleEntityDelete(final QueueMessage message) {

    Preconditions.checkNotNull(message, "Queue Message cannot be null for handleEntityDelete");

    final AsyncEvent event = (AsyncEvent) message.getBody();
    Preconditions.checkNotNull(message, "QueueMessage Body cannot be null for handleEntityDelete");
    Preconditions.checkArgument(
        event instanceof EntityDeleteEvent,
        String.format(
            "Event Type for handleEntityDelete must be ENTITY_DELETE, got %s", event.getClass()));

    final EntityDeleteEvent entityDeleteEvent = (EntityDeleteEvent) event;
    final ApplicationScope applicationScope =
        entityDeleteEvent.getEntityIdScope().getApplicationScope();
    final Id entityId = entityDeleteEvent.getEntityIdScope().getId();

    if (logger.isDebugEnabled())
      logger.debug(
          "Deleting entity id from index in app scope {} with entityId {}",
          applicationScope,
          entityId);

    final EventBuilderImpl.EntityDeleteResults entityDeleteResults =
        eventBuilder.buildEntityDelete(applicationScope, entityId);

    // Delete the entities and remove from graph separately
    entityDeleteResults.getEntitiesDeleted().toBlocking().lastOrDefault(null);

    entityDeleteResults.getCompactedNode().toBlocking().lastOrDefault(null);

    // default this observable's return to empty index operation message if nothing is emitted
    return entityDeleteResults
        .getIndexObservable()
        .toBlocking()
        .lastOrDefault(new IndexOperationMessage());
  }