001/*
002 * (C) Copyright 2018 Nuxeo (http://nuxeo.com/) and others.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *     http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 *
016 * Contributors:
017 *     Funsho David
018 */
019package org.nuxeo.ecm.core.bulk;
020
021import java.io.Serializable;
022import java.time.Duration;
023import java.util.List;
024import java.util.Map;
025
026import org.nuxeo.ecm.core.api.AsyncService;
027import org.nuxeo.ecm.core.bulk.message.BulkCommand;
028import org.nuxeo.ecm.core.bulk.message.BulkStatus;
029
030/**
031 * API to manage Bulk Computation.
032 * <p>
033 * At this level, there is no verification of the user calling the method against command's user.
034 * <p>
035 * This kind of verification has to be done by caller if needed.
036 *
037 * @since 10.2
038 */
039public interface BulkService extends AsyncService<String, BulkStatus, Map<String, Serializable>> {
040
041    /**
042     * Submits a {@link BulkCommand} that will be processed asynchronously.
043     *
044     * @param command the command to submit
045     * @return a unique bulk command identifier
046     */
047    String submit(BulkCommand command);
048
049    /**
050     * Returns the command or null if the command is not found or aborted.
051     */
052    BulkCommand getCommand(String commandId);
053
054    /**
055     * Waits for completion of given bulk command.
056     *
057     * @param commandId the command to wait
058     * @param duration the duration to wait
059     * @return {@code true} if bulk command completed or {@code false} if computation has not finished after the timeout
060     */
061    boolean await(String commandId, Duration duration) throws InterruptedException;
062
063    /**
064     * Waits for completion of all bulk commands.
065     *
066     * @param duration the duration to wait
067     * @return {@code true} if all bulk commands completed or {@code false} if one or more has not finished after the
068     *         timeout
069     * @since 10.3
070     */
071    boolean await(Duration duration) throws InterruptedException;
072
073    /**
074     * Gets the list of action statuses triggered by the given user.
075     *
076     * @param username the user name
077     * @return the list of statuses
078     * @since 10.3
079     */
080    List<BulkStatus> getStatuses(String username);
081
082}