Package org.openstreetmap.osmosis.replication.v0_6

Examples of org.openstreetmap.osmosis.replication.v0_6.BaseReplicationDownloader


    String fileName;
    File tmpFile;
    File file;

    // Generate the changeset file name.
    fileName = new ChangesetFileNameFormatter(config.getChangeFileBeginFormat(), config.getChangeFileEndFormat())
        .generateFileName(intervalBegin, intervalEnd);

    // Generate the temporary output file.
    tmpFile = new File(baseDirectory, TMP_FILE_NAME);
View Full Code Here


   * to the output task.
   */
  private void download() {
    IntervalDownloaderConfiguration configuration;
    TimestampTracker timestampTracker;
    ChangesetFileNameFormatter fileNameFormatter;
    Date currentTime;
    Date maximumTime;
    URL baseUrl;
    int maxDownloadCount;
    int downloadCount;
    ArrayList<File> tmpFileList;
    ArrayList<RunnableChangeSource> tasks;
    ArrayList<TaskRunner> taskRunners;
    boolean tasksSuccessful;
   
    // Instantiate utility objects.
    configuration = new IntervalDownloaderConfiguration(new File(workingDirectory, CONFIG_FILE));
    timestampTracker = new TimestampTracker(
      new File(workingDirectory, TSTAMP_FILE),
      new File(workingDirectory, TSTAMP_NEW_FILE)
    );
    fileNameFormatter = new ChangesetFileNameFormatter(
      configuration.getChangeFileBeginFormat(),
      configuration.getChangeFileEndFormat()
    );
   
    // Create the base url.
    try {
      baseUrl = new URL(configuration.getBaseUrl());
    } catch (MalformedURLException e) {
      throw new OsmosisRuntimeException(
          "Unable to convert URL string (" + configuration.getBaseUrl() + ") into a URL.", e);
    }
   
    tmpFileList = new ArrayList<File>();
   
    // Load the current time from the timestamp tracking file.
    currentTime = timestampTracker.getTime();
   
    // Load the latest timestamp from the server.
    maximumTime = getServerTimestamp(baseUrl);
   
    // Process until all files have been retrieved from the server.
    maxDownloadCount = configuration.getMaxDownloadCount();
    downloadCount = 0;
    while ((maxDownloadCount == 0 || downloadCount < maxDownloadCount) && currentTime.before(maximumTime)) {
      Date nextTime;
      String downloadFileName;
     
      // Calculate the end of the next time interval.
      nextTime = new Date(currentTime.getTime() + configuration.getIntervalLength());
     
      // Generate the filename to be retrieved from the server.
      downloadFileName = fileNameFormatter.generateFileName(currentTime, nextTime);
     
      // Download the changeset from the server.
      tmpFileList.add(downloadChangesetFile(downloadFileName, baseUrl));
     
      // Move the current time to the next interval.
View Full Code Here

  /**
   * Downloads the changeset files from the server and writes their contents
   * to the output task.
   */
  private void download() {
    IntervalDownloaderConfiguration configuration;
    TimestampTracker timestampTracker;
    ChangesetFileNameFormatter fileNameFormatter;
    Date currentTime;
    Date maximumTime;
    URL baseUrl;
    int maxDownloadCount;
    int downloadCount;
    ArrayList<File> tmpFileList;
    ArrayList<RunnableChangeSource> tasks;
    ArrayList<TaskRunner> taskRunners;
    boolean tasksSuccessful;
   
    // Instantiate utility objects.
    configuration = new IntervalDownloaderConfiguration(new File(workingDirectory, CONFIG_FILE));
    timestampTracker = new TimestampTracker(
      new File(workingDirectory, TSTAMP_FILE),
      new File(workingDirectory, TSTAMP_NEW_FILE)
    );
    fileNameFormatter = new ChangesetFileNameFormatter(
      configuration.getChangeFileBeginFormat(),
      configuration.getChangeFileEndFormat()
    );
   
    // Create the base url.
    try {
      baseUrl = new URL(configuration.getBaseUrl());
    } catch (MalformedURLException e) {
      throw new OsmosisRuntimeException(
          "Unable to convert URL string (" + configuration.getBaseUrl() + ") into a URL.", e);
    }
   
    tmpFileList = new ArrayList<File>();
   
    // Load the current time from the timestamp tracking file.
    currentTime = timestampTracker.getTime();
   
    // Load the latest timestamp from the server.
    maximumTime = getServerTimestamp(baseUrl);
   
    // Process until all files have been retrieved from the server.
    maxDownloadCount = configuration.getMaxDownloadCount();
    downloadCount = 0;
    while ((maxDownloadCount == 0 || downloadCount < maxDownloadCount) && currentTime.before(maximumTime)) {
      Date nextTime;
      String downloadFileName;
     
      // Calculate the end of the next time interval.
      nextTime = new Date(currentTime.getTime() + configuration.getIntervalLength());
     
      // Generate the filename to be retrieved from the server.
      downloadFileName = fileNameFormatter.generateFileName(currentTime, nextTime);
     
      // Download the changeset from the server.
View Full Code Here

  }
 
 
  private void runImpl() {
    try {
      ReplicationDownloaderConfiguration configuration;
      ReplicationState serverState;
      ReplicationState localState;
      PropertiesPersister localStatePersistor;
     
      // Instantiate utility objects.
      configuration = new ReplicationDownloaderConfiguration(new File(workingDirectory, CONFIG_FILE));
     
      // Obtain the server state.
      LOG.fine("Reading current server state.");
      serverState = serverStateReader.getServerState(configuration.getBaseUrl());
     
      // Build the local state persister which is used for both loading and storing local state.
      localStatePersistor = new PropertiesPersister(new File(workingDirectory, LOCAL_STATE_FILE));
     
      // Begin processing.
View Full Code Here

 
  /**
   * Calculate the replication lag and print it to stdout
   */
  private void getLag() {
    ReplicationDownloaderConfiguration configuration;
    ReplicationState serverState;
    ReplicationState localState;
    PropertiesPersister localStatePersistor;
   
    // Instantiate utility objects.
    configuration = new ReplicationDownloaderConfiguration(new File(workingDirectory, CONFIG_FILE));
   
    // Obtain the server state.
    LOG.fine("Reading current server state.");
    serverState = serverStateReader.getServerState(configuration.getBaseUrl());
   
    // Build the local state persister which is used for both loading and storing local state.
    localStatePersistor = new PropertiesPersister(new File(workingDirectory, LOCAL_STATE_FILE));
   
    // If local state isn't available we need to fail because no lag can be calculated.
View Full Code Here

    xmlReader.run();
  }


  private ReplicationFileMergerConfiguration getConfiguration() {
    return new ReplicationFileMergerConfiguration(new File(getWorkingDirectory(), CONFIG_FILE));
  }
View Full Code Here

   * {@inheritDoc}
   */
  @Override
  protected void processChangeset(XmlChangeReader xmlReader, ReplicationState replicationState) {
    int intervalLength;
    ReplicationFileMergerConfiguration configuration;

    configuration = getConfiguration();

    // Get the configured interval length.
    intervalLength = configuration.getIntervalLength();

    // If this is the first time through, initialise a writer for the next
    // sequence number.
    if (!sinkActive) {
      // Increment the current sequence number.
      currentDataState.setSequenceNumber(currentDataState.getSequenceNumber() + 1);

      // Initialise an output file for the new sequence number.
      LOG.finer("Opening change sink for interval with sequence number " + currentDataState.getSequenceNumber());
      changeSink = buildResultWriter(currentDataState.getSequenceNumber());
    }

    if (intervalLength > 0) {
      // If this is the first time through, align the timestamp at the
      // next boundary.
      if (!sinkActive) {
        Date intervalEnd;

        intervalEnd = new Date(currentDataState.getTimestamp().getTime() + intervalLength);
        intervalEnd = alignDateToIntervalBoundary(intervalEnd, intervalLength);
        currentDataState.setTimestamp(intervalEnd);
        LOG.finer("End of current interval is " + intervalEnd);
      }

      // If the replication state has moved us past the current interval
      // end point we need to
      // open a new interval. This may occur many times if the current
      // replication state moves
      // us past several intervals.
      while (replicationState.getTimestamp().compareTo(currentDataState.getTimestamp()) > 0) {

        // If we have an open changeset writer, close it and save the
        // current state.
        LOG.finer("Closing change sink for interval with sequence number "
            + currentDataState.getSequenceNumber());
        changeSink.complete();
        changeSink.release();

        replicationStore.saveState(currentDataState);

        // Update the state to match the next interval.
        currentDataState.setSequenceNumber(currentDataState.getSequenceNumber() + 1);
        currentDataState.setTimestamp(new Date(currentDataState.getTimestamp().getTime()
            + configuration.getIntervalLength()));

        // Begin a new interval.
        LOG.finer("Opening change sink for interval with sequence number "
            + currentDataState.getSequenceNumber());
        changeSink = buildResultWriter(currentDataState.getSequenceNumber());
View Full Code Here

TOP

Related Classes of org.openstreetmap.osmosis.replication.v0_6.BaseReplicationDownloader

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.