// Path: api/src/main/java/org/alfresco/extension/bulkimport/source/BulkImportSource.java
// public interface BulkImportSource
// {
//     /**
//      * @return The human readable name of this bulk import source <i>(must not be null, empty or blank)</i>.
//      */
//     String getName();
//     
//     
//     /**
//      * @return A description of this bulk import source - may contain HTML tags <i>(may be null, empty or blank)</i>.
//      */
//     String getDescription();
//     
//     
//     /**
//      * @return The parameters used to initialise this import source, as human-readable text <i>(may be null or empty)</i>.
//      */
//     Map<String, String> getParameters();
// 
//     
//     /**
//      * @return The URI of the Web Script to display in the initiation form, when this source is selected <i>(may be null)</i>.
//      */
//     String getConfigWebScriptURI();
//     
//     
//     /**
//      * Called before anything else, so that the source can validate and parse its parameters.  If the parameters are invalid,
//      * sources should throw an <code>IllegalArgumentException</code> with details on which parameters were missing / invalid.
//      * 
//      * @param status     The status object to use to pre-register any source-side statistics <i>(will not be null)</li>.
//      * @param parameters The parameters (if any) provided by the initiator of the import <i>(will not be null, but may be empty)</i>.
//      */
//     void init(BulkImportSourceStatus status, Map<String, List<String>> parameters);
//     
//     
//     /**
//      * Query to determine whether an "in-place" import is possible, given the provided parameters.  Note that this doesn't imply
//      * that all content in the source must be imported in-place - that can be decided by a source implementation on a file-by-file
//      * basis.  Instead this is indicative of whether any amount of in-place import is possible or not.
//      * 
//      * @return True if an in-place import is possible with the given parameters, or false otherwise.
//      */
//     boolean inPlaceImportPossible();
//     
//     
//     /**
//      * Called when the folder scanning phase of a bulk import is commenced.  Importable items should be submitted via the callback,
//      * and status may (optionally) be provided via the status object.
//      * 
//      * Notes:
//      * <ol>
//      * <li>Items must be submitted in dependency order i.e. parents before children.
//      * Failure to do so will have a <b>severe</b> impact on performance (due to
//      * transactional rollbacks, followed by retries).</li>
//      * <li>This code <u>must not</u> use any Alfresco repository services whatsoever,
//      * as this method is executed on a background thread that runs outside of both
//      * an Alfresco authentication context and an Alfresco transaction.</li>
//      * </ol>
//      * 
//      * @param status     The status object to use to report source-side statistics <i>(will not be null)</li>.
//      * @param callback   The callback into the bulk import engine with which to enqueue items discovered <i>(will not be null)</li>.
//      * @throws InterruptedException Should be thrown if the thread running the scan is interrupted.
//      */
//     void scanFolders(BulkImportSourceStatus status, BulkImportCallback callback)
//         throws InterruptedException;
// 
//     
//     /**
//      * Called when the file scanning phase of a bulk import is commenced.  Importable items should be submitted via the callback,
//      * and status may (optionally) be provided via the status object.
//      * 
//      * Notes:
//      * <ol>
//      * <li>This code must <u>not</u> use any Alfresco repository services whatsoever,
//      * as this method is executed on a background thread that runs outside of both
//      * an Alfresco authentication context and an Alfresco transaction.</li>
//      * </ol>
//      * 
//      * @param status     The status object to use to report source-side statistics <i>(will not be null)</li>.
//      * @param callback   The callback into the bulk import engine with which to enqueue items discovered <i>(will not be null)</li>.
//      * @throws InterruptedException Should be thrown if the thread running the scan is interrupted.
//      */
//     void scanFiles(BulkImportSourceStatus status, BulkImportCallback callback)
//         throws InterruptedException;
//     
// }


import java.util.concurrent.atomic.AtomicLong;
import org.alfresco.extension.bulkimport.source.BulkImportSource;
import static java.util.concurrent.TimeUnit.*;
import static org.alfresco.extension.bulkimport.util.LogUtils.*;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.Collections;
import java.util.Date;
import java.util.Map;
import java.util.Set;
import java.util.TreeSet;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
/*
 * Copyright (C) 2007 Peter Monks
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *     http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * 
 * This file is part of an unsupported extension to Alfresco.
 * 
 */

package org.alfresco.extension.bulkimport.impl;





/**
 * Thread-safe implementation of Bulk Import Status.
 *
 * @author Peter Monks (pmonks@gmail.com)
 * @see org.alfresco.extension.bulkimport.impl.WritableBulkImportStatus
 */
