Esempio n. 1
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());
  }
Esempio n. 2
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());
  }
Esempio 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());
  }
Esempio n. 4
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());
  }