Class AsynchronousUploadPrimitivesTask

  • All Implemented Interfaces:
    java.lang.Runnable, ProgressMonitor.CancelListener

    public final class AsynchronousUploadPrimitivesTask
    extends UploadPrimitivesTask
    Task for uploading primitives using background worker threads. The actual upload is delegated to the UploadPrimitivesTask. This class is a wrapper over that to make the background upload process safe. There can only be one instance of this class, hence background uploads are limited to one at a time. This class also changes the editLayer of MainLayerManager to null during upload so that any changes to the uploading layer are prohibited.
    Since:
    13133
    • Constructor Detail

      • AsynchronousUploadPrimitivesTask

        private AsynchronousUploadPrimitivesTask​(UploadStrategySpecification uploadStrategySpecification,
                                                 OsmDataLayer osmDataLayer,
                                                 APIDataSet apiDataSet,
                                                 Changeset changeset)
        Private constructor to restrict creating more Asynchronous upload tasks
        Parameters:
        uploadStrategySpecification - UploadStrategySpecification for the DataLayer
        osmDataLayer - Datalayer to be uploaded
        apiDataSet - ApiDataSet that contains the primitives to be uploaded
        changeset - Changeset for the datalayer
        Throws:
        java.lang.IllegalArgumentException - if layer is null
        java.lang.IllegalArgumentException - if toUpload is null
        java.lang.IllegalArgumentException - if strategy is null
        java.lang.IllegalArgumentException - if changeset is null
    • Method Detail

      • createAsynchronousUploadTask

        public static java.util.Optional<AsynchronousUploadPrimitivesTaskcreateAsynchronousUploadTask​(UploadStrategySpecification uploadStrategySpecification,
                                                                                                        OsmDataLayer dataLayer,
                                                                                                        APIDataSet apiDataSet,
                                                                                                        Changeset changeset)
        Creates an instance of AsynchronousUploadPrimitiveTask
        Parameters:
        uploadStrategySpecification - UploadStrategySpecification for the DataLayer
        dataLayer - Datalayer to be uploaded
        apiDataSet - ApiDataSet that contains the primitives to be uploaded
        changeset - Changeset for the datalayer
        Returns:
        Returns an Optional<AsynchronousUploadPrimitivesTask> if there is no background upload in progress. Otherwise returns an Optional.empty()
        Throws:
        java.lang.IllegalArgumentException - if layer is null
        java.lang.IllegalArgumentException - if toUpload is null
        java.lang.IllegalArgumentException - if strategy is null
        java.lang.IllegalArgumentException - if changeset is null
      • canRunInBackground

        public ProgressTaskId canRunInBackground()
        Description copied from class: PleaseWaitRunnable
        Task can run in background if returned value != null. Note that it's tasks responsibility to ensure proper synchronization, PleaseWaitRunnable doesn't with it.
        Overrides:
        canRunInBackground in class PleaseWaitRunnable
        Returns:
        If returned value is != null then task can run in background. TaskId could be used in future for "Always run in background" checkbox
      • realRun

        protected void realRun()
        Description copied from class: PleaseWaitRunnable
        Called in the worker thread to do the actual work. When any of the exception is thrown, a message box will be displayed and closeDialog is called. finish() is called in any case.
        Overrides:
        realRun in class UploadPrimitivesTask
      • finish

        protected void finish()
        Description copied from class: UploadPrimitivesTask
        Depending on the success of the upload operation and on the policy for multi changeset uploads this will send the user back to the appropriate place in JOSM, either:
        • to an error dialog,
        • to the Upload Dialog, or
        • to map editing.
        Overrides:
        finish in class UploadPrimitivesTask