public class BulkImportStatusImpl
    implements WritableBulkImportStatus
{
    // General information
    private AtomicBoolean                inProgress            = new AtomicBoolean(false);
    private volatile ProcessingState     state                 = ProcessingState.NEVER_RUN;
    private volatile ProcessingState     priorState            = state;
    private String                       initiatingUserId      = null;
// Path: api/src/main/java/org/alfresco/extension/bulkimport/source/BulkImportSource.java
// public interface BulkImportSource
// {
//     /**
//      * @return The human readable name of this bulk import source <i>(must not be null, empty or blank)</i>.
//      */
//     String getName();
//     
//     
//     /**
//      * @return A description of this bulk import source - may contain HTML tags <i>(may be null, empty or blank)</i>.
//      */
//     String getDescription();
//     
//     
//     /**
//      * @return The parameters used to initialise this import source, as human-readable text <i>(may be null or empty)</i>.
//      */
//     Map<String, String> getParameters();
// 
//     
//     /**
//      * @return The URI of the Web Script to display in the initiation form, when this source is selected <i>(may be null)</i>.
//      */
//     String getConfigWebScriptURI();
//     
//     
//     /**
//      * Called before anything else, so that the source can validate and parse its parameters.  If the parameters are invalid,
//      * sources should throw an <code>IllegalArgumentException</code> with details on which parameters were missing / invalid.
//      * 
//      * @param status     The status object to use to pre-register any source-side statistics <i>(will not be null)</li>.
//      * @param parameters The parameters (if any) provided by the initiator of the import <i>(will not be null, but may be empty)</i>.
//      */
//     void init(BulkImportSourceStatus status, Map<String, List<String>> parameters);
//     
//     
//     /**
//      * Query to determine whether an "in-place" import is possible, given the provided parameters.  Note that this doesn't imply
//      * that all content in the source must be imported in-place - that can be decided by a source implementation on a file-by-file
//      * basis.  Instead this is indicative of whether any amount of in-place import is possible or not.
//      * 
//      * @return True if an in-place import is possible with the given parameters, or false otherwise.
//      */
//     boolean inPlaceImportPossible();
//     
//     
//     /**
//      * Called when the folder scanning phase of a bulk import is commenced.  Importable items should be submitted via the callback,
//      * and status may (optionally) be provided via the status object.
//      * 
//      * Notes:
//      * <ol>
//      * <li>Items must be submitted in dependency order i.e. parents before children.
//      * Failure to do so will have a <b>severe</b> impact on performance (due to
//      * transactional rollbacks, followed by retries).</li>
//      * <li>This code <u>must not</u> use any Alfresco repository services whatsoever,
//      * as this method is executed on a background thread that runs outside of both
//      * an Alfresco authentication context and an Alfresco transaction.</li>
//      * </ol>
//      * 
//      * @param status     The status object to use to report source-side statistics <i>(will not be null)</li>.
//      * @param callback   The callback into the bulk import engine with which to enqueue items discovered <i>(will not be null)</li>.
//      * @throws InterruptedException Should be thrown if the thread running the scan is interrupted.
//      */
//     void scanFolders(BulkImportSourceStatus status, BulkImportCallback callback)
//         throws InterruptedException;
// 
//     
//     /**
//      * Called when the file scanning phase of a bulk import is commenced.  Importable items should be submitted via the callback,
//      * and status may (optionally) be provided via the status object.
//      * 
//      * Notes:
//      * <ol>
//      * <li>This code must <u>not</u> use any Alfresco repository services whatsoever,
//      * as this method is executed on a background thread that runs outside of both
//      * an Alfresco authentication context and an Alfresco transaction.</li>
//      * </ol>
//      * 
//      * @param status     The status object to use to report source-side statistics <i>(will not be null)</li>.
//      * @param callback   The callback into the bulk import engine with which to enqueue items discovered <i>(will not be null)</li>.
//      * @throws InterruptedException Should be thrown if the thread running the scan is interrupted.
//      */
//     void scanFiles(BulkImportSourceStatus status, BulkImportCallback callback)
//         throws InterruptedException;
//     
// }


// Path: amp/src/main/java/org/alfresco/extension/bulkimport/impl/BulkImportStatusImpl.java
import java.util.concurrent.atomic.AtomicLong;
import org.alfresco.extension.bulkimport.source.BulkImportSource;
import static java.util.concurrent.TimeUnit.*;
import static org.alfresco.extension.bulkimport.util.LogUtils.*;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.Collections;
import java.util.Date;
import java.util.Map;
import java.util.Set;
import java.util.TreeSet;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;

/*
 * Copyright (C) 2007 Peter Monks
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *     http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * 
 * This file is part of an unsupported extension to Alfresco.
 * 
 */

package org.alfresco.extension.bulkimport.impl;





/**
 * Thread-safe implementation of Bulk Import Status.
 *
 * @author Peter Monks (pmonks@gmail.com)
 * @see org.alfresco.extension.bulkimport.impl.WritableBulkImportStatus
 */
public class BulkImportStatusImpl
    implements WritableBulkImportStatus
{
    // General information
    private AtomicBoolean                inProgress            = new AtomicBoolean(false);
    private volatile ProcessingState     state                 = ProcessingState.NEVER_RUN;
    private volatile ProcessingState     priorState            = state;
    private String                       initiatingUserId      = null;
    private BulkImportSource             source                = null;