001/*
002 * (C) Copyright 2010 Nuxeo SA (http://nuxeo.com/) and contributors.
003 *
004 * All rights reserved. This program and the accompanying materials
005 * are made available under the terms of the GNU Lesser General Public License
006 * (LGPL) version 2.1 which accompanies this distribution, and is available at
007 * http://www.gnu.org/licenses/lgpl.html
008 *
009 * This library is distributed in the hope that it will be useful,
010 * but WITHOUT ANY WARRANTY; without even the implied warranty of
011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012 * Lesser General Public License for more details.
013 *
014 * Contributors:
015 *     Nuxeo - initial API and implementation
016 */
017package org.nuxeo.ecm.platform.routing.core.impl;
018
019import java.util.List;
020
021import org.nuxeo.ecm.core.api.CoreSession;
022import org.nuxeo.ecm.platform.routing.api.DocumentRouteElement;
023
024/**
025 * Run all of its children simultaneous and is done when all the children are done.
026 *
027 * @author <a href="mailto:arussel@nuxeo.com">Alexandre Russel</a>
028 * @deprecated since 5.9.2 - Use only routes of type 'graph'
029 */
030@Deprecated
031public class ParallelRunner extends AbstractRunner implements ElementRunner {
032
033    @Override
034    public void run(CoreSession session, DocumentRouteElement element) {
035        List<DocumentRouteElement> children = getChildrenElement(session, element);
036        if (children.isEmpty()) {
037            element.setRunning(session);
038            element.setDone(session);
039            return;
040        }
041        if (!element.isRunning()) {
042            element.setRunning(session);
043            boolean someChildrenNotDone = false;
044            for (DocumentRouteElement child : children) {
045                child.run(session);
046                if (!child.isDone()) {
047                    someChildrenNotDone = true;
048                }
049            }
050            if (!someChildrenNotDone) {
051                element.setDone(session);
052            }
053            return;
054        } else {
055            boolean someChildrenNotDone = false;
056            for (DocumentRouteElement child : children) {
057                if (!child.isDone()) {
058                    child.run(session);
059                    if (!child.isDone()) {
060                        someChildrenNotDone = true;
061                    }
062                }
063            }
064            if (!someChildrenNotDone) {
065                element.setDone(session);
066            }
067        }
068    }
069}