Changeset 7656 in josm for trunk/src/org


Ignore:
Timestamp:
2014-10-27T20:47:56+01:00 (5 years ago)
Author:
Don-vip
Message:

improve performance of "Postprocessing uploaded data ..." step after upload by locking dataset (avoid map repaint each time a new primitive is assigned an id). Changes impact sds plugin.

Location:
trunk/src/org/openstreetmap/josm/io
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/io/DiffResultProcessor.java

    r7012 r7656  
    1717
    1818import org.openstreetmap.josm.data.osm.Changeset;
    19 import org.openstreetmap.josm.data.osm.IPrimitive;
     19import org.openstreetmap.josm.data.osm.DataSet;
     20import org.openstreetmap.josm.data.osm.OsmPrimitive;
    2021import org.openstreetmap.josm.data.osm.OsmPrimitiveType;
    2122import org.openstreetmap.josm.data.osm.PrimitiveId;
     
    4445    private Map<PrimitiveId, DiffResultEntry> diffResults = new HashMap<>();
    4546    /**
    46      * the set of processed primitives *after* the new id, the new version and the new changeset id
    47      * is set
     47     * the set of processed primitives *after* the new id, the new version and the new changeset id is set
    4848     */
    49     private Set<IPrimitive> processed;
     49    private Set<OsmPrimitive> processed;
    5050    /**
    5151     * the collection of primitives being uploaded
    5252     */
    53     private Collection<? extends IPrimitive> primitives;
     53    private Collection<? extends OsmPrimitive> primitives;
    5454
    5555    /**
     
    5959     * assumes an empty collection.
    6060     */
    61     public DiffResultProcessor(Collection<? extends IPrimitive> primitives) {
     61    public DiffResultProcessor(Collection<? extends OsmPrimitive> primitives) {
    6262        if (primitives == null) {
    6363            primitives = Collections.emptyList();
     
    105105     * @return the collection of processed primitives
    106106     */
    107     protected Set<IPrimitive> postProcess(Changeset cs, ProgressMonitor monitor) {
     107    protected Set<OsmPrimitive> postProcess(Changeset cs, ProgressMonitor monitor) {
    108108        if (monitor == null) {
    109109            monitor = NullProgressMonitor.INSTANCE;
    110110        }
     111        DataSet ds = primitives.iterator().next().getDataSet();
     112        ds.beginUpdate();
    111113        try {
    112114            monitor.beginTask("Postprocessing uploaded data ...");
    113115            monitor.setTicksCount(primitives.size());
    114116            monitor.setTicks(0);
    115             for (IPrimitive p : primitives) {
     117            for (OsmPrimitive p : primitives) {
    116118                monitor.worked(1);
    117119                DiffResultEntry entry = diffResults.get(p.getPrimitiveId());
     
    132134            return processed;
    133135        } finally {
     136            ds.endUpdate();
    134137            monitor.finishTask();
    135138        }
  • trunk/src/org/openstreetmap/josm/io/OsmApi.java

    r7476 r7656  
    3131import org.openstreetmap.josm.data.osm.Changeset;
    3232import org.openstreetmap.josm.data.osm.IPrimitive;
     33import org.openstreetmap.josm.data.osm.OsmPrimitive;
    3334import org.openstreetmap.josm.data.osm.OsmPrimitiveType;
    3435import org.openstreetmap.josm.gui.layer.ImageryLayer;
     
    387388     * @throws OsmTransferException if something goes wrong
    388389     */
    389     public void deletePrimitive(IPrimitive osm, ProgressMonitor monitor) throws OsmTransferException {
     390    public void deletePrimitive(OsmPrimitive osm, ProgressMonitor monitor) throws OsmTransferException {
    390391        ensureValidChangeset();
    391392        initialize(monitor);
     
    506507     * @throws OsmTransferException if something is wrong
    507508     */
    508     public Collection<IPrimitive> uploadDiff(Collection<? extends IPrimitive> list, ProgressMonitor monitor) throws OsmTransferException {
     509    public Collection<OsmPrimitive> uploadDiff(Collection<? extends OsmPrimitive> list, ProgressMonitor monitor) throws OsmTransferException {
    509510        try {
    510511            monitor.beginTask("", list.size() * 2);
  • trunk/src/org/openstreetmap/josm/io/OsmServerWritePostprocessor.java

    r4645 r7656  
    44import java.util.Collection;
    55
    6 import org.openstreetmap.josm.data.osm.IPrimitive;
     6import org.openstreetmap.josm.data.osm.OsmPrimitive;
    77import org.openstreetmap.josm.gui.progress.ProgressMonitor;
    88
    99public interface OsmServerWritePostprocessor {
    1010
    11     public void postprocessUploadedPrimitives(Collection<IPrimitive> p, ProgressMonitor progress);
     11    public void postprocessUploadedPrimitives(Collection<OsmPrimitive> p, ProgressMonitor progress);
    1212
    1313}
  • trunk/src/org/openstreetmap/josm/io/OsmServerWriter.java

    r7005 r7656  
    1313
    1414import org.openstreetmap.josm.data.osm.Changeset;
    15 import org.openstreetmap.josm.data.osm.IPrimitive;
     15import org.openstreetmap.josm.data.osm.OsmPrimitive;
    1616import org.openstreetmap.josm.data.osm.OsmPrimitiveType;
    1717import org.openstreetmap.josm.gui.io.UploadStrategySpecification;
     
    3535     * than where passed in the list to upload*.
    3636     */
    37     private Collection<IPrimitive> processed;
     37    private Collection<OsmPrimitive> processed;
    3838
    3939    private static List<OsmServerWritePostprocessor> postprocessors;
     
    8585     * @throws OsmTransferException thrown if an exception occurs
    8686     */
    87     protected void uploadChangesIndividually(Collection<? extends IPrimitive> primitives, ProgressMonitor progressMonitor) throws OsmTransferException {
     87    protected void uploadChangesIndividually(Collection<? extends OsmPrimitive> primitives, ProgressMonitor progressMonitor) throws OsmTransferException {
    8888        try {
    8989            progressMonitor.beginTask(tr("Starting to upload with one request per primitive ..."));
    9090            progressMonitor.setTicksCount(primitives.size());
    9191            uploadStartTime = System.currentTimeMillis();
    92             for (IPrimitive osm : primitives) {
     92            for (OsmPrimitive osm : primitives) {
    9393                int progress = progressMonitor.getTicks();
    9494                String time_left_str = timeLeft(progress, primitives.size());
     
    127127     * @throws OsmTransferException thrown if an exception occurs
    128128     */
    129     protected void uploadChangesAsDiffUpload(Collection<? extends IPrimitive> primitives, ProgressMonitor progressMonitor) throws OsmTransferException {
     129    protected void uploadChangesAsDiffUpload(Collection<? extends OsmPrimitive> primitives, ProgressMonitor progressMonitor) throws OsmTransferException {
    130130        try {
    131131            progressMonitor.beginTask(tr("Starting to upload in one request ..."));
     
    147147     * @throws OsmTransferException thrown if an exception occurs
    148148     */
    149     protected void uploadChangesInChunks(Collection<? extends IPrimitive> primitives, ProgressMonitor progressMonitor, int chunkSize) throws OsmTransferException, IllegalArgumentException {
     149    protected void uploadChangesInChunks(Collection<? extends OsmPrimitive> primitives, ProgressMonitor progressMonitor, int chunkSize) throws OsmTransferException, IllegalArgumentException {
    150150        if (chunkSize <=0)
    151151            throw new IllegalArgumentException(tr("Value >0 expected for parameter ''{0}'', got {1}", "chunkSize", chunkSize));
    152152        try {
    153153            progressMonitor.beginTask(tr("Starting to upload in chunks..."));
    154             List<IPrimitive> chunk = new ArrayList<>(chunkSize);
    155             Iterator<? extends IPrimitive> it = primitives.iterator();
     154            List<OsmPrimitive> chunk = new ArrayList<>(chunkSize);
     155            Iterator<? extends OsmPrimitive> it = primitives.iterator();
    156156            int numChunks = (int)Math.ceil((double)primitives.size() / (double)chunkSize);
    157157            int i= 0;
     
    190190     * @throws OsmTransferException thrown if something goes wrong
    191191     */
    192     public void uploadOsm(UploadStrategySpecification strategy, Collection<? extends IPrimitive> primitives, Changeset changeset, ProgressMonitor monitor) throws OsmTransferException {
     192    public void uploadOsm(UploadStrategySpecification strategy, Collection<? extends OsmPrimitive> primitives, Changeset changeset, ProgressMonitor monitor) throws OsmTransferException {
    193193        CheckParameterUtil.ensureParameterNotNull(changeset, "changeset");
    194194        processed = new LinkedList<>();
     
    224224    }
    225225
    226     void makeApiRequest(IPrimitive osm, ProgressMonitor progressMonitor) throws OsmTransferException {
     226    void makeApiRequest(OsmPrimitive osm, ProgressMonitor progressMonitor) throws OsmTransferException {
    227227        if (osm.isDeleted()) {
    228228            api.deletePrimitive(osm, progressMonitor);
     
    246246     * @return the collection of successfully processed primitives
    247247     */
    248     public Collection<IPrimitive> getProcessedPrimitives() {
     248    public Collection<OsmPrimitive> getProcessedPrimitives() {
    249249        return processed;
    250250    }
Note: See TracChangeset for help on using the changeset viewer.