Ticket #1749: osmosis-0.6-maxDownloadCount.patch

File osmosis-0.6-maxDownloadCount.patch, 3.6 KB (added by jburgess777@…, 11 years ago)
  • src/org/openstreetmap/osmosis/core/merge/v0_6/impl/configuration.txt

     
    99# Change file begin format
    1010changeFileBeginFormat=yyyyMMddHH
    1111changeFileEndFormat=yyyyMMddHH
     12
     13# Defines the maximum number of files to download in a single invocation.
     14# There will be approximately two threads created for every downloaded file.
     15# Setting this to 0 disables this feature.
     16maxDownloadCount = 20
     17 No newline at end of file
  • src/org/openstreetmap/osmosis/core/merge/v0_6/impl/DownloaderConfiguration.java

     
    2323        private static final String KEY_CHANGE_FILE_BEGIN_FORMAT = "changeFileBeginFormat";
    2424        private static final String KEY_CHANGE_FILE_END_FORMAT = "changeFileEndFormat";
    2525        private static final String KEY_INTERVAL_LENGTH = "intervalLength";
     26        private static final String KEY_MAX_DOWNLOAD_COUNT = "maxDownloadCount";
    2627       
    2728       
    2829        private Properties properties;
     
    4950                       
    5051                        properties.load(fileInputStream);
    5152                       
     53                        fileInputStream.close();
     54                        fileInputStream = null;
     55                       
    5256                } catch (IOException e) {
    5357                        throw new OsmosisRuntimeException("Unable to load properties from config file " + configFile);
    5458                } finally {
     
    112116        public int getIntervalLength() {
    113117                return Integer.parseInt(properties.getProperty(KEY_INTERVAL_LENGTH)) * 1000;
    114118        }
     119       
     120       
     121        /**
     122         * Returns the maximum number of files to download in a single invocation.
     123         *
     124         * @return The maximum download count.
     125         */
     126        public int getMaxDownloadCount() {
     127                return Integer.parseInt(properties.getProperty(KEY_MAX_DOWNLOAD_COUNT));
     128        }
    115129}
  • src/org/openstreetmap/osmosis/core/merge/v0_6/ChangeDownloader.java

     
    185185                        return outputFile;
    186186                       
    187187                } catch (IOException e) {
    188                         throw new OsmosisRuntimeException("Unable to read the changeset file from the server.", e);
     188                        throw new OsmosisRuntimeException("Unable to read the changeset file " + fileName + " from the server.", e);
    189189                } finally {
    190190                        try {
    191191                                if (inputStream != null) {
     
    218218                Date currentTime;
    219219                Date maximumTime;
    220220                URL baseUrl;
     221                int maxDownloadCount;
     222                int downloadCount;
    221223                ArrayList<File> tmpFileList;
    222224                ArrayList<RunnableChangeSource> tasks;
    223225                ArrayList<TaskRunner> taskRunners;
     
    251253                maximumTime = getServerTimestamp(baseUrl);
    252254               
    253255                // Process until all files have been retrieved from the server.
    254                 while (currentTime.before(maximumTime)) {
     256                maxDownloadCount = configuration.getMaxDownloadCount();
     257                downloadCount = 0;
     258                while ((maxDownloadCount == 0 || downloadCount < maxDownloadCount) && currentTime.before(maximumTime)) {
    255259                        Date nextTime;
    256260                        String downloadFileName;
    257261                       
     
    266270                       
    267271                        // Move the current time to the next interval.
    268272                        currentTime = nextTime;
     273                       
     274                        // Increment the current download count.
     275                        downloadCount++;
    269276                }
    270277               
    271278                // Generate a set of tasks for loading the change files and merge them