org.openstreetmap.josm.io
Class OsmServerWriter

java.lang.Object
  extended by org.openstreetmap.josm.io.OsmServerWriter

public class OsmServerWriter
extends java.lang.Object

Class that uploads all changes to the osm server. This is done like this: - All objects with id = 0 are uploaded as new, except those in deleted, which are ignored - All objects in deleted list are deleted. - All remaining objects with modified flag set are updated.


Field Summary
private  OsmApi api
           
private  boolean canceled
           
private static int MSECS_PER_MINUTE
           
private static int MSECS_PER_SECOND
           
private static java.util.ArrayList<OsmServerWritePostprocessor> postprocessors
           
private  java.util.Collection<IPrimitive> processed
          This list contains all successfully processed objects.
private static int SECONDS_PER_MINUTE
           
(package private)  long uploadStartTime
           
 
Constructor Summary
OsmServerWriter()
           
 
Method Summary
 void cancel()
           
 void executePostprocessors(ProgressMonitor pm)
          Calls all registered upload postprocessors.
 java.util.Collection<IPrimitive> getProcessedPrimitives()
          Replies the collection of successfully processed primitives
(package private)  void makeApiRequest(IPrimitive osm, ProgressMonitor progressMonitor)
           
static void registerPostprocessor(OsmServerWritePostprocessor pp)
           
 java.lang.String timeLeft(int progress, int list_size)
           
static void unregisterPostprocessor(OsmServerWritePostprocessor pp)
           
protected  void uploadChangesAsDiffUpload(java.util.Collection<? extends IPrimitive> primitives, ProgressMonitor progressMonitor)
          Upload all changes in one diff upload
protected  void uploadChangesInChunks(java.util.Collection<? extends IPrimitive> primitives, ProgressMonitor progressMonitor, int chunkSize)
          Upload all changes in one diff upload
protected  void uploadChangesIndividually(java.util.Collection<? extends IPrimitive> primitives, ProgressMonitor progressMonitor)
          Uploads the changes individually.
 void uploadOsm(UploadStrategySpecification strategy, java.util.Collection<? extends IPrimitive> primitives, Changeset changeset, ProgressMonitor monitor)
          Send the dataset to the server.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

processed

private java.util.Collection<IPrimitive> processed
This list contains all successfully processed objects. The caller of upload* has to check this after the call and update its dataset. If a server connection error occurs, this may contain fewer entries than where passed in the list to upload*.


postprocessors

private static java.util.ArrayList<OsmServerWritePostprocessor> postprocessors

api

private OsmApi api

canceled

private boolean canceled

MSECS_PER_SECOND

private static final int MSECS_PER_SECOND
See Also:
Constant Field Values

SECONDS_PER_MINUTE

private static final int SECONDS_PER_MINUTE
See Also:
Constant Field Values

MSECS_PER_MINUTE

private static final int MSECS_PER_MINUTE
See Also:
Constant Field Values

uploadStartTime

long uploadStartTime
Constructor Detail

OsmServerWriter

public OsmServerWriter()
Method Detail

registerPostprocessor

public static void registerPostprocessor(OsmServerWritePostprocessor pp)

unregisterPostprocessor

public static void unregisterPostprocessor(OsmServerWritePostprocessor pp)

timeLeft

public java.lang.String timeLeft(int progress,
                                 int list_size)

uploadChangesIndividually

protected void uploadChangesIndividually(java.util.Collection<? extends IPrimitive> primitives,
                                         ProgressMonitor progressMonitor)
                                  throws OsmTransferException
Uploads the changes individually. Invokes one API call per uploaded primitmive.

Parameters:
primitives - the collection of primitives to upload
progressMonitor - the progress monitor
Throws:
OsmTransferException - thrown if an exception occurs

uploadChangesAsDiffUpload

protected void uploadChangesAsDiffUpload(java.util.Collection<? extends IPrimitive> primitives,
                                         ProgressMonitor progressMonitor)
                                  throws OsmTransferException
Upload all changes in one diff upload

Parameters:
primitives - the collection of primitives to upload
progressMonitor - the progress monitor
Throws:
OsmTransferException - thrown if an exception occurs

uploadChangesInChunks

protected void uploadChangesInChunks(java.util.Collection<? extends IPrimitive> primitives,
                                     ProgressMonitor progressMonitor,
                                     int chunkSize)
                              throws OsmTransferException,
                                     java.lang.IllegalArgumentException
Upload all changes in one diff upload

Parameters:
primitives - the collection of primitives to upload
progressMonitor - the progress monitor
chunkSize - the size of the individual upload chunks. > 0 required.
Throws:
java.lang.IllegalArgumentException - thrown if chunkSize <= 0
OsmTransferException - thrown if an exception occurs

uploadOsm

public void uploadOsm(UploadStrategySpecification strategy,
                      java.util.Collection<? extends IPrimitive> primitives,
                      Changeset changeset,
                      ProgressMonitor monitor)
               throws OsmTransferException
Send the dataset to the server.

Parameters:
strategy - the upload strategy. Must not be null.
primitives - list of objects to send
changeset - the changeset the data is uploaded to. Must not be null.
monitor - the progress monitor. If null, assumes NullProgressMonitor.INSTANCE
Throws:
java.lang.IllegalArgumentException - thrown if changeset is null
java.lang.IllegalArgumentException - thrown if strategy is null
OsmTransferException - thrown if something goes wrong

makeApiRequest

void makeApiRequest(IPrimitive osm,
                    ProgressMonitor progressMonitor)
              throws OsmTransferException
Throws:
OsmTransferException

cancel

public void cancel()

getProcessedPrimitives

public java.util.Collection<IPrimitive> getProcessedPrimitives()
Replies the collection of successfully processed primitives

Returns:
the collection of successfully processed primitives

executePostprocessors

public void executePostprocessors(ProgressMonitor pm)
Calls all registered upload postprocessors.



JOSM