Package org.openstreetmap.josm.gui.io
Class AsynchronousUploadPrimitivesTask
- java.lang.Object
-
- org.openstreetmap.josm.gui.PleaseWaitRunnable
-
- org.openstreetmap.josm.gui.io.AbstractUploadTask
-
- org.openstreetmap.josm.gui.io.UploadPrimitivesTask
-
- org.openstreetmap.josm.gui.io.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 theUploadPrimitivesTask. 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 ofMainLayerManagerto null during upload so that any changes to the uploading layer are prohibited.- Since:
- 13133
-
-
Field Summary
Fields Modifier and Type Field Description private static AsynchronousUploadPrimitivesTaskasynchronousUploadPrimitivesTaskStatic instanceprivate ProgressTaskIdtaskIdMember fieldsprivate OsmDataLayeruploadDataLayer-
Fields inherited from class org.openstreetmap.josm.gui.PleaseWaitRunnable
progressMonitor
-
-
Constructor Summary
Constructors Modifier Constructor Description privateAsynchronousUploadPrimitivesTask(UploadStrategySpecification uploadStrategySpecification, OsmDataLayer osmDataLayer, APIDataSet apiDataSet, Changeset changeset)Private constructor to restrict creating more Asynchronous upload tasks
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidcancel()User pressed cancel button.ProgressTaskIdcanRunInBackground()Task can run in background if returned value != null.static java.util.Optional<AsynchronousUploadPrimitivesTask>createAsynchronousUploadTask(UploadStrategySpecification uploadStrategySpecification, OsmDataLayer dataLayer, APIDataSet apiDataSet, Changeset changeset)Creates an instance of AsynchronousUploadPrimitiveTaskprotected voidfinish()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.static java.util.Optional<AsynchronousUploadPrimitivesTask>getCurrentAsynchronousUploadTask()Get the current upload taskprotected voidrealRun()Called in the worker thread to do the actual work.-
Methods inherited from class org.openstreetmap.josm.gui.io.UploadPrimitivesTask
cleanupAfterUpload, handleChangesetFullResponse, promptUserForPolicy, recoverFromGoneOnServer
-
Methods inherited from class org.openstreetmap.josm.gui.io.AbstractUploadTask
handleFailedUpload, handleGone, handlePreconditionFailed, handleUploadConflict, handleUploadConflictForClosedChangeset, handleUploadConflictForKnownConflict, handleUploadConflictForUnknownConflict, handleUploadPreconditionFailedConflict, synchronizeDataSet, synchronizePrimitive
-
Methods inherited from class org.openstreetmap.josm.gui.PleaseWaitRunnable
afterFinish, getProgressMonitor, operationCanceled, run
-
-
-
-
Field Detail
-
asynchronousUploadPrimitivesTask
private static AsynchronousUploadPrimitivesTask asynchronousUploadPrimitivesTask
Static instance
-
taskId
private final ProgressTaskId taskId
Member fields
-
uploadDataLayer
private final OsmDataLayer uploadDataLayer
-
-
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 DataLayerosmDataLayer- Datalayer to be uploadedapiDataSet- ApiDataSet that contains the primitives to be uploadedchangeset- Changeset for the datalayer- Throws:
java.lang.IllegalArgumentException- if layer is nulljava.lang.IllegalArgumentException- if toUpload is nulljava.lang.IllegalArgumentException- if strategy is nulljava.lang.IllegalArgumentException- if changeset is null
-
-
Method Detail
-
createAsynchronousUploadTask
public static java.util.Optional<AsynchronousUploadPrimitivesTask> createAsynchronousUploadTask(UploadStrategySpecification uploadStrategySpecification, OsmDataLayer dataLayer, APIDataSet apiDataSet, Changeset changeset)
Creates an instance of AsynchronousUploadPrimitiveTask- Parameters:
uploadStrategySpecification- UploadStrategySpecification for the DataLayerdataLayer- Datalayer to be uploadedapiDataSet- ApiDataSet that contains the primitives to be uploadedchangeset- 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 nulljava.lang.IllegalArgumentException- if toUpload is nulljava.lang.IllegalArgumentException- if strategy is nulljava.lang.IllegalArgumentException- if changeset is null
-
getCurrentAsynchronousUploadTask
public static java.util.Optional<AsynchronousUploadPrimitivesTask> getCurrentAsynchronousUploadTask()
Get the current upload task- Returns:
- Optional<AsynchronousUploadPrimitivesTask>
-
canRunInBackground
public ProgressTaskId canRunInBackground()
Description copied from class:PleaseWaitRunnableTask can run in background if returned value != null. Note that it's tasks responsibility to ensure proper synchronization, PleaseWaitRunnable doesn't with it.- Overrides:
canRunInBackgroundin classPleaseWaitRunnable- 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:PleaseWaitRunnableCalled 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:
realRunin classUploadPrimitivesTask
-
cancel
protected void cancel()
Description copied from class:PleaseWaitRunnableUser pressed cancel button.- Overrides:
cancelin classUploadPrimitivesTask
-
finish
protected void finish()
Description copied from class:UploadPrimitivesTaskDepending 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:
finishin classUploadPrimitivesTask
-
-