Search in sources :

Example 6 with MessagingException

use of com.metabroadcast.common.queue.MessagingException in project atlas-deer by atlasapi.

the class AbstractEquivalentContentStore method updateEquivalences.

@Override
public final void updateEquivalences(EquivalenceGraphUpdate update) throws WriteException {
    metricRegistry.meter(updateEquivalences + METER_CALLED).mark();
    Set<Id> ids = idsOf(update);
    ImmutableSet<Id> staleContentIds = ImmutableSet.of();
    try {
        lock.lock(ids);
        ImmutableSetMultimap.Builder<EquivalenceGraph, Content> graphsAndContentBuilder = ImmutableSetMultimap.builder();
        Function<Id, Optional<Content>> toContent = Functions.forMap(resolveIds(ids));
        for (EquivalenceGraph graph : update.getAllGraphs()) {
            Iterable<Optional<Content>> content = Collections2.transform(graph.getEquivalenceSet(), toContent);
            graphsAndContentBuilder.putAll(graph, Optional.presentInstances(content));
        }
        ImmutableSetMultimap<EquivalenceGraph, Content> graphsAndContent = graphsAndContentBuilder.build();
        // This has to run before we process the update so we can still resolve the set(s)
        // that are going to be deleted
        staleContentIds = getStaleContent(update.getDeleted(), graphsAndContent);
        update(graphsAndContent, update);
        sendEquivalentContentGraphChangedMessage(update);
    } catch (MessagingException | InterruptedException e) {
        metricRegistry.meter(updateEquivalences + METER_FAILURE).mark();
        throw new WriteException("Updating " + ids, e);
    } finally {
        lock.unlock(ids);
    }
    // We are updating stale content after we have already released our held IDs because
    // the ID(s) of the deleted graph(s) on which we hold a lock could be among the stale
    // content IDs and the lock is not reentrant
    updateStaleContent(staleContentIds);
}
Also used : WriteException(org.atlasapi.entity.util.WriteException) Optional(com.google.common.base.Optional) MessagingException(com.metabroadcast.common.queue.MessagingException) EquivalenceGraph(org.atlasapi.equivalence.EquivalenceGraph) Id(org.atlasapi.entity.Id)

Aggregations

MessagingException (com.metabroadcast.common.queue.MessagingException)6 Id (org.atlasapi.entity.Id)4 WriteException (org.atlasapi.entity.util.WriteException)3 Timestamp (com.metabroadcast.common.time.Timestamp)2 EquivalenceGraph (org.atlasapi.equivalence.EquivalenceGraph)2 Optional (com.google.common.base.Optional)1 OptionalMap (com.metabroadcast.common.collect.OptionalMap)1 BroadcastRef (org.atlasapi.content.BroadcastRef)1 ResourceUpdatedMessage (org.atlasapi.messaging.ResourceUpdatedMessage)1 ScheduleUpdateMessage (org.atlasapi.messaging.v3.ScheduleUpdateMessage)1 DateTime (org.joda.time.DateTime)1