001/*
002 * (C) Copyright 2015 Nuxeo SA (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 *     <a href="mailto:grenard@nuxeo.com">Guillaume Renard</a>
018 *
019 */
020package org.nuxeo.ecm.liveconnect.update;
021
022import java.util.List;
023
024import org.nuxeo.ecm.core.api.DocumentModel;
025import org.nuxeo.ecm.liveconnect.update.listener.BlobProviderDocumentsUpdateListener;
026import org.nuxeo.ecm.liveconnect.update.worker.BlobProviderDocumentsUpdateWork;
027
028/**
029 * Interface to batch update documents provided by implementing provider. The method {@link #processDocumentsUpdate()}
030 * is called by {@link BlobProviderDocumentsUpdateListener}.
031 * <p>
032 * The implementation of {@link #processDocumentsUpdate()} must schedule a {@link BlobProviderDocumentsUpdateWork} with
033 * the document ids to be checked and updated if needed.
034 * <p>
035 * The @{link BlobProviderDocumentsUpdateWork} will then call the implementation of
036 * {@link #checkChangesAndUpdateBlob(List)}.
037 * <p>
038 * Note that it is recommended to schedule many workers dealing with a smaller amount of documents (using
039 * {@link #MAX_RESULT}) rather than a single one processing all document brought by the provider.
040 *
041 * @since 7.3
042 */
043public interface BatchUpdateBlobProvider {
044
045    long MAX_RESULT = 50;
046
047    /**
048     * Check the given list of document for change and update if needed. Note that session.save still needs to be called
049     * on changed documents.
050     *
051     * @param documents to be checked for update
052     * @return the list of DocumentModel that have changed
053     */
054    List<DocumentModel> checkChangesAndUpdateBlob(List<DocumentModel> documents);
055
056    /**
057     * Trigger the documents update for the implementing providers.
058     */
059    void processDocumentsUpdate();
060
061}