001/*
002 * Copyright (c) 2006-2011 Nuxeo SA (http://nuxeo.com/) and others.
003 *
004 * All rights reserved. This program and the accompanying materials
005 * are made available under the terms of the Eclipse Public License v1.0
006 * which accompanies this distribution, and is available at
007 * http://www.eclipse.org/legal/epl-v10.html
008 *
009 * Contributors:
010 *     Florent Guillaume
011 */
012package org.nuxeo.ecm.core.storage.sql;
013
014import java.util.ArrayList;
015import java.util.Collection;
016
017/**
018 * Propagator of invalidations to a set of {@link InvalidationsQueue}s.
019 */
020public class InvalidationsPropagator {
021
022    public final ArrayList<InvalidationsQueue> queues; // used synchronized
023
024    public InvalidationsPropagator() {
025        queues = new ArrayList<InvalidationsQueue>();
026    }
027
028    public synchronized void addQueue(InvalidationsQueue queue) {
029        if (!queues.contains(queue)) {
030            queues.add(queue);
031        }
032    }
033
034    public synchronized void removeQueue(InvalidationsQueue queue) {
035        queues.remove(queue);
036    }
037
038    @SuppressWarnings("unchecked")
039    public void propagateInvalidations(Invalidations invalidations, InvalidationsQueue skipQueue) {
040        Collection<InvalidationsQueue> qq;
041        synchronized (this) {
042            qq = (Collection<InvalidationsQueue>) queues.clone();
043        }
044        for (InvalidationsQueue q : qq) {
045            if (q != skipQueue) {
046                q.addInvalidations(invalidations);
047            }
048        }
049    }
050
051